I've recently been told by developers that some of our
SQL 2000 stored procedures an application is using take
longer to run the first time they are ran in a while. If
they run them again, they seem to be quicker. Does
anyone have any suggestions as to where to start looking
to resolve this? Does this have to do with the execution
plan not staying in the cache? Is there a way to fix
this?Stored procedures are compiled when the execution plan is not in cache
but the performance hit is usually not significant for occasional
compiles. The more likely cause is that data is retrieved from disk
when the proc is first run and remains in cache for subsequent access.
You can see if this is the case by running the following test:
USE MyDatabase
GO
CHECKPOINT
DBCC DROPCLEANBUFFERS
GO
SELECT GETDATE()
EXECUTE MyProcedure
SELECT GETDATE()
EXECUTE MyProcedure
SELECT GETDATE()
GO
If the second execution is noticeably faster, you might take a look at
the execution plan to see if you can optimize the queries and/or add
indexes. This can reduce both physical and logical i/o.
--
Hope this helps.
Dan Guzman
SQL Server MVP
--
SQL FAQ links (courtesy Neil Pike):
http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--
"Bill" <bill4390@.hotmaillcom> wrote in message
news:286f01c3673b$06480360$7d02280a@.phx.gbl...
> I've recently been told by developers that some of our
> SQL 2000 stored procedures an application is using take
> longer to run the first time they are ran in a while. If
> they run them again, they seem to be quicker. Does
> anyone have any suggestions as to where to start looking
> to resolve this? Does this have to do with the execution
> plan not staying in the cache? Is there a way to fix
> this?
>
Showing posts with label procedures. Show all posts
Showing posts with label procedures. Show all posts
Sunday, March 11, 2012
Caching stored procedures
Labels:
application,
caching,
database,
developers,
microsoft,
mysql,
oracle,
procedures,
run,
server,
sql,
stored,
time
Thursday, March 8, 2012
Caching of inline queries
Hi,
I am trying to evaluate the benefits of writing stored procedures over
using inline SQL code using ADO.net and SqlServer. I am coming from an
oracle background, and am trying to understand under what
circumstances SqlServer will recompile my query, and when it will use
a pre-compiled version. The Oracle term for this behavior is
'bind-variable'. The only Oracle/bind-variable related information I
found here was
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=e0dtNgY%24CHA.2572%40TK2MSFTNGP11.phx.gbl
It seems to indicate that in order to avoid recompilation that I could
use stored procedures, format my queries using sp_executesql, or use
the prepared statement in my command object and reuse the object.
I am confused because by examining the syscacheobjects, it seems my
parameterized query is cached and reused automatically.
Here is what I am doing to test this. I have some code that looks like
this:
SqlConnection MyConnection = new SqlConnection(ConnectionString);
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT GStudentId, Lastname,
FirstName FROM student WHERE GStudentId=@.StudentId", MyConnection);
MyCommand.Parameters.Add("@.StudentId", _GStudentId);
SqlDataReader MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
I call this code on a simple web page, which lets me easily execute it
again and again.
I then do the following query inside Query Analyzer:
select usecounts, sql from syscacheobjects
where sql like '%SELECT GStudentId, Lastname, FirstName FROM student
WHERE GStudentId=@.StudentId%'
As I execute the page over and over the use count goes up.
Syscacheobjects actually returns two rows, one with a cached object
type of ?Executable Plan' (this is the one with the ?incrementing
usecounts'), and one with a type of ?Compiled Plan'. What are these
each used for?
Doesn't this mean that Sql Server is caching the query? I am
recreating the command object from scratch each time, yet it seems to
use the same "cached execution plan".
I am very happy with this behavior, yet it is in contradiction to the
other information I was able to find.
Can someone validate?
Thanks!
DaveSQL Server will do SIMPLE parameter substitution to reuse an ad-hoc plan.
That's probably what's happening in your example, but this will only happen
in trivial cases. You're better off with a proc us sp_executesql.
This paper is a good starting point for understanding SQL Server
behaivior...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_queryrecompilation.asp
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"HaukiDog" <HaukiDog@.hotmail.com> wrote in message
news:6d3bc6d9.0311241301.58817947@.posting.google.com...
> Hi,
> I am trying to evaluate the benefits of writing stored procedures over
> using inline SQL code using ADO.net and SqlServer. I am coming from an
> oracle background, and am trying to understand under what
> circumstances SqlServer will recompile my query, and when it will use
> a pre-compiled version. The Oracle term for this behavior is
> 'bind-variable'. The only Oracle/bind-variable related information I
> found here was
>
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=e0dtNgY%24CHA.2572%40TK2MSFTNGP11.phx.gbl
> It seems to indicate that in order to avoid recompilation that I could
> use stored procedures, format my queries using sp_executesql, or use
> the prepared statement in my command object and reuse the object.
> I am confused because by examining the syscacheobjects, it seems my
> parameterized query is cached and reused automatically.
> Here is what I am doing to test this. I have some code that looks like
> this:
> SqlConnection MyConnection = new SqlConnection(ConnectionString);
> MyConnection.Open();
> SqlCommand MyCommand = new SqlCommand("SELECT GStudentId, Lastname,
> FirstName FROM student WHERE GStudentId=@.StudentId", MyConnection);
> MyCommand.Parameters.Add("@.StudentId", _GStudentId);
> SqlDataReader MyReader => MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
> I call this code on a simple web page, which lets me easily execute it
> again and again.
> I then do the following query inside Query Analyzer:
> select usecounts, sql from syscacheobjects
> where sql like '%SELECT GStudentId, Lastname, FirstName FROM student
> WHERE GStudentId=@.StudentId%'
> As I execute the page over and over the use count goes up.
> Syscacheobjects actually returns two rows, one with a cached object
> type of 'Executable Plan' (this is the one with the 'incrementing
> usecounts'), and one with a type of 'Compiled Plan'. What are these
> each used for?
> Doesn't this mean that Sql Server is caching the query? I am
> recreating the command object from scratch each time, yet it seems to
> use the same "cached execution plan".
> I am very happy with this behavior, yet it is in contradiction to the
> other information I was able to find.
> Can someone validate?
> Thanks!
> Dave
I am trying to evaluate the benefits of writing stored procedures over
using inline SQL code using ADO.net and SqlServer. I am coming from an
oracle background, and am trying to understand under what
circumstances SqlServer will recompile my query, and when it will use
a pre-compiled version. The Oracle term for this behavior is
'bind-variable'. The only Oracle/bind-variable related information I
found here was
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=e0dtNgY%24CHA.2572%40TK2MSFTNGP11.phx.gbl
It seems to indicate that in order to avoid recompilation that I could
use stored procedures, format my queries using sp_executesql, or use
the prepared statement in my command object and reuse the object.
I am confused because by examining the syscacheobjects, it seems my
parameterized query is cached and reused automatically.
Here is what I am doing to test this. I have some code that looks like
this:
SqlConnection MyConnection = new SqlConnection(ConnectionString);
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT GStudentId, Lastname,
FirstName FROM student WHERE GStudentId=@.StudentId", MyConnection);
MyCommand.Parameters.Add("@.StudentId", _GStudentId);
SqlDataReader MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
I call this code on a simple web page, which lets me easily execute it
again and again.
I then do the following query inside Query Analyzer:
select usecounts, sql from syscacheobjects
where sql like '%SELECT GStudentId, Lastname, FirstName FROM student
WHERE GStudentId=@.StudentId%'
As I execute the page over and over the use count goes up.
Syscacheobjects actually returns two rows, one with a cached object
type of ?Executable Plan' (this is the one with the ?incrementing
usecounts'), and one with a type of ?Compiled Plan'. What are these
each used for?
Doesn't this mean that Sql Server is caching the query? I am
recreating the command object from scratch each time, yet it seems to
use the same "cached execution plan".
I am very happy with this behavior, yet it is in contradiction to the
other information I was able to find.
Can someone validate?
Thanks!
DaveSQL Server will do SIMPLE parameter substitution to reuse an ad-hoc plan.
That's probably what's happening in your example, but this will only happen
in trivial cases. You're better off with a proc us sp_executesql.
This paper is a good starting point for understanding SQL Server
behaivior...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_queryrecompilation.asp
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"HaukiDog" <HaukiDog@.hotmail.com> wrote in message
news:6d3bc6d9.0311241301.58817947@.posting.google.com...
> Hi,
> I am trying to evaluate the benefits of writing stored procedures over
> using inline SQL code using ADO.net and SqlServer. I am coming from an
> oracle background, and am trying to understand under what
> circumstances SqlServer will recompile my query, and when it will use
> a pre-compiled version. The Oracle term for this behavior is
> 'bind-variable'. The only Oracle/bind-variable related information I
> found here was
>
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=e0dtNgY%24CHA.2572%40TK2MSFTNGP11.phx.gbl
> It seems to indicate that in order to avoid recompilation that I could
> use stored procedures, format my queries using sp_executesql, or use
> the prepared statement in my command object and reuse the object.
> I am confused because by examining the syscacheobjects, it seems my
> parameterized query is cached and reused automatically.
> Here is what I am doing to test this. I have some code that looks like
> this:
> SqlConnection MyConnection = new SqlConnection(ConnectionString);
> MyConnection.Open();
> SqlCommand MyCommand = new SqlCommand("SELECT GStudentId, Lastname,
> FirstName FROM student WHERE GStudentId=@.StudentId", MyConnection);
> MyCommand.Parameters.Add("@.StudentId", _GStudentId);
> SqlDataReader MyReader => MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
> I call this code on a simple web page, which lets me easily execute it
> again and again.
> I then do the following query inside Query Analyzer:
> select usecounts, sql from syscacheobjects
> where sql like '%SELECT GStudentId, Lastname, FirstName FROM student
> WHERE GStudentId=@.StudentId%'
> As I execute the page over and over the use count goes up.
> Syscacheobjects actually returns two rows, one with a cached object
> type of 'Executable Plan' (this is the one with the 'incrementing
> usecounts'), and one with a type of 'Compiled Plan'. What are these
> each used for?
> Doesn't this mean that Sql Server is caching the query? I am
> recreating the command object from scratch each time, yet it seems to
> use the same "cached execution plan".
> I am very happy with this behavior, yet it is in contradiction to the
> other information I was able to find.
> Can someone validate?
> Thanks!
> Dave
Friday, February 24, 2012
C# Express vs CLR integration with SQL Server 2005
Hi,
I wonder if it is possible to use the Express edition of C# to write CLR procedures?
Regards
/Mattias
Hi,sure it is even possible to use just notepad.exe and csc.exe to build the CLR part. Deployment will take place using TSQL commands. So yes, this is sure possible :-)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
Tuesday, February 14, 2012
business process logic in stored procedures
Hi All,
I've always tried to think of and use sql as being a tool to quickly
retrieve / update relevant data, and let other parts of a system handle
the decisions as to what needs to be done to the data. However I keep
coming across (and sometimes find myself creating) the situation where
there are massive stored procedures which will have several different
statements, pulling data from loads of tables and updating others based
on some business logic.
First question: is this a bad thing?
as I see it this has the advantage that updates can be expressed as a
function to be applied over a whole table, making the process much
faster than if the data was changed in a business layer, then
propogated to the database. However the "code" is hard for someone else
to understand, and hard to re-use/improve. I often find that processes
which would be modelled with quite a large framework of objects are
condensed down into a large stored procedure, such that to anyone else
looking at it will just see a mass of update insert and selects with no
idea why.
Second question: when to do it?
I have found that at times it's unaviodable, either for performance or
simply the ease of access to all the data that I need to use a stored
proc, does anyone have any rules of thumb as to when it's a good/bad
idea?
Third question: what are the alternatives?
I'd hope that there are other ways to get around the problems that
people are solving using sql, does anyone have any links/suggestions of
how to approach things that people would often resort to sql for, using
more maintainable methods?
I could probably rattle on for days on this issue, but I'm hoping maybe
people will be able to suggest some best practice about this.
Cheers
WillWill
1),2)
I remember some times ago it was discussion about this subject and some
people say that they put the business logic in the stored procedure and
some people say they do not but only code/dll....
I have been praticipate in some projects where we put all login in to
stored procedure and it was relaible/readable and worder very good in terms
of perfomance as well
So the answer will be it depends on YOUR project's business logic and sure
if you can test 'somehow' and make the right decision
3) Well if you develop multi tier application the question is where to put
BL in data layer (dll that access to the database) or directly to stored
procedures
Again , I have seen many projects where people (including me) put the logic
into SP and some projects where people put the BL (including me) in the
code, so it is really DEPENDS on many things.
If you are lucky and Erlan ( and many others here at forum) jump in , it is
interesting to see what does he suggest ?
"Will" <william_pegg@.yahoo.co.uk> wrote in message
news:1144324357.527781.15400@.e56g2000cwe.googlegroups.com...
> Hi All,
> I've always tried to think of and use sql as being a tool to quickly
> retrieve / update relevant data, and let other parts of a system handle
> the decisions as to what needs to be done to the data. However I keep
> coming across (and sometimes find myself creating) the situation where
> there are massive stored procedures which will have several different
> statements, pulling data from loads of tables and updating others based
> on some business logic.
> First question: is this a bad thing?
> as I see it this has the advantage that updates can be expressed as a
> function to be applied over a whole table, making the process much
> faster than if the data was changed in a business layer, then
> propogated to the database. However the "code" is hard for someone else
> to understand, and hard to re-use/improve. I often find that processes
> which would be modelled with quite a large framework of objects are
> condensed down into a large stored procedure, such that to anyone else
> looking at it will just see a mass of update insert and selects with no
> idea why.
> Second question: when to do it?
> I have found that at times it's unaviodable, either for performance or
> simply the ease of access to all the data that I need to use a stored
> proc, does anyone have any rules of thumb as to when it's a good/bad
> idea?
> Third question: what are the alternatives?
> I'd hope that there are other ways to get around the problems that
> people are solving using sql, does anyone have any links/suggestions of
> how to approach things that people would often resort to sql for, using
> more maintainable methods?
> I could probably rattle on for days on this issue, but I'm hoping maybe
> people will be able to suggest some best practice about this.
> Cheers
> Will
>
I've always tried to think of and use sql as being a tool to quickly
retrieve / update relevant data, and let other parts of a system handle
the decisions as to what needs to be done to the data. However I keep
coming across (and sometimes find myself creating) the situation where
there are massive stored procedures which will have several different
statements, pulling data from loads of tables and updating others based
on some business logic.
First question: is this a bad thing?
as I see it this has the advantage that updates can be expressed as a
function to be applied over a whole table, making the process much
faster than if the data was changed in a business layer, then
propogated to the database. However the "code" is hard for someone else
to understand, and hard to re-use/improve. I often find that processes
which would be modelled with quite a large framework of objects are
condensed down into a large stored procedure, such that to anyone else
looking at it will just see a mass of update insert and selects with no
idea why.
Second question: when to do it?
I have found that at times it's unaviodable, either for performance or
simply the ease of access to all the data that I need to use a stored
proc, does anyone have any rules of thumb as to when it's a good/bad
idea?
Third question: what are the alternatives?
I'd hope that there are other ways to get around the problems that
people are solving using sql, does anyone have any links/suggestions of
how to approach things that people would often resort to sql for, using
more maintainable methods?
I could probably rattle on for days on this issue, but I'm hoping maybe
people will be able to suggest some best practice about this.
Cheers
WillWill
1),2)
I remember some times ago it was discussion about this subject and some
people say that they put the business logic in the stored procedure and
some people say they do not but only code/dll....
I have been praticipate in some projects where we put all login in to
stored procedure and it was relaible/readable and worder very good in terms
of perfomance as well
So the answer will be it depends on YOUR project's business logic and sure
if you can test 'somehow' and make the right decision
3) Well if you develop multi tier application the question is where to put
BL in data layer (dll that access to the database) or directly to stored
procedures
Again , I have seen many projects where people (including me) put the logic
into SP and some projects where people put the BL (including me) in the
code, so it is really DEPENDS on many things.
If you are lucky and Erlan ( and many others here at forum) jump in , it is
interesting to see what does he suggest ?
"Will" <william_pegg@.yahoo.co.uk> wrote in message
news:1144324357.527781.15400@.e56g2000cwe.googlegroups.com...
> Hi All,
> I've always tried to think of and use sql as being a tool to quickly
> retrieve / update relevant data, and let other parts of a system handle
> the decisions as to what needs to be done to the data. However I keep
> coming across (and sometimes find myself creating) the situation where
> there are massive stored procedures which will have several different
> statements, pulling data from loads of tables and updating others based
> on some business logic.
> First question: is this a bad thing?
> as I see it this has the advantage that updates can be expressed as a
> function to be applied over a whole table, making the process much
> faster than if the data was changed in a business layer, then
> propogated to the database. However the "code" is hard for someone else
> to understand, and hard to re-use/improve. I often find that processes
> which would be modelled with quite a large framework of objects are
> condensed down into a large stored procedure, such that to anyone else
> looking at it will just see a mass of update insert and selects with no
> idea why.
> Second question: when to do it?
> I have found that at times it's unaviodable, either for performance or
> simply the ease of access to all the data that I need to use a stored
> proc, does anyone have any rules of thumb as to when it's a good/bad
> idea?
> Third question: what are the alternatives?
> I'd hope that there are other ways to get around the problems that
> people are solving using sql, does anyone have any links/suggestions of
> how to approach things that people would often resort to sql for, using
> more maintainable methods?
> I could probably rattle on for days on this issue, but I'm hoping maybe
> people will be able to suggest some best practice about this.
> Cheers
> Will
>
business logic location
For quite a while I've had pretty good success with putting most of my
business logic in stored procedures and triggers. It's fast, relational,
searchable, and updatable without any recompiling.
At the moment I'm considering supporting both SQL Server and Oracle, and it
seems to me that to support multiple database platforms the business logic
needs to be moved out of the database layer. Not only would this seem
necessary to me, but it would also seem to be ugly, much more complicated,
harder to maintain, and slower, maybe far slower.
This is the first time I've looked at this problem; it was my assessment
years ago that deep business logic (not the minor stuff associated with just
the UI) in hard code was a bad idea. I was hoping someone could share their
point of view on this area with me, maybe point out some examples of how
multiple database support is currently done, and how feasable (automatable)
it is to port data, with stored procedures and triggers, between SQL and
Oracle.
PaulOn Mon, 19 Sep 2005 10:44:04 -0400, PJ6 wrote:
>For quite a while I've had pretty good success with putting most of my
>business logic in stored procedures and triggers. It's fast, relational,
>searchable, and updatable without any recompiling.
>At the moment I'm considering supporting both SQL Server and Oracle, and it
>seems to me that to support multiple database platforms the business logic
>needs to be moved out of the database layer. Not only would this seem
>necessary to me, but it would also seem to be ugly, much more complicated,
>harder to maintain, and slower, maybe far slower.
Hi Paul,
I disagree. Even when porting to Oracle or any other platform, you'll
still have to have the business logic in the data layer. Just think
back: over the last few years, how many client technologies have you
seen come and go? And how many times did you switch database vendor?
Besides: business rules in the front end tend to be much easier to
bypass than business rules in triggers in the database.
>This is the first time I've looked at this problem; it was my assessment
>years ago that deep business logic (not the minor stuff associated with jus
t
>the UI) in hard code was a bad idea. I was hoping someone could share their
>point of view on this area with me, maybe point out some examples of how
>multiple database support is currently done, and how feasable (automatable)
>it is to port data, with stored procedures and triggers, between SQL and
>Oracle.
It helps if you start coding from day one with the idea that you might
one day have to port. Use ANSI-standard whenever feasible. If you do use
proprietary (because ANSI would require an extremely ugly kludge or many
extra lines of code, or because the ANSI version is lots slower),
document it, and describe how the ANSI version looks.
You'll still have a lot of work carved out for you before you'll be
ready to run the same product on SQL Server and Oracle, becuase there
are lots of irritating differences. Expect the porting of data to be
relatively easy, the porting of queries quite complicated and the
porting of stored procedures and triggers to be hell. Especially if you
didn't write the original code with portability as one of the design
objectives...
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:7u01j1tqn6tnoaol3siot2te99bl5psnne@.
4ax.com...
<...>
> Besides: business rules in the front end tend to be much easier to
> bypass than business rules in triggers in the database.
<...>
> You'll still have a lot of work carved out for you before you'll be
> ready to run the same product on SQL Server and Oracle, becuase there
> are lots of irritating differences. Expect the porting of data to be
> relatively easy, the porting of queries quite complicated and the
> porting of stored procedures and triggers to be hell. Especially if you
> didn't write the original code with portability as one of the design
> objectives...
Well I guess I'll to stand by my choice to keep most business logic in the
data layer then, and damn the torpeedos, we won't support Oracle.
MSDE is free anyway.
Paul|||"PJ6" <nobody@.nowhere.net> wrote in message
news:eEAw3rrvFHA.2932@.TK2MSFTNGP10.phx.gbl...
... we won't support Oracle.
Great idea... :-)|||>Especially if you
>didn't write the original code with >portability as one of the design
>objectives...
just wanted to add that the price for portability may be very very
high.
For instance, a wide table, appr. 4100 bytes per row, which menas 1 row
per page. Start using those "horrible proprietary" data types like bit
and smalldatatime, and here you go: 3900 bytes, 2 rows per page!
Having sacrificed portasbility, all of a sudden you get 100% better
performance.
There are also plenty of differences in locking and concurrency, index
behaviour etc.|||On Wed, 21 Sep 2005 10:44:26 -0400, PJ6 wrote:
>"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
> news:7u01j1tqn6tnoaol3siot2te99bl5psnne@.
4ax.com...
><...>
><...>
>Well I guess I'll to stand by my choice to keep most business logic in the
>data layer then, and damn the torpeedos, we won't support Oracle.
Hi Paul,
If the expected extra revenues do not outweigh the expected cost of
having to maintain two versions of the code plus the write-off of the
conversion to Oracle, that'd be the soundest decision.
>MSDE is free anyway.
And ditto for SQL Express (with even less limitation, IIRC).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 21 Sep 2005 08:45:19 -0700, Alexander Kuznetsov wrote:
>just wanted to add that the price for portability may be very very
>high.
(snip)
>Having sacrificed portasbility, all of a sudden you get 100% better
>performance.
Hi Alexander,
Great example!
That's exactly why I want portability to be "one of" the design
objectives. Not the only one, nor even the most important one.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
business logic in stored procedures and triggers. It's fast, relational,
searchable, and updatable without any recompiling.
At the moment I'm considering supporting both SQL Server and Oracle, and it
seems to me that to support multiple database platforms the business logic
needs to be moved out of the database layer. Not only would this seem
necessary to me, but it would also seem to be ugly, much more complicated,
harder to maintain, and slower, maybe far slower.
This is the first time I've looked at this problem; it was my assessment
years ago that deep business logic (not the minor stuff associated with just
the UI) in hard code was a bad idea. I was hoping someone could share their
point of view on this area with me, maybe point out some examples of how
multiple database support is currently done, and how feasable (automatable)
it is to port data, with stored procedures and triggers, between SQL and
Oracle.
PaulOn Mon, 19 Sep 2005 10:44:04 -0400, PJ6 wrote:
>For quite a while I've had pretty good success with putting most of my
>business logic in stored procedures and triggers. It's fast, relational,
>searchable, and updatable without any recompiling.
>At the moment I'm considering supporting both SQL Server and Oracle, and it
>seems to me that to support multiple database platforms the business logic
>needs to be moved out of the database layer. Not only would this seem
>necessary to me, but it would also seem to be ugly, much more complicated,
>harder to maintain, and slower, maybe far slower.
Hi Paul,
I disagree. Even when porting to Oracle or any other platform, you'll
still have to have the business logic in the data layer. Just think
back: over the last few years, how many client technologies have you
seen come and go? And how many times did you switch database vendor?
Besides: business rules in the front end tend to be much easier to
bypass than business rules in triggers in the database.
>This is the first time I've looked at this problem; it was my assessment
>years ago that deep business logic (not the minor stuff associated with jus
t
>the UI) in hard code was a bad idea. I was hoping someone could share their
>point of view on this area with me, maybe point out some examples of how
>multiple database support is currently done, and how feasable (automatable)
>it is to port data, with stored procedures and triggers, between SQL and
>Oracle.
It helps if you start coding from day one with the idea that you might
one day have to port. Use ANSI-standard whenever feasible. If you do use
proprietary (because ANSI would require an extremely ugly kludge or many
extra lines of code, or because the ANSI version is lots slower),
document it, and describe how the ANSI version looks.
You'll still have a lot of work carved out for you before you'll be
ready to run the same product on SQL Server and Oracle, becuase there
are lots of irritating differences. Expect the porting of data to be
relatively easy, the porting of queries quite complicated and the
porting of stored procedures and triggers to be hell. Especially if you
didn't write the original code with portability as one of the design
objectives...
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:7u01j1tqn6tnoaol3siot2te99bl5psnne@.
4ax.com...
<...>
> Besides: business rules in the front end tend to be much easier to
> bypass than business rules in triggers in the database.
<...>
> You'll still have a lot of work carved out for you before you'll be
> ready to run the same product on SQL Server and Oracle, becuase there
> are lots of irritating differences. Expect the porting of data to be
> relatively easy, the porting of queries quite complicated and the
> porting of stored procedures and triggers to be hell. Especially if you
> didn't write the original code with portability as one of the design
> objectives...
Well I guess I'll to stand by my choice to keep most business logic in the
data layer then, and damn the torpeedos, we won't support Oracle.
MSDE is free anyway.
Paul|||"PJ6" <nobody@.nowhere.net> wrote in message
news:eEAw3rrvFHA.2932@.TK2MSFTNGP10.phx.gbl...
... we won't support Oracle.
Great idea... :-)|||>Especially if you
>didn't write the original code with >portability as one of the design
>objectives...
just wanted to add that the price for portability may be very very
high.
For instance, a wide table, appr. 4100 bytes per row, which menas 1 row
per page. Start using those "horrible proprietary" data types like bit
and smalldatatime, and here you go: 3900 bytes, 2 rows per page!
Having sacrificed portasbility, all of a sudden you get 100% better
performance.
There are also plenty of differences in locking and concurrency, index
behaviour etc.|||On Wed, 21 Sep 2005 10:44:26 -0400, PJ6 wrote:
>"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
> news:7u01j1tqn6tnoaol3siot2te99bl5psnne@.
4ax.com...
><...>
><...>
>Well I guess I'll to stand by my choice to keep most business logic in the
>data layer then, and damn the torpeedos, we won't support Oracle.
Hi Paul,
If the expected extra revenues do not outweigh the expected cost of
having to maintain two versions of the code plus the write-off of the
conversion to Oracle, that'd be the soundest decision.
>MSDE is free anyway.
And ditto for SQL Express (with even less limitation, IIRC).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 21 Sep 2005 08:45:19 -0700, Alexander Kuznetsov wrote:
>just wanted to add that the price for portability may be very very
>high.
(snip)
>Having sacrificed portasbility, all of a sudden you get 100% better
>performance.
Hi Alexander,
Great example!
That's exactly why I want portability to be "one of" the design
objectives. Not the only one, nor even the most important one.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Subscribe to:
Posts (Atom)