Showing posts with label performance. Show all posts
Showing posts with label performance. Show all posts

Thursday, March 22, 2012

Computed column

I created a index on a computed column. I did not see any improvement
in performance with a join to this column and also my inserts and
updates to this table are failing. Any ideas?

ChenderRegarding your failing inserts and updates, the likely cause is that one ore
more connection options are not set properly for maintaining a computed
column index. The error message will indicate which option(s) is
incompatible. The required options specified in the Books Online
<createdb.chm::/cm_8_des_05_8os3.htm> are:

SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF

All but ARITHABORT are set automatically when connection via OLEDB or ODBC.

Please post your DDL, query and sample data for help with your performance
issue.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"BCR" <bcrao@.yahoo.com> wrote in message
news:32c11012.0411181258.7d47dd2b@.posting.google.c om...
>I created a index on a computed column. I did not see any improvement
> in performance with a join to this column and also my inserts and
> updates to this table are failing. Any ideas?
> Chender|||[posted and mailed, please reply in nes]

BCR (bcrao@.yahoo.com) writes:
> I created a index on a computed column. I did not see any improvement
> in performance with a join to this column and also my inserts and
> updates to this table are failing. Any ideas?

As Dan pointed out the update/inserts are failing because of the settings.
I like to add two things. The first is that the lack of performance is
very likely due to the same problems. If the proper settings are not in
effect, SQL Server will not consider the index.

The other is that the two settings ANSI_NULLS and QUOTED_IDENTIFIER are
saved when you create a stored procedure, view, trigger or user-defined
functions. So that if even if these are on at run-time, they will not be
in effect if they were off when the procedure was created. Some tools,
Enterprise Manager and OSQL to be precise, have QUOTED_IDENTIFIER off by
default.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Monday, March 19, 2012

Composite primary key

Hello,

Does composite primary key affect performance on the table that contains the composite primary key or tables that references this table?

When composite primary key should be used?

In my experience composite keys are a through back to old systems that where converted to databases such as SQL Server / Oracle.

As a developer, rather than a DBA, composite keys are a real pain to program against especially in the modern world of object programming, data objects etc. I would always use a single unique value to identify a row rather than using composite keys. If you regularly query dataing using mulitple values from columns in the where statement then by all means create a normal index based on these columns (in the order that you use them in the where statement).

|||

so considering performance issue!! does databases with such structure perform worse than ones with single keys!! i mean directly or indirectly.

*Directly: if it has a bad performance in join clauses or in search criteria.

*Indirectly: in programming specially in .Net when using datagrids and such controls that generate relations and act with whole tables in runtime.

Thnx

composite key structure

I'm just looking to get suggestions as to what the best way to handle this
key structure is, in terms of performance. At present, the current pk is on
an identity value. I 'inherited' this and am sing to change post haste
for many reasons. These three columns combined equate to the primary key
from a business-perspective: tradetime,endpoint,ordernumber
Because of this, I have created a clustered compound primary key with the
columns in this order: tradetime,endpoint,ordernumber
Tradetime has the most selectivity, as it nearly always montonically
increases.
Endpoint is used first in most of the ad hoc where clauses.
All my procedures, however, are very date-specific. So this, too, puts
tradetime in the where clauses a lot.
tradetime is datetime, endpoint is varchar(8) and ordernumber is varchar(32)
hence, the thing is kind of wide. but, as i said before, it is the only
uniqueID from a business perspective. the db structure is both current and
historical. current is about 300-600K and nearly all continuous inserts,
historical averages around 38M and it's where the reporting and analysis is
done. the data is rarely ever updated in either.
So, should it be clustered or non? Are the columns ordered correctly in the
compound key? And any thoughts as to how this will impact insertion
performance?
thank you in advance,
-- LynnLynn,

Base on the this, you should already have a unique index by these three
columns. I think the key is to wide to be used as a clustered index. Remembe
r
that the key of a clustered index is used by the rest of nonclustered indexe
s.
Tips on Optimizing SQL Server Clustered Indexes
http://www.sql-server-performance.c...red_indexes.asp
AMB
"Lynn" wrote:
> I'm just looking to get suggestions as to what the best way to handle this
> key structure is, in terms of performance. At present, the current pk is
on
> an identity value. I 'inherited' this and am sing to change post haste
> for many reasons. These three columns combined equate to the primary key
> from a business-perspective: tradetime,endpoint,ordernumber
> Because of this, I have created a clustered compound primary key with the
> columns in this order: tradetime,endpoint,ordernumber
> Tradetime has the most selectivity, as it nearly always montonically
> increases.
> Endpoint is used first in most of the ad hoc where clauses.
> All my procedures, however, are very date-specific. So this, too, puts
> tradetime in the where clauses a lot.
> tradetime is datetime, endpoint is varchar(8) and ordernumber is varchar(3
2)
> hence, the thing is kind of wide. but, as i said before, it is the only
> uniqueID from a business perspective. the db structure is both current an
d
> historical. current is about 300-600K and nearly all continuous inserts,
> historical averages around 38M and it's where the reporting and analysis i
s
> done. the data is rarely ever updated in either.
> So, should it be clustered or non? Are the columns ordered correctly in t
he
> compound key? And any thoughts as to how this will impact insertion
> performance?
> thank you in advance,
> -- Lynn|||ok, amb, but are you suggesting i do not create a compound pk on these three
columns and that a unique index or unique constraint will suffice, or are yo
u
suggesting i should do the compound pk but that it should be non-clustered?
Lynn
"Alejandro Mesa" wrote:
> Lynn,
>
>
> Base on the this, you should already have a unique index by these three
> columns. I think the key is to wide to be used as a clustered index. Remem
ber
> that the key of a clustered index is used by the rest of nonclustered inde
xes.
> Tips on Optimizing SQL Server Clustered Indexes
> http://www.sql-server-performance.c...red_indexes.asp
>
> AMB
> "Lynn" wrote:
>|||> ok, amb, but are you suggesting i do not create a compound pk on these
> three
> columns and that a unique index or unique constraint will suffice, or are
> you
> suggesting i should do the compound pk but that it should be
> non-clustered?
Do you have related tables (like OrderDetails) that need referential
integrity back to this table? Do you want to store OrderNumber there, or do
you want to repeat the tradetime,endpoint,ordernumber combo in every related
table?|||Actually, no, there are very few related tables. It's a trading repository
that we continually load with trades. The other tables are specific to
accounts and bi, but not to the ordernumbers themselves. There is a need to
go back in a report on/query the data regularly, but it's done against the
historical table, which is structured identically.
--
Lynn
"Aaron Bertrand [SQL Server MVP]" wrote:

> Do you have related tables (like OrderDetails) that need referential
> integrity back to this table? Do you want to store OrderNumber there, or
do
> you want to repeat the tradetime,endpoint,ordernumber combo in every relat
ed
> table?
>
>|||Lynn,
What I meant was that an identity column as pk, does not asure that there
will not be duplicated rows by (tradetime,endpoint,ordernumber) and because
these columns, as you said, equate to the primary key from a
business-perspective then it should exists already a constraint to force the
uniqueness by these columns. The question is if this unique index should be
clustered or not?. I will also consider what Aaron is asking you for (is
there any other table that is referencing this table?). Well, there are othe
r
things to consider like if there are other columns that you use for range
queries or are used in the "group by" clause, what is more important for you
"select" or "insert" performance, etc. Take a look to the article in the
link, it can help you to understand what are the columns in your table prope
r
for a clustered index.
AMB
"Lynn" wrote:
> ok, amb, but are you suggesting i do not create a compound pk on these thr
ee
> columns and that a unique index or unique constraint will suffice, or are
you
> suggesting i should do the compound pk but that it should be non-clustered
?
> --
> Lynn
>
> "Alejandro Mesa" wrote:
>|||Yes, I understand that the identity column pk didn't prevent dupes, nor is i
t
portable at all. All it does is sequentially number the records and it has
no pertinence whatsoever to the actual data value. Except for very few
maintenace scripts, the data is never queried looking on identity value.
Hence, I'm changing it. But I'm not done yet. That's the reason for my
inquiry. I'm trying to find the best way to get us where we need to be. I
understand the three columns already imply a constraint to force the
uniqueness. But that constraint does not yet exist. I intend to drop the
existing pk and replace with one that is actually meaningful, and I feel it
should be based upon these three fields, which uniquely identify our data.
I've already done this in my dev bed as clustered, and I've actually read
that article before several times - it is what prompted me to cluster the pk
in the first place because of the remark near the bottom about wide indices.
But today i've been researching and have seen the nonclustered composite pk
referenced several times, so now I'm debating whether I've done it properly
and I thought I'd s a little advice.
--
Lynn
"Alejandro Mesa" wrote:
> Lynn,
> What I meant was that an identity column as pk, does not asure that there
> will not be duplicated rows by (tradetime,endpoint,ordernumber) and becaus
e
> these columns, as you said, equate to the primary key from a
> business-perspective then it should exists already a constraint to force t
he
> uniqueness by these columns. The question is if this unique index should b
e
> clustered or not?. I will also consider what Aaron is asking you for (is
> there any other table that is referencing this table?). Well, there are ot
her
> things to consider like if there are other columns that you use for range
> queries or are used in the "group by" clause, what is more important for y
ou
> "select" or "insert" performance, etc. Take a look to the article in the
> link, it can help you to understand what are the columns in your table pro
per
> for a clustered index.
>
> AMB
> "Lynn" wrote:
>|||>> Except for very few
maintenace scripts, the data is never queried looking on identity
value.
Hence, I'm changing it.<<
usually we need a stronger reason for changing a working system. What
are your other reasons?|||We have no unique ID. And many, many holes because of this.
--
Lynn
"AK" wrote:

> maintenace scripts, the data is never queried looking on identity
> value.
> Hence, I'm changing it.<<
> usually we need a stronger reason for changing a working system. What
> are your other reasons?
>|||> We have no unique ID. And many, many holes because of this.
AK is merely suggesting that you could easily add a UNIQUE CONSTRAINT or
INDEX to your three columns, and leave the rest as is. The IDENTITY doesn't
have to be the PK but you don't have to remove it completely if the system
will continue to work while it is still there. And you never know, you may
later want to use a skinnier pk than you three wide columns for related
tables (given that such things don't exist now, think about trying to undo
this change later).

Saturday, February 25, 2012

complex queries and performance

i have a question on the above mention... say if i need to run a batch
procedure with very complex and multiple set base CRUD functionalites, does
it make any difference if i break them down into 1 store procedure per query
or multiple query per procedure. Presumbly everything is set to run with no
lock, does it make any difference?It usually depends. Consider recompilations: what needs to be
recompiled if you refresh statistics on one table? What needs to be
recompiled when you add an index on one table? How much time does
recompilation take?

Sunday, February 19, 2012

Compiles / Sec on 2005

Hi All
I read somewhere that the compiles / sec performance counter should be used
to evaluate the risk involved in upgrating a SQL 2000 Server to a SQL 2005
server. That SQL 2005 is more CPU intensive on these tasks? Does anyone
have more documentation / information on the subject ?
Thanks
Elrond BishopWell since 2005 can compile at the statement level vs. the entire batch or
proc there can be considerable savings in recompile costs. It they are all
compiles that means none of the plans are being reused. In that case you may
be able to get some help with the Force Parameterization option or the use
of plan guides. See here for more details:
http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Elrond Bishop" <billgates@.microsoft.com> wrote in message
news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
> Hi All
> I read somewhere that the compiles / sec performance counter should be
> used to evaluate the risk involved in upgrating a SQL 2000 Server to a SQL
> 2005 server. That SQL 2005 is more CPU intensive on these tasks? Does
> anyone have more documentation / information on the subject ?
> Thanks
> Elrond Bishop|||The database has a lot of "Dynamic" SQL coming into the database from VB
strings executed through the conneciton object.. Bad programming practice I
know but very little we can do about it at the moment.
Should I be worried about a higher CPU usage in that case ?
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23ZmiGEpBIHA.1208@.TK2MSFTNGP05.phx.gbl...
> Well since 2005 can compile at the statement level vs. the entire batch or
> proc there can be considerable savings in recompile costs. It they are all
> compiles that means none of the plans are being reused. In that case you
> may be able to get some help with the Force Parameterization option or the
> use of plan guides. See here for more details:
> http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
> news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I read somewhere that the compiles / sec performance counter should be
>> used to evaluate the risk involved in upgrating a SQL 2000 Server to a
>> SQL 2005 server. That SQL 2005 is more CPU intensive on these tasks?
>> Does anyone have more documentation / information on the subject ?
>> Thanks
>> Elrond Bishop
>|||Not only CPU, but also RAM and Network...
You may want to analyse that using SQL Server Profiler (make a workload file
and trace conditions of your queries) and Database Tuning Advisor for
getting some useful recommendation on your query commands (using that
workload file)?
From your message I understand that you are not with your current querying
solution but I just wanted to stress that it would be much much better using
SPs for quering against your database from your VB apps. Using SPs, you'll
not be able to change your hard-coded SPs for minor code changings (which
does not affect datasets that return to your app) and it would be more
secure and fast (SPs are much faster and better than ad hocs)
--
Ekrem Önsoy
"Elrond Bishop" <billgates@.microsoft.com> wrote in message
news:ORurkmpBIHA.3900@.TK2MSFTNGP02.phx.gbl...
> The database has a lot of "Dynamic" SQL coming into the database from VB
> strings executed through the conneciton object.. Bad programming practice
> I know but very little we can do about it at the moment.
> Should I be worried about a higher CPU usage in that case ?
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23ZmiGEpBIHA.1208@.TK2MSFTNGP05.phx.gbl...
>> Well since 2005 can compile at the statement level vs. the entire batch
>> or proc there can be considerable savings in recompile costs. It they are
>> all compiles that means none of the plans are being reused. In that case
>> you may be able to get some help with the Force Parameterization option
>> or the use of plan guides. See here for more details:
>> http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
>> news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I read somewhere that the compiles / sec performance counter should be
>> used to evaluate the risk involved in upgrating a SQL 2000 Server to a
>> SQL 2005 server. That SQL 2005 is more CPU intensive on these tasks?
>> Does anyone have more documentation / information on the subject ?
>> Thanks
>> Elrond Bishop
>|||I understand the importance of stored procedures. just dont have a choice in
the matter at the moment. there are +- 80 different VB applicaitons
countless lines of VBA and other methods of accessing the data. a bit of a
mess, but it was inherited. There is a project underway to move the
applications to SP's but thats going to take a while. there are also loads
and loads of SP based queries, so compiles may have been coming from that as
well. looking at an average of 3000 - 8000 connections during the day, 500
gig database.
"Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
news:E474511D-11F6-4CA3-B459-A4793192154A@.microsoft.com...
> Not only CPU, but also RAM and Network...
> You may want to analyse that using SQL Server Profiler (make a workload
> file and trace conditions of your queries) and Database Tuning Advisor for
> getting some useful recommendation on your query commands (using that
> workload file)?
> From your message I understand that you are not with your current querying
> solution but I just wanted to stress that it would be much much better
> using SPs for quering against your database from your VB apps. Using SPs,
> you'll not be able to change your hard-coded SPs for minor code changings
> (which does not affect datasets that return to your app) and it would be
> more secure and fast (SPs are much faster and better than ad hocs)
> --
> Ekrem Önsoy
>
> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
> news:ORurkmpBIHA.3900@.TK2MSFTNGP02.phx.gbl...
>> The database has a lot of "Dynamic" SQL coming into the database from VB
>> strings executed through the conneciton object.. Bad programming practice
>> I know but very little we can do about it at the moment.
>> Should I be worried about a higher CPU usage in that case ?
>>
>> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
>> news:%23ZmiGEpBIHA.1208@.TK2MSFTNGP05.phx.gbl...
>> Well since 2005 can compile at the statement level vs. the entire batch
>> or proc there can be considerable savings in recompile costs. It they
>> are all compiles that means none of the plans are being reused. In that
>> case you may be able to get some help with the Force Parameterization
>> option or the use of plan guides. See here for more details:
>> http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
>> news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I read somewhere that the compiles / sec performance counter should be
>> used to evaluate the risk involved in upgrating a SQL 2000 Server to a
>> SQL 2005 server. That SQL 2005 is more CPU intensive on these tasks?
>> Does anyone have more documentation / information on the subject ?
>> Thanks
>> Elrond Bishop
>>
>|||SQL 2005 will not increase the compile rates if they are already not reusing
the plans in 2000. It may in fact decrease it especially if you utilize some
of the features I mentioned earlier. But having said that the engine is
always evolving and the only way to know for sure is to test it under your
real life conditions. But the solution is really to fix the way the app
makes the calls so that you either use sps or format the calls so that they
can be reused via autoparameterizaion or sp_executesql.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Elrond Bishop" <billgates@.microsoft.com> wrote in message
news:ORurkmpBIHA.3900@.TK2MSFTNGP02.phx.gbl...
> The database has a lot of "Dynamic" SQL coming into the database from VB
> strings executed through the conneciton object.. Bad programming practice
> I know but very little we can do about it at the moment.
> Should I be worried about a higher CPU usage in that case ?
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23ZmiGEpBIHA.1208@.TK2MSFTNGP05.phx.gbl...
>> Well since 2005 can compile at the statement level vs. the entire batch
>> or proc there can be considerable savings in recompile costs. It they are
>> all compiles that means none of the plans are being reused. In that case
>> you may be able to get some help with the Force Parameterization option
>> or the use of plan guides. See here for more details:
>> http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
>> news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I read somewhere that the compiles / sec performance counter should be
>> used to evaluate the risk involved in upgrating a SQL 2000 Server to a
>> SQL 2005 server. That SQL 2005 is more CPU intensive on these tasks?
>> Does anyone have more documentation / information on the subject ?
>> Thanks
>> Elrond Bishop
>|||With a bunch of dynamic sql it is quite possible you could very much benefit
from FORCED PARAMETERIZATION setting in 2005, as Andrew mentioned. Dynamic
sql that does lots of statement calls where it simply changes the values in
one or more WHERE clause lines is a great example of code that would
benefit. The first execution would be parameterized and the (hopefully
index seek/bookmark lookup) query plan cached. then as the code looped
through the remaining where clause values (such as EmpID = 1, EmpID = 2 ...)
the cached query plan will be reused - saving a lot of effort on compiles.
I have seen this very thing result in 30-40% throughput inprovement at one
of my clients.
"Elrond Bishop" <billgates@.microsoft.com> wrote in message
news:ORurkmpBIHA.3900@.TK2MSFTNGP02.phx.gbl...
> The database has a lot of "Dynamic" SQL coming into the database from VB
> strings executed through the conneciton object.. Bad programming practice
> I know but very little we can do about it at the moment.
> Should I be worried about a higher CPU usage in that case ?
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23ZmiGEpBIHA.1208@.TK2MSFTNGP05.phx.gbl...
>> Well since 2005 can compile at the statement level vs. the entire batch
>> or proc there can be considerable savings in recompile costs. It they are
>> all compiles that means none of the plans are being reused. In that case
>> you may be able to get some help with the Force Parameterization option
>> or the use of plan guides. See here for more details:
>> http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "Elrond Bishop" <billgates@.microsoft.com> wrote in message
>> news:ODJKGvoBIHA.1208@.TK2MSFTNGP03.phx.gbl...
>> Hi All
>> I read somewhere that the compiles / sec performance counter should be
>> used to evaluate the risk involved in upgrating a SQL 2000 Server to a
>> SQL 2005 server. That SQL 2005 is more CPU intensive on these tasks?
>> Does anyone have more documentation / information on the subject ?
>> Thanks
>> Elrond Bishop
>

Sunday, February 12, 2012

Compatibility and Performance

Is there any performance hit when using a lower compatiblity mode? IE 70 instead of 90?

Compatibility level 70 means you are trying to SQL Server 7.0 mode? Is that what you really want to do? You obviously will not be able to use any SQL 2005 features.

Look for sp_dbcmptlevel in BOL and check out all the info.

|||

Yes we want the database to be in 7.0 mode. I understand the options. What I want to know is... is there a performance hit by using different compatiblity modes? Since SQL 2005 'performs' better than SQL 7 or SQL 2000, will we see any of that performance related to queries etc, or will the added overhead of the compatibility negate the performance improvements.

Also, what performance related issues are there to consider when using different modes, if any?

Thanks,

Raymond Laubert

MCDBA, MCITP:Administrator, MCT