Friday, March 30, 2012
optimizing queries
I am about to start system optimization and I have a general question about
how to proceed.
I am a coldfusion programmer and working on a lagre system with a lot of db
interaction. Recently, our isp upgraded to SQL 2000 and I started using
functions quite extensively for validation and calculations. I have a lot of
large queries that I am planning to transfer from coldfusion scripts to sql.
My question is:
SQL Server has few options for queries: stored procedures (I use them a lot
for complex logic), views and functions. What should I use for queries? For
example views can be indexed same as tables, stored procedures are compiled
and last one is functions (I dont think is such a good idea to store queries
but they can return tables). What are general recommendations?
Thanks in advance,
GeneThe answer: It depends.
If you can take part of your complex operation and make an indexed view, it
is certainly worthwhile, esp. if this view of information is used in more
than one procedure.
If the index will not help and there is no reuse, the procedures are the
best avenue for most work that performs CRUD on one or more tables.
Functions are used to solve problems outside of the data set realm (at
least, in general), like special calculations of aggregations or date
formatting outside of what is natively in SQL Server. For example, we had a
function like:
SELECT OurCustomerDateFormat(DateField) FROM SomeTable
That was a function.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"News" wrote:
> Hi,
> I am about to start system optimization and I have a general question abou
t
> how to proceed.
> I am a coldfusion programmer and working on a lagre system with a lot of d
b
> interaction. Recently, our isp upgraded to SQL 2000 and I started using
> functions quite extensively for validation and calculations. I have a lot
of
> large queries that I am planning to transfer from coldfusion scripts to sq
l.
> My question is:
> SQL Server has few options for queries: stored procedures (I use them a lo
t
> for complex logic), views and functions. What should I use for queries? Fo
r
> example views can be indexed same as tables, stored procedures are compile
d
> and last one is functions (I dont think is such a good idea to store queri
es
> but they can return tables). What are general recommendations?
> Thanks in advance,
> Gene
>
>|||>> I started using functions quite extensively for validation and calculatio
ns. <<
Usually a bad idea for validation. SQL is declarative and you want to
use CHECK() and DEFAULT clauses that apply to an entire column, rather
than triggers, functions and procedures which work on scalars.
I would go with stored procedures and VIEWs for the calculations.
Functions that return tables and indexed views are proprietary.
Wednesday, March 28, 2012
Optimizing Job fails on tables with computed fields
we have some tables in SQL Server 2000 with computed fields. When we try to
run an optimization job, it return the error
"Rebuilding indexes for table 'FI_Period'
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft][ODBC SQL
Server Driver][SQL Server]DBCC failed because the following SET options have
incorrect settings: 'QUOTED_IDENTIFIER'"
After removing the field the job runs without errors. I cannot see any link
between a computed field and the Quoted Identifier setting.
Any input is appreciated.
TIA, Norbert Meiss
See MSKB 301292 <http://support.microsoft.com/kb/q301292/>.
Hope this helps.
Dan Guzman
SQL Server MVP
"Norbert Meiss" <NorbertMeiss@.discussions.microsoft.com> wrote in message
news:436B7DE5-21CC-413B-A0D6-854FD3721894@.microsoft.com...
> Hi,
> we have some tables in SQL Server 2000 with computed fields. When we try
> to
> run an optimization job, it return the error
> "Rebuilding indexes for table 'FI_Period'
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft][ODBC
> SQL
> Server Driver][SQL Server]DBCC failed because the following SET options
> have
> incorrect settings: 'QUOTED_IDENTIFIER'"
> After removing the field the job runs without errors. I cannot see any
> link
> between a computed field and the Quoted Identifier setting.
> Any input is appreciated.
> TIA, Norbert Meiss
Optimizing Job fails on tables with computed fields
we have some tables in SQL Server 2000 with computed fields. When we try to
run an optimization job, it return the error
"Rebuilding indexes for table 'FI_Period'
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft][ODBC SQL
Server Driver][SQL Server]DBCC failed because the following SET options have
incorrect settings: 'QUOTED_IDENTIFIER'"
After removing the field the job runs without errors. I cannot see any link
between a computed field and the Quoted Identifier setting.
Any input is appreciated.
TIA, Norbert MeissSee MSKB 301292 <http://support.microsoft.com/kb/q301292/>.
Hope this helps.
Dan Guzman
SQL Server MVP
"Norbert Meiss" <NorbertMeiss@.discussions.microsoft.com> wrote in message
news:436B7DE5-21CC-413B-A0D6-854FD3721894@.microsoft.com...
> Hi,
> we have some tables in SQL Server 2000 with computed fields. When we try
> to
> run an optimization job, it return the error
> "Rebuilding indexes for table 'FI_Period'
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft][ODBC
> SQL
> Server Driver][SQL Server]DBCC failed because the following SET options
> have
> incorrect settings: 'QUOTED_IDENTIFIER'"
> After removing the field the job runs without errors. I cannot see any
> link
> between a computed field and the Quoted Identifier setting.
> Any input is appreciated.
> TIA, Norbert Meiss
Optimizing Job fails on tables with computed fields
we have some tables in SQL Server 2000 with computed fields. When we try to
run an optimization job, it return the error
"Rebuilding indexes for table 'FI_Period'
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft]
91;ODBC SQL
Server Driver][SQL Server]DBCC failed because the following SET options
have
incorrect settings: 'QUOTED_IDENTIFIER'"
After removing the field the job runs without errors. I cannot see any link
between a computed field and the Quoted Identifier setting.
Any input is appreciated.
TIA, Norbert MeissSee MSKB 301292 <http://support.microsoft.com/kb/q301292/>.
Hope this helps.
Dan Guzman
SQL Server MVP
"Norbert Meiss" <NorbertMeiss@.discussions.microsoft.com> wrote in message
news:436B7DE5-21CC-413B-A0D6-854FD3721894@.microsoft.com...
> Hi,
> we have some tables in SQL Server 2000 with computed fields. When we try
> to
> run an optimization job, it return the error
> "Rebuilding indexes for table 'FI_Period'
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1934: [Microsoft]
[ODBC
> SQL
> Server Driver][SQL Server]DBCC failed because the following SET option
s
> have
> incorrect settings: 'QUOTED_IDENTIFIER'"
> After removing the field the job runs without errors. I cannot see any
> link
> between a computed field and the Quoted Identifier setting.
> Any input is appreciated.
> TIA, Norbert Meiss
Wednesday, March 21, 2012
Optimizations & Integrity Check Jobs failing?
What would cause Optimization & Integrity Check jobs to fail? The agent info
shows SQL State = 42000, which, according to BOL is "Syntax error,
permission violation, or other nonspecific error. " Hmm... where to go from
here?
Thanks,
MorganI think I have found out what it is...
After further investigation, the server is running SQL Server personal
edition and was exceeding the 5 user limit, which I am guessing is causing
the jobs to not run and reporting back a generic error message.
"Morgan" <abcd@.senditon.com> wrote in message
news:ercGkiL7DHA.1428@.TK2MSFTNGP12.phx.gbl...
> Thanks in advance for any info.
> What would cause Optimization & Integrity Check jobs to fail? The agent
info
> shows SQL State = 42000, which, according to BOL is "Syntax error,
> permission violation, or other nonspecific error. " Hmm... where to go
from
> here?
>
> Thanks,
> Morgan
>
>|||The "5 user limit" shouldn't cause this. That is only a throttling mechanism
(very misunderstood, though). Are you using the maint wizard? If so, specify
a report file in the maint plan and check for the real error message in that
report file.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Morgan" <abcd@.senditon.com> wrote in message
news:OPPPEXM7DHA.2300@.TK2MSFTNGP10.phx.gbl...
> I think I have found out what it is...
> After further investigation, the server is running SQL Server personal
> edition and was exceeding the 5 user limit, which I am guessing is causing
> the jobs to not run and reporting back a generic error message.
> "Morgan" <abcd@.senditon.com> wrote in message
> news:ercGkiL7DHA.1428@.TK2MSFTNGP12.phx.gbl...
> > Thanks in advance for any info.
> >
> > What would cause Optimization & Integrity Check jobs to fail? The agent
> info
> > shows SQL State = 42000, which, according to BOL is "Syntax error,
> > permission violation, or other nonspecific error. " Hmm... where to go
> from
> > here?
> >
> >
> > Thanks,
> >
> > Morgan
> >
> >
> >
>|||Thanks, Tibor. Unfortunately we had to burn the SQL Server install and
install EE on the box. If it starts happening again, we'll hit the logs for
more detail.
Thanks again.
Morgan
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OfAd4CO7DHA.1596@.TK2MSFTNGP10.phx.gbl...
> The "5 user limit" shouldn't cause this. That is only a throttling
mechanism
> (very misunderstood, though). Are you using the maint wizard? If so,
specify
> a report file in the maint plan and check for the real error message in
that
> report file.
> --
> Tibor Karaszi, SQL Server MVP
> Archive at:
>
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
>
> "Morgan" <abcd@.senditon.com> wrote in message
> news:OPPPEXM7DHA.2300@.TK2MSFTNGP10.phx.gbl...
> > I think I have found out what it is...
> > After further investigation, the server is running SQL Server personal
> > edition and was exceeding the 5 user limit, which I am guessing is
causing
> > the jobs to not run and reporting back a generic error message.
> >
> > "Morgan" <abcd@.senditon.com> wrote in message
> > news:ercGkiL7DHA.1428@.TK2MSFTNGP12.phx.gbl...
> > > Thanks in advance for any info.
> > >
> > > What would cause Optimization & Integrity Check jobs to fail? The
agent
> > info
> > > shows SQL State = 42000, which, according to BOL is "Syntax error,
> > > permission violation, or other nonspecific error. " Hmm... where to go
> > from
> > > here?
> > >
> > >
> > > Thanks,
> > >
> > > Morgan
> > >
> > >
> > >
> >
> >
>
Optimizations & Integrity Check Jobs failing?
What would cause Optimization & Integrity Check jobs to fail? The agent info
shows SQL State = 42000, which, according to BOL is "Syntax error,
permission violation, or other nonspecific error. " Hmm... where to go from
here?
Thanks,
MorganI think I have found out what it is...
After further investigation, the server is running SQL Server personal
edition and was exceeding the 5 user limit, which I am guessing is causing
the jobs to not run and reporting back a generic error message.
"Morgan" <abcd@.senditon.com> wrote in message
news:ercGkiL7DHA.1428@.TK2MSFTNGP12.phx.gbl...
> Thanks in advance for any info.
> What would cause Optimization & Integrity Check jobs to fail? The agent
info
> shows SQL State = 42000, which, according to BOL is "Syntax error,
> permission violation, or other nonspecific error. " Hmm... where to go
from
> here?
>
> Thanks,
> Morgan
>
>|||The "5 user limit" shouldn't cause this. That is only a throttling mechanism
(very misunderstood, though). Are you using the maint wizard? If so, specify
a report file in the maint plan and check for the real error message in that
report file.
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"Morgan" <abcd@.senditon.com> wrote in message
news:OPPPEXM7DHA.2300@.TK2MSFTNGP10.phx.gbl...
> I think I have found out what it is...
> After further investigation, the server is running SQL Server personal
> edition and was exceeding the 5 user limit, which I am guessing is causing
> the jobs to not run and reporting back a generic error message.
> "Morgan" <abcd@.senditon.com> wrote in message
> news:ercGkiL7DHA.1428@.TK2MSFTNGP12.phx.gbl...
> info
> from
>|||Thanks, Tibor. Unfortunately we had to burn the SQL Server install and
install EE on the box. If it starts happening again, we'll hit the logs for
more detail.
Thanks again.
Morgan
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OfAd4CO7DHA.1596@.TK2MSFTNGP10.phx.gbl...
> The "5 user limit" shouldn't cause this. That is only a throttling
mechanism
> (very misunderstood, though). Are you using the maint wizard? If so,
specify
> a report file in the maint plan and check for the real error message in
that
> report file.
> --
> Tibor Karaszi, SQL Server MVP
> Archive at:
>
http://groups.google.com/groups?oi=...ublic.sqlserver
>
> "Morgan" <abcd@.senditon.com> wrote in message
> news:OPPPEXM7DHA.2300@.TK2MSFTNGP10.phx.gbl...
causing
agent
>
optimization, comparing execution plan
inefficiency in the code (a loop that executed the same expensive SQL
multiple times), and so I re-implemented a large portion of que code.
Because of this I'm having trouble comparing the 'efficiency' of the new sp
over the old one, because I'm not sure how to compare measurements from the
execution plan between the two functions. If I'm optimizing one sp, it's
easy to see the optimization is good when the cost numbers in the same code
paths start decreasing. But I don't think these numbers have any meaning
when comparing between two different functions with different execution
paths altogether.
So, how would you recommend I compare the two so that I can definitively say
the new sp is faster and more efficient than the old one?
Thanks.axis
To compare both sp
DBCC DROPCLEANBUFFERS
SET STATISTICS IO ON
SET STATISTICS TIME ON
--Run First one
DBCC DROPCLEANBUFFERS
SET STATISTICS IO ON
SET STATISTICS TIME ON
--Run second one
"axis" <none@.none.com> wrote in message
news:4253f751$1@.news.microsoft.com...
> I have a sp that was taking longer than it should. I found a large
> inefficiency in the code (a loop that executed the same expensive SQL
> multiple times), and so I re-implemented a large portion of que code.
> Because of this I'm having trouble comparing the 'efficiency' of the new
sp
> over the old one, because I'm not sure how to compare measurements from
the
> execution plan between the two functions. If I'm optimizing one sp, it's
> easy to see the optimization is good when the cost numbers in the same
code
> paths start decreasing. But I don't think these numbers have any meaning
> when comparing between two different functions with different execution
> paths altogether.
> So, how would you recommend I compare the two so that I can definitively
say
> the new sp is faster and more efficient than the old one?
> Thanks.
>|||Thanks. I had tried that and it comes back with 30 to 40 lines of time
measurements (it seems to measure each statement execution). Is there a way
to just get the sp execution time?
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:esjQGnrOFHA.1476@.TK2MSFTNGP09.phx.gbl...
> axis
> To compare both sp
> DBCC DROPCLEANBUFFERS
> SET STATISTICS IO ON
> SET STATISTICS TIME ON
> --Run First one
> DBCC DROPCLEANBUFFERS
> SET STATISTICS IO ON
> SET STATISTICS TIME ON
> --Run second one
>
>
> "axis" <none@.none.com> wrote in message
> news:4253f751$1@.news.microsoft.com...
> sp
> the
> code
> say
>|||If I turn on TIME and execute one SP, would adding up all the "elapsed time
= #ms" messages I get give me a rough estimate of the sp's execution time?
"axis" <none@.none.com> wrote in message news:4253fb31@.news.microsoft.com...
> Thanks. I had tried that and it comes back with 30 to 40 lines of time
> measurements (it seems to measure each statement execution). Is there a
way
> to just get the sp execution time?
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:esjQGnrOFHA.1476@.TK2MSFTNGP09.phx.gbl...
new
from
it's
meaning
execution
definitively
>|||Uri,
Did you mean DBCC FREEPROCCACHE?
AMB
"Uri Dimant" wrote:
> axis
> To compare both sp
> DBCC DROPCLEANBUFFERS
> SET STATISTICS IO ON
> SET STATISTICS TIME ON
> --Run First one
> DBCC DROPCLEANBUFFERS
> SET STATISTICS IO ON
> SET STATISTICS TIME ON
> --Run second one
>
>
> "axis" <none@.none.com> wrote in message
> news:4253f751$1@.news.microsoft.com...
> sp
> the
> code
> say
>
>|||A quick way would be to compare the execution plan of the old and
optimized SP in one go. Highlight the two stored procedures and do
Ctrl-L, this should show you the relative query cost of one over the
other.
Aramid
On Wed, 6 Apr 2005 10:50:22 -0400, "axis" <none@.none.com> wrote:
>I have a sp that was taking longer than it should. I found a large
>inefficiency in the code (a loop that executed the same expensive SQL
>multiple times), and so I re-implemented a large portion of que code.
>Because of this I'm having trouble comparing the 'efficiency' of the new sp
>over the old one, because I'm not sure how to compare measurements from the
>execution plan between the two functions. If I'm optimizing one sp, it's
>easy to see the optimization is good when the cost numbers in the same code
>paths start decreasing. But I don't think these numbers have any meaning
>when comparing between two different functions with different execution
>paths altogether.
>So, how would you recommend I compare the two so that I can definitively sa
y
>the new sp is faster and more efficient than the old one?
>Thanks.
>|||On Wed, 6 Apr 2005 11:06:51 -0400, axis wrote:
>Thanks. I had tried that and it comes back with 30 to 40 lines of time
>measurements (it seems to measure each statement execution). Is there a way
>to just get the sp execution time?
Hi Axis,
Here's a method that I often use:
-- First, write dirty buffers to disk and clear the data cache,
-- so that measuring is not influenced by logical vs physical I/O
CHECKPOINT
DBCC DROPCLEANBUFFERS
-- Also clear out the procedure cache to get rid of old plans
DBCC FREEPROCCACHE
go
DECLARE @.started datetime, @.ended datetime
SET @.started = CURRENT_TIMESTAMP
/* Insert code to performance-test here */
SET @.ended = CURRENT_TIMESTAMP
SELECT DATEDIFF(ms, @.started, @.ended) AS "ms elapsed"
go
Perform your tests when noone else is using the system. Run the test a
couple of times and use the average execution time (even when noone is
using the server, there might be maintenance processes or OS overhead
kicking in from time to time).
If the code isn't very long-running, you might include a loop to execute
it 10 times before calculating elapsed time. The first one will run
slower (since data has to be read into cache), the next executions will
read data from cache, so that other efficiency aspects than just
physical I/O will influence the results.
Oh, before I forget - if the code to be tested includes queries that
return data to the front-end and the results are more than just a few
rows, than you should modify this to SELECT ... INTO #Temp FROM ...
This will route the output to a temp table instead of to the QA output
window. If you don't do this, you'll only measure how fast QA can
format, display and scroll the result set...
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Optimization Within ForEachLoop For Iteration Through A Large DataSet.
I am a novice and am still learning with this new tool:
I am Iterating through a DataSet that is stored in a variable as an object.
The Data Set contains approximately 10,000 lines of data ( here in lies the problem)
I am using a ForEachLoop container to iterate through this large set of data:
In the loop are several ExecuteSQLTasks, which may or may not return a results.
There are roughly 12 tasks here.
At the end of the 12 tasks I do an Update.
I find the processing to be slow. Even after:
- placing the iteration into a separate package and calling it out of process.
From what I've read on the forum, execution should be quite fast
Could someone enlighten me on how execution is called within the ForEachLoop, are there solutions I can pursue ? Or should I rethink the design?
your help is greatly appreciatedIf you could build your process using data flows instead of Exec SQL, I think your performance will go up. It sounds like you are inserting/updating each row individually, rather than treating it as a batch. SSIS performs much better when you make use of the data flow components, and handle your processing within the data flow.|||Thank You Very Much for you Prompt Reply John.
Yes I have been following your advice. Hence my Tardy Reply.
With some design changes, appropriate lookups and parallel processing
I've managed to successfully execute the package under 10 minutes.
Though I'm sure there is room for Improvement.
Once again thank you for your advice.|||
Glad to help. Do you mind marking my response as an answer? It helps others searching the forums to find useful information.
Be sure to post if you need anything else.
Optimization Within ForEachLoop For Iteration Through A Large DataSet.
I am a novice and am still learning with this new tool:
I am Iterating through a DataSet that is stored in a variable as an object.
The Data Set contains approximately 10,000 lines of data ( here in lies the problem)
I am using a ForEachLoop container to iterate through this large set of data:
In the loop are several ExecuteSQLTasks, which may or may not return a results.
There are roughly 12 tasks here.
At the end of the 12 tasks I do an Update.
I find the processing to be slow. Even after:
- placing the iteration into a separate package and calling it out of process.
From what I've read on the forum, execution should be quite fast
Could someone enlighten me on how execution is called within the ForEachLoop, are there solutions I can pursue ? Or should I rethink the design?
your help is greatly appreciatedIf you could build your process using data flows instead of Exec SQL, I think your performance will go up. It sounds like you are inserting/updating each row individually, rather than treating it as a batch. SSIS performs much better when you make use of the data flow components, and handle your processing within the data flow.|||Thank You Very Much for you Prompt Reply John.
Yes I have been following your advice. Hence my Tardy Reply.
With some design changes, appropriate lookups and parallel processing
I've managed to successfully execute the package under 10 minutes.
Though I'm sure there is room for Improvement.
Once again thank you for your advice.|||
Glad to help. Do you mind marking my response as an answer? It helps others searching the forums to find useful information.
Be sure to post if you need anything else.
Optimization with ORs
select from table where col1=x and (col2 = y or col3=z)
It results in terrible performance. It seems to me that there is no way to
make an index which really covers a statement like this. I can either index
on col1, col2 or col1, col3; an index on col1, col2, col3 is not really of
any value. Is this correct? If so, how can I improve performance in this
situation? Do I need 2 indexes? Do I just index col1 and leave it at that?
Thanks,
ChrisYou can use the Show Execution Plan feature of Query Analyzer to see exactly
how your query is utilizing indexes.
http://msdn.microsoft.com/library/d... />
1_5pde.asp
If col2 or col3 is highly selective (for example zipcode or date of birth),
then an additional index here would be useful.
http://www.sql-server-performance.c...s_not_equal.asp
SQL Server's query optimizer may even ignore an index when building the
execution plan if the index is not judged as selective enough for it's case
usage.
http://www.sql-server-performance.com/statistics.asp
http://msdn.microsoft.com/library/d.../>
sz_4fxv.asp
"querylous" <querylous@.discussions.microsoft.com> wrote in message
news:63A055ED-F3D7-4D95-B887-5F9C16C03F35@.microsoft.com...
> Hi- I notice that many times when I use an "or" in a query with an and
> select from table where col1=x and (col2 = y or col3=z)
> It results in terrible performance. It seems to me that there is no way to
> make an index which really covers a statement like this. I can either
> index
> on col1, col2 or col1, col3; an index on col1, col2, col3 is not really of
> any value. Is this correct? If so, how can I improve performance in this
> situation? Do I need 2 indexes? Do I just index col1 and leave it at that?
> Thanks,
> Chris|||"querylous" <querylous@.discussions.microsoft.com> wrote in message
news:63A055ED-F3D7-4D95-B887-5F9C16C03F35@.microsoft.com...
> Hi- I notice that many times when I use an "or" in a query with an and
> select from table where col1=x and (col2 = y or col3=z)
> It results in terrible performance. It seems to me that there is no way to
> make an index which really covers a statement like this. I can either
> index
> on col1, col2 or col1, col3; an index on col1, col2, col3 is not really of
> any value. Is this correct? If so, how can I improve performance in this
> situation? Do I need 2 indexes? Do I just index col1 and leave it at that?
> Thanks,
> Chris
Have you tried a covering index on col1/col2 and another on col1/col3?
Also, try rewritting the query using Union All:
select from table where col1=x and col2 = y
union all
select from table where col1=x and col3 = z|||Chris,
a lot depends on selectivity of the columns. For instance, if col1 is
highly selective, then an index on (col1, col2, col3) might be very
useful.|||Raymond,
a minor correction:
select from table where col1=x and col2 = y
union all
select from table where col1=x and col3 = z
-- do not introduce duplicates
and not(col2 = y)|||Would a Union really be any faster than an or? Isn't it essentially the same
thing?
Chris
"Alexander Kuznetsov" wrote:
> Raymond,
> a minor correction:
> select from table where col1=x and col2 = y
> union all
> select from table where col1=x and col3 = z
> -- do not introduce duplicates
> and not(col2 = y)
>|||You've mentionned queries with terrible performance.
Modify one of them using Union and compare.
I can't say that this will solve all your problems though.
"querylous" <querylous@.discussions.microsoft.com> wrote in message
news:400D4757-8B2B-4DB2-9A78-92683567A820@.microsoft.com...
> Would a Union really be any faster than an or? Isn't it essentially the
> same
> thing?
> Chris
> "Alexander Kuznetsov" wrote:
>|||Chris,
in some cases a query with OR will be executed as a table/clustered
index scan. Rewriting it as a UNION, you may get the same results
retrieved by 2 index s
not a UNION ALL. I don't think anybody can tell you what's better in
your case without getting more information|||Good catch Alex.
"Alexander Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1140796390.674385.23120@.v46g2000cwv.googlegroups.com...
> Raymond,
> a minor correction:
> select from table where col1=x and col2 = y
> union all
> select from table where col1=x and col3 = z
> -- do not introduce duplicates
> and not(col2 = y)
>|||Xref: TK2MSFTNGP08.phx.gbl microsoft.public.sqlserver.programming:587028
If you have many queries like that, then maybe your schema is not
properly normalized. Do you have a real life example?
Gert-Jan
querylous wrote:
> Hi- I notice that many times when I use an "or" in a query with an and
> select from table where col1=x and (col2 = y or col3=z)
> It results in terrible performance. It seems to me that there is no way to
> make an index which really covers a statement like this. I can either inde
x
> on col1, col2 or col1, col3; an index on col1, col2, col3 is not really of
> any value. Is this correct? If so, how can I improve performance in this
> situation? Do I need 2 indexes? Do I just index col1 and leave it at that?
> Thanks,
> Chrissql
Optimization tips for Cursor and Scope_Identity
...This is for a data migration project which involves the splitting of a
flat file into two or more tables with relationships. The migration will
happen over time and not at one time.
...My SQL Server/DB experience up to this point has been primarily focused
on client side request, but am pretty short on optimization... so I need som
e
direction here. I can research via Google, BOL and forums, but I don't even
know where to start.
I am currently using a cursor to walk through rows in tblMigration and build
an insert statement for tblParent. I am using the cursor becuase I need to
capture the new identity value (SCOPE_IDENTITY) after each insert into
tblParent and use it to migrate the rest of the records destined for the
various child tables in the new schema.
I am moving data from one server to another and have set up a linked server.
currently a migration of 53,000 records is taking 42 min (on my dev box:
WINXP, 1GB ram, 2 GHZ).
I originally wanted to do the following, but was told this would play havoc
with replication
1. ALTER tblParent ADD old_id BIGINT
2. INSERT tblParent (field1,field2,old_id) SELECT field1, field2, id FROM
tblMigration WHERE field1='parent'
3. do remaing migration relating the tblParent.old_id to tblMIgration.id fie
ld
4. and then drop the old_id collumn from tblParent
Once again, I have not posted actual TSQL because it would be very long and
I just need the pointer in the right direction... but if that would help, le
t
me know.
thanks
KevinHavoc with replication? How?
> I originally wanted to do the following, but was told this would play
> havoc
> with replication
> 1. ALTER tblParent ADD old_id BIGINT
> 2. INSERT tblParent (field1,field2,old_id) SELECT field1, field2, id FROM
> tblMigration WHERE field1='parent'
> 3. do remaing migration relating the tblParent.old_id to tblMIgration.id
> field
> 4. and then drop the old_id collumn from tblParent
Either way, if you have a natural key in the field1 or field2 combination
that you can use for getting the surrogate (identity) key that is even
better.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"kevin" <kevin@.discussions.microsoft.com> wrote in message
news:1A0B0471-24CF-414D-AE0B-5EF830993828@.microsoft.com...
> ...using SQL 2K
> ...This is for a data migration project which involves the splitting of a
> flat file into two or more tables with relationships. The migration will
> happen over time and not at one time.
> ...My SQL Server/DB experience up to this point has been primarily focused
> on client side request, but am pretty short on optimization... so I need
> some
> direction here. I can research via Google, BOL and forums, but I don't
> even
> know where to start.
> I am currently using a cursor to walk through rows in tblMigration and
> build
> an insert statement for tblParent. I am using the cursor becuase I need
> to
> capture the new identity value (SCOPE_IDENTITY) after each insert into
> tblParent and use it to migrate the rest of the records destined for the
> various child tables in the new schema.
> I am moving data from one server to another and have set up a linked
> server.
> currently a migration of 53,000 records is taking 42 min (on my dev box:
> WINXP, 1GB ram, 2 GHZ).
> I originally wanted to do the following, but was told this would play
> havoc
> with replication
> 1. ALTER tblParent ADD old_id BIGINT
> 2. INSERT tblParent (field1,field2,old_id) SELECT field1, field2, id FROM
> tblMigration WHERE field1='parent'
> 3. do remaing migration relating the tblParent.old_id to tblMIgration.id
> field
> 4. and then drop the old_id collumn from tblParent
> Once again, I have not posted actual TSQL because it would be very long
> and
> I just need the pointer in the right direction... but if that would help,
> let
> me know.
> thanks
> Kevin
>|||"Louis Davidson" wrote:
> Havoc with replication? How?
>
I was told, by our SQL DBA, that ad-hoc schema changes would not be allowed
with replication. Now I am not certain if he meant
1. that replication, by design, would cause any schema changes to fail
2. that schema changes would be in violation of business rules because they
would break replication and thus I was not to do this or
3. that replication would destroy any schema changes I made by overwritting
them
I am working on the understanding, a bit fuzzy as it is, that replication
essentially is a manage procedure for copying database schema and data
changes from one server to another as a form of backup and/or security.
Suffice it to say, I was explicity told "No schema changes". Personnaly I
don't see the big deal wth adding collumns as this will be invisible to any
client apps unless they are calculating the ordinal position of particular
collumns... which would be pretty insane.
In either case saying that a migration of a midsized client would take 40
minutes got a consession. I will throwing my old_id into an existing collum
n
that would never be populated by legacy records on the most critical part of
the migration.
I will still have to use cursors for some of the smaller tables.
If there is a way to optimize (hints etc), I would love the input.
thanks.
Kevin
"Louis Davidson" wrote:
> Havoc with replication? How?
>
Optimization technique
What is the optimization technique used by SqlServer dbms?
Thankscost based optimisation IIRC
Optimization Rules for XML Bulk Insert
I was wondering if there were any guide lines to optimize the XML Bulk
Insert component by using different XML formats. I read an article that did
cases, but can't remember where I saw it.
Thank for any help!
-Frank
I found what I was looking for.
http://msdn.microsoft.com/library/de...erformance.asp
If anyone wanted to know also.
"Frank DeLuccia" <fdeluccia-RemoveThisInsert-@.edifice-ims.com> wrote in
message news:OMsHu%239REHA.3984@.TK2MSFTNGP11.phx.gbl...
> Hello Again,
> I was wondering if there were any guide lines to optimize the XML Bulk
> Insert component by using different XML formats. I read an article that
did
> cases, but can't remember where I saw it.
> Thank for any help!
> -Frank
>
Optimization Required for User Defined Function
I've an UDF which inside has two query joined by union and it 's similar to this
select * from Table1 ... (several conditions)
union
select * from Table2 ... (several conditions) (this could takes long time to run)
Since i can't write dynamic sql into UDF , i can't avoid to insert Table2 into the query but to improve permormance I've seen how costant can help me.
For Example if I change my UDF in
select * from Table1 ... (several conditions)
union
select * from Table2 Where 1=2 AND (several conditions)
Optimazer is able to skip completely the second execution, so i need to transform 1=2 into a dynamic condition for example test a field table existence.
select * from Table2 Where Exist (select * from Table3 where Field1=1)
That is why i try to write a single UDF can adapt itself to several situations using second condition only where is necessary and not always.
The problem is the dynamic condition for simple could be, wasn't recognize as costant.
For Example
select top 1 * from MyTable where (select 1)=2
select top 1 * from MyTable where 1=2
If you see the execution plan of these 2 queries you could see that the first takes more than 80% of execution time and in the second less than 20%.
Moreover the second plan use a costant scan unlike the first doesn't it.
Do anyone know a way to tell to optimizer to use a simple condition as constant ? This improve drastically my UDF performance.... :( :(
Thanks.1) why is it essential to make it a function and not procedure or view.
2) how do u find
..you could see that the first takes more than 80% of execution time and in the second less than 20%...
if u r referring to execution-plan these % values relative to the batch and does not represent an absolute value. and practically both are taking 0 sec in my machine.
3) if u use "select" in a "where" it is evaluated once for each row of the outer query hence is inefficient.
Optimization Question: Date ranges, Between Operaror and Clustered Index
are too many hits for my key words, so I'll ask these questions afresh:
1) Is it reasonable to expect improved performance by putting the
clustered index on the field you most use for RANGE searches.
2) Is there any reason you wouldn't create a clustered index on a
DateTime field, if the data in that field was autogenerated by
the server clock and moved only forward chronologically?
3) Is the BETWEEN operator slower than >= and <= Is this ... CallDate BETWEEN '2004-01-15' AND '2004-01-23'
faster or slower than this ...
CallDate >='2004-01-15' AND CallDate <= '2004-01-23'
Thanks in advance for any feedback you have to give on these issues.
--
Danny J. Lesandrini
dlesandrini@.hotmail.com
http://amazecreations.com/datafast/"Danny J. Lesandrini" <dlesandrini@.hotmail.com> wrote in message
news:eDFKzxTVEHA.2508@.TK2MSFTNGP12.phx.gbl...
> 1) Is it reasonable to expect improved performance by putting the
> clustered index on the field you most use for RANGE searches.
Most likely, yes.
> 2) Is there any reason you wouldn't create a clustered index on a
> DateTime field, if the data in that field was autogenerated by
> the server clock and moved only forward chronologically?
No, in my opinion that would be a good candidate for a clustered index
as it would create a hotspot at the end of the table, which is good for
insert performance.
> 3) Is the BETWEEN operator slower than >= and <=> Is this ... CallDate BETWEEN '2004-01-15' AND '2004-01-23'
> faster or slower than this ...
> CallDate >='2004-01-15' AND CallDate <= '2004-01-23'
No. But there are other issues to consider. See:
http://www.aspfaq.com/show.asp?id=2280|||Thanks Adam, that was exactly what I was looking for.
Danny
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:ucJkm8TVEHA.2944@.tk2msftngp13.phx.gbl...
> "Danny J. Lesandrini" <dlesandrini@.hotmail.com> wrote in message
> news:eDFKzxTVEHA.2508@.TK2MSFTNGP12.phx.gbl...
> >
> > 1) Is it reasonable to expect improved performance by putting the
> > clustered index on the field you most use for RANGE searches.
> Most likely, yes.
> > 2) Is there any reason you wouldn't create a clustered index on a
> > DateTime field, if the data in that field was autogenerated by
> > the server clock and moved only forward chronologically?
> No, in my opinion that would be a good candidate for a clustered index
> as it would create a hotspot at the end of the table, which is good for
> insert performance.
> > 3) Is the BETWEEN operator slower than >= and <=> > Is this ... CallDate BETWEEN '2004-01-15' AND '2004-01-23'
> > faster or slower than this ...
> > CallDate >='2004-01-15' AND CallDate <= '2004-01-23'
> No. But there are other issues to consider. See:
> http://www.aspfaq.com/show.asp?id=2280
>
>
>
>sql
Optimization Question: Date ranges, Between Operaror and Clustered Index
are too many hits for my key words, so I'll ask these questions afresh:
1) Is it reasonable to expect improved performance by putting the
clustered index on the field you most use for RANGE searches.
2) Is there any reason you wouldn't create a clustered index on a
DateTime field, if the data in that field was autogenerated by
the server clock and moved only forward chronologically?
3) Is the BETWEEN operator slower than >= and <=
Is this ... CallDate BETWEEN '2004-01-15' AND '2004-01-23'
faster or slower than this ...
CallDate >='2004-01-15' AND CallDate <= '2004-01-23'
Thanks in advance for any feedback you have to give on these issues.
--
Danny J. Lesandrini
dlesandrini@.hotmail.com
http://amazecreations.com/datafast/"Danny J. Lesandrini" <dlesandrini@.hotmail.com> wrote in message
news:eDFKzxTVEHA.2508@.TK2MSFTNGP12.phx.gbl...
> 1) Is it reasonable to expect improved performance by putting the
> clustered index on the field you most use for RANGE searches.
Most likely, yes.
> 2) Is there any reason you wouldn't create a clustered index on a
> DateTime field, if the data in that field was autogenerated by
> the server clock and moved only forward chronologically?
No, in my opinion that would be a good candidate for a clustered index
as it would create a hotspot at the end of the table, which is good for
insert performance.
> 3) Is the BETWEEN operator slower than >= and <=
> Is this ... CallDate BETWEEN '2004-01-15' AND '2004-01-23'
> faster or slower than this ...
> CallDate >='2004-01-15' AND CallDate <= '2004-01-23'
No. But there are other issues to consider. See:
http://www.aspfaq.com/show.asp?id=2280|||Thanks Adam, that was exactly what I was looking for.
Danny
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:ucJkm8TVEHA.2944@.tk2msftngp13.phx.gbl...
> "Danny J. Lesandrini" <dlesandrini@.hotmail.com> wrote in message
> news:eDFKzxTVEHA.2508@.TK2MSFTNGP12.phx.gbl...
> Most likely, yes.
>
> No, in my opinion that would be a good candidate for a clustered index
> as it would create a hotspot at the end of the table, which is good for
> insert performance.
>
> No. But there are other issues to consider. See:
> http://www.aspfaq.com/show.asp?id=2280
>
>
>
>
optimization question
ID|NAME|HITScolumns
ID is the primary key
NAME is nvarchar
HITS is int
I run this query, it takes less than a second
select top 40 * from table 1 order by id desc
but when i run this it take more than 10 seconds
select top 40 * from table 1 order by hits desc
hits column keeps track of time the page has been loaded
what can i do to make the second query run just as fast as the first one?Do you have an index on HIts? If not then you might want to add one.
Andrew J. Kelly SQL MVP
"Howard" <howdy0909@.yahoo.com> wrote in message
news:%23hSBkKSUGHA.5552@.TK2MSFTNGP14.phx.gbl...
>I have a table with a large amount of rows > 100 000 with
> ID|NAME|HITScolumns
> ID is the primary key
> NAME is nvarchar
> HITS is int
> I run this query, it takes less than a second
> select top 40 * from table 1 order by id desc
> but when i run this it take more than 10 seconds
> select top 40 * from table 1 order by hits desc
>
> hits column keeps track of time the page has been loaded
> what can i do to make the second query run just as fast as the first one?
>
>|||what type of index would you recommend? I ran the Database Engine Tuning
Advisor it didn't give me anything
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:u0g2bRSUGHA.5552@.TK2MSFTNGP14.phx.gbl...
> Do you have an index on HIts? If not then you might want to add one.
> --
> Andrew J. Kelly SQL MVP
>
> "Howard" <howdy0909@.yahoo.com> wrote in message
> news:%23hSBkKSUGHA.5552@.TK2MSFTNGP14.phx.gbl...
>|||You really only have two choices here. A clustered or a Nonclustered index.
I assume you already have a clustered index on ID. So try adding a
non-clustered index on Hits and see if it helps.
Andrew J. Kelly SQL MVP
"Howard" <howdy0909@.yahoo.com> wrote in message
news:e$EfRUSUGHA.5500@.TK2MSFTNGP12.phx.gbl...
> what type of index would you recommend? I ran the Database Engine Tuning
> Advisor it didn't give me anything
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:u0g2bRSUGHA.5552@.TK2MSFTNGP14.phx.gbl...
>
Optimization Processing Cube Duration In SSAS 2005
i need to optimize the duration of processing Cube,Fact table Record Count 100,00,00,00 Recoreds Current Duration Almost 18 hours
If any one Know how to Optimize Performance Please advice me
The main boost in performance you will get once you partition you cube.
Create partitions in your measure group and start processing them in parallel.
Please note the partitions are feature of Enterprise edition of SQL Server Analysis Services.
Take a look at the project REAL. http://www.microsoft.com/technet/prodtechnol/sql/2005/realastd.mspx for an example of how to partition your data and achieve processing performance.
Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Optimization problem
I got a problem when run optimization. In SQL 7, transaction log usage is
very limit but after upgraded to SQL 2000, found the optimization job ate 9G
transaction (the db size is 21G). How can I limit the transaction log usage?
Thanks & regards,
henryHi,
you can set maximum size of the log. But then set an alert to notify you
when log is nearly full.
Other good way to keep tran log small is to regulary backup it...
Danijel
"Monster Henry" <henry@.monster.com> wrote in message
news:eJnzn3cAFHA.3592@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I got a problem when run optimization. In SQL 7, transaction log usage is
> very limit but after upgraded to SQL 2000, found the optimization job ate
> 9G transaction (the db size is 21G). How can I limit the transaction log
> usage?
> Thanks & regards,
> henry
>|||Hi
The transaction log growing due to a Index Re-Builds are expected. Since the
operation is fully logged, you need as much space (1.2 times) as the biggest
table when a clustered index is re-built.
Regards
Mike
"Monster Henry" wrote:
> Hi,
> I got a problem when run optimization. In SQL 7, transaction log usage is
> very limit but after upgraded to SQL 2000, found the optimization job ate 9G
> transaction (the db size is 21G). How can I limit the transaction log usage?
> Thanks & regards,
> henry
>
>sql
Optimization problem
I got a problem when run optimization. In SQL 7, transaction log usage is
very limit but after upgraded to SQL 2000, found the optimization job ate 9G
transaction (the db size is 21G). How can I limit the transaction log usage?
Thanks & regards,
henry
Hi,
you can set maximum size of the log. But then set an alert to notify you
when log is nearly full.
Other good way to keep tran log small is to regulary backup it...
Danijel
"Monster Henry" <henry@.monster.com> wrote in message
news:eJnzn3cAFHA.3592@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I got a problem when run optimization. In SQL 7, transaction log usage is
> very limit but after upgraded to SQL 2000, found the optimization job ate
> 9G transaction (the db size is 21G). How can I limit the transaction log
> usage?
> Thanks & regards,
> henry
>
|||Hi
The transaction log growing due to a Index Re-Builds are expected. Since the
operation is fully logged, you need as much space (1.2 times) as the biggest
table when a clustered index is re-built.
Regards
Mike
"Monster Henry" wrote:
> Hi,
> I got a problem when run optimization. In SQL 7, transaction log usage is
> very limit but after upgraded to SQL 2000, found the optimization job ate 9G
> transaction (the db size is 21G). How can I limit the transaction log usage?
> Thanks & regards,
> henry
>
>