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

Thursday, March 22, 2012

BigInt performance on SQL 64

Has anyone done some benchmarks of BigInt vs. Int on SQL Server
2000/2005 64 bit? If so I would like to know what your conclusion was.Performance in regards to what? A bigint is twice the size of an Int so it
will take up twice the memory and disk space for tables and indexes. You
really shouldn't be looking at performance to make a decision such as this.
You need to consider the data that you will be storing in that column. What
will the business rules dictate. Why use a BigInt when an Int will suffice?
Why use an Int if it can't hold your largest value?
Andrew J. Kelly SQL MVP
"Will" <whbmitchell@.gmail.com> wrote in message
news:1139525534.880875.88630@.o13g2000cwo.googlegroups.com...
> Has anyone done some benchmarks of BigInt vs. Int on SQL Server
> 2000/2005 64 bit? If so I would like to know what your conclusion was.
>|||I have. BigInt will store a much larger number than Int will. So storing a
really big number in and Int will be much slower than with a BigInt :)
Seriously, I too would like to hear if there is any difference.
Since it is just 8 bytes instead of 4 bytes, it will be a bit slower, for
many reasons on any version because at the very least a bit more disk space
will be required. Fact is, if you need a BigInt, use it, otherwise use an
int. I wouldn't expect to do much math on a number > 2 billion, (certainly
not extensively,) and that is where a minute difference might be noticed
based on 32 or 64 bit hardware, though even on 64 bit hardware the Int
"shouldn't" be slower than the BigInt, since math would be done in the same
hardware, just probably no "tricks" to deal with the number that is bigger
than the native registers.
Do you have any specific instances where you think it was slower?
----
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)
"Will" <whbmitchell@.gmail.com> wrote in message
news:1139525534.880875.88630@.o13g2000cwo.googlegroups.com...
> Has anyone done some benchmarks of BigInt vs. Int on SQL Server
> 2000/2005 64 bit? If so I would like to know what your conclusion was.
>

bigint or uniqueidentifer performance metrics?

If the use of the uniqueidentifier is now preferred, across how many
relations is it optimal to use as the type for primary keys? Is there some
point other than performance why one should not worry about reverting to the
use of bigint for related tables? I've only read a couple of stories about
it so far. What do you think?
<%= Clinton GallagherClinton
I would try to avoid using GUID as a Primary Key.
GUIDs take up 16-bytes of storage, more than an Identify column, which in
turn make the index larger, which increases I/O reads, which can hurt
performance. While the performance hit will be minimal if you do decide to
add a clustered index to a GUID column, every little bit adds up
"clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
news:%2388qeVoOGHA.1832@.TK2MSFTNGP11.phx.gbl...
> If the use of the uniqueidentifier is now preferred, across how many
> relations is it optimal to use as the type for primary keys? Is there some
> point other than performance why one should not worry about reverting to
> the use of bigint for related tables? I've only read a couple of stories
> about it so far. What do you think?
> <%= Clinton Gallagher
>|||That's what I read Uri but then on the next article GUIDs are praised not to
mention their use in the aspnet_Users table as well as other tables in the
ASP.NET 2.0 Membership, Roles and Profiles implementation Microsoft has
provided.
I think I'll just use their GUID as a foreign key and revert to bigint for
primary keys. It seems there are benefits for grabbing the last inserted
record using @.@.IDENTITY which GUID does not support.
I'm also trying to figure out how to use GUID as a primary key -- anyway --
and auto-generate the value using the newid( ) default binding. I've tried
learning to use newid( ) by entering data into the table but all I get to
see is red circles with ! and error messages or the red circles and no error
messages.
Thanks for your attention...
<%= Clinton Gallagher
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eqYqhBqOGHA.2300@.TK2MSFTNGP15.phx.gbl...
> Clinton
> I would try to avoid using GUID as a Primary Key.
> GUIDs take up 16-bytes of storage, more than an Identify column, which in
> turn make the index larger, which increases I/O reads, which can hurt
> performance. While the performance hit will be minimal if you do decide to
> add a clustered index to a GUID column, every little bit adds up
>
> "clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
> news:%2388qeVoOGHA.1832@.TK2MSFTNGP11.phx.gbl...
>|||This is kind of a confusing question, since you really need to give us more
information. Do you have tables that you need to store > 4 billion row? In
2005 there is a way to create an always increasing guid using
newsequentialid that can help a bit with the problems that using a GUID for
a key can create, but GUIDs make fine surrogate keys for tables, other than
performance and typability (the latter of which is just a programmer
convienience, so should not be really important to the question of whether
to choose them or not)
If you need the benefits of a GUID (like the UI can create them and be
guaranteed uniqueness,) then it might be worth it, otherwise use the correct
integer type. If you are going to have > 4 billion rows in many of your
tables, I hope you have spent a lot of money on a fast disk subsystem anyhow
because you will need it!
----
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)
"clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
news:%2388qeVoOGHA.1832@.TK2MSFTNGP11.phx.gbl...
> If the use of the uniqueidentifier is now preferred, across how many
> relations is it optimal to use as the type for primary keys? Is there some
> point other than performance why one should not worry about reverting to
> the use of bigint for related tables? I've only read a couple of stories
> about it so far. What do you think?
> <%= Clinton Gallagher
>|||Well, good point. I should be comparing an int rather than bigint.
If its true that deleting a record can leave gaps in the sequence of the
key's
value when using an int which can impact sorting the same must be true
when using the uniqueidentifier.
Furthermore, as I understand it even when using newsequentialid( ) there
is no @.@.IDENTITY to get the value of the last inserted record. Do you
know if this is true?
Other than uniqueness, I see no reason to use uniqueidentifier yet..
That's the basis of this inquiry.
<%= Clinton Gallagher
"Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
news:OwfDDvxOGHA.2040@.TK2MSFTNGP14.phx.gbl...
> This is kind of a confusing question, since you really need to give us
> more information. Do you have tables that you need to store > 4 billion
> row? In 2005 there is a way to create an always increasing guid using
> newsequentialid that can help a bit with the problems that using a GUID
> for a key can create, but GUIDs make fine surrogate keys for tables, other
> than performance and typability (the latter of which is just a programmer
> convienience, so should not be really important to the question of whether
> to choose them or not)
> If you need the benefits of a GUID (like the UI can create them and be
> guaranteed uniqueness,) then it might be worth it, otherwise use the
> correct integer type. If you are going to have > 4 billion rows in many
> of your tables, I hope you have spent a lot of money on a fast disk
> subsystem anyhow because you will need it!
> --
> ----
--
> 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)
> "clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
> news:%2388qeVoOGHA.1832@.TK2MSFTNGP11.phx.gbl...
>|||> Furthermore, as I understand it even when using newsequentialid( ) there
> is no @.@.IDENTITY to get the value of the last inserted record. Do you
> know if this is true?
One of the differences between uniqueidentifier and identity is that a
uniqueidentifier value can be assigned by the application instead of SQL
Server. This eliminates the need to retrieve the surrogate key value after
insertion.
Hope this helps.
Dan Guzman
SQL Server MVP
"clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
news:%2313yEZzOGHA.2624@.TK2MSFTNGP12.phx.gbl...
> Well, good point. I should be comparing an int rather than bigint.
> If its true that deleting a record can leave gaps in the sequence of the
> key's
> value when using an int which can impact sorting the same must be true
> when using the uniqueidentifier.
> Furthermore, as I understand it even when using newsequentialid( ) there
> is no @.@.IDENTITY to get the value of the last inserted record. Do you
> know if this is true?
> Other than uniqueness, I see no reason to use uniqueidentifier yet..
> That's the basis of this inquiry.
> <%= Clinton Gallagher
> "Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
> news:OwfDDvxOGHA.2040@.TK2MSFTNGP14.phx.gbl...
>|||That was helpful to be reminded of as the DNF will indeed generate a GUID
consistent with the uniqueidentitifer.
<%= Clinton Gallagher
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:OOChgd0OGHA.2696@.TK2MSFTNGP14.phx.gbl...
> One of the differences between uniqueidentifier and identity is that a
> uniqueidentifier value can be assigned by the application instead of SQL
> Server. This eliminates the need to retrieve the surrogate key value
> after insertion.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "clintonG" < csgallagher@.REMOVETHISTEXTmetromilwaukee
.com> wrote in message
> news:%2313yEZzOGHA.2624@.TK2MSFTNGP12.phx.gbl...
>

Tuesday, March 20, 2012

Bigger sample databases

I like Northwind and Pubs. They're cute.
But, if you're trying to train on issues surrounding performance testing,
having a much larger database would be advantageous.
Is there any resources to get larger sample databases from?
Thanks!http://www.microsoft.com/downloads/.../>
BFB66F0ABDC
For performance testing there is no substitute for using data that matches
or approximates your own production data. Test data generation ought to be
part of your project plan for new projects.
David Portas
SQL Server MVP
--|||David,
Thanks, this is just what I was looking for! Since I'm still working on
an MCDBA cert, I don't really have any "production data" I can use yet. But,
this Adventure Works DB looks like what I needed.
I guess why I need it is that as I train, I want to compare various
options. For instance, which is faster, using subqueries or joins between
tables in T-SQL statements? When you only have 16 records in a table, it's a
little difficult to do "real world analysis" to answer performance questions
like that.
Thanks again!
"David Portas" wrote:

> http://www.microsoft.com/downloads/...
-2BFB66F0ABDC
> For performance testing there is no substitute for using data that matches
> or approximates your own production data. Test data generation ought to be
> part of your project plan for new projects.
> --
> David Portas
> SQL Server MVP
> --
>
>|||Joel wrote:
> I like Northwind and Pubs. They're cute.
> But, if you're trying to train on issues surrounding performance
> testing, having a much larger database would be advantageous.
> Is there any resources to get larger sample databases from?
> Thanks!
BigNW Script attached. Scott's web site is down. See file for comments
related to new database size and file / backup locations.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||I get to this newsgroup by browsing to:
http://msdn.microsoft.com/newsgroup...c6-099a858cd211
...and find this post currently on page 4. I don't see anything for
attachments, just the text you wrote. How do I get the attachment?
Thanks!
"David Gugick" wrote:

> Joel wrote:
> BigNW Script attached. Scott's web site is down. See file for comments
> related to new database size and file / backup locations.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest|||Joel wrote:
> I get to this newsgroup by browsing to:
> http://msdn.microsoft.com/newsgroup...c6-099a858cd211
> ...and find this post currently on page 4. I don't see anything for
> attachments, just the text you wrote. How do I get the attachment?
>
Use a real news reader :-)
I see it from Outlook Express... The ng server name is
msnews.microsoft.com
David Gugick
Quest Software
www.imceda.com
www.quest.com|||David,
Well, our company uses a standard desktop configuration, that doesn't
have Outlook or Outlook Express. There are no Exchange servers, as they use
Lotus Notes / Domino as their e-mail platform (Grrrr...). They seem to have
Internet news groups in Notes blocked as well (Grrrr....).
Is there any other way to get the script you're talking about? A web or
ftp site perhaps?
Thanks again...
"David Gugick" wrote:

> Joel wrote:
> Use a real news reader :-)
> I see it from Outlook Express... The ng server name is
> msnews.microsoft.com
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>|||Joel wrote:
> David,
> Well, our company uses a standard desktop configuration, that
> doesn't have Outlook or Outlook Express. There are no Exchange
> servers, as they use Lotus Notes / Domino as their e-mail platform
> (Grrrr...). They seem to have Internet news groups in Notes blocked
> as well (Grrrr....).
>
Send me an email. Remove the nospam from the email address.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||Joel wrote:
> Is there any other way to get the script you're talking about?
> A web or ftp site perhaps?
Use Google Groups as a newsreader:
http://groups-beta.google.com/group...br />
84054e82
Razvan|||David,
Razvan Socol's post about using the Google news groups helped me. I
was able to get the script from your previous post.
Thanks for your help and your patience!
Joel
David Gugick wrote:
> Joel wrote:
> Send me an email. Remove the nospam from the email address.
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.comsql

Bigger sample databases

I like Northwind and Pubs. They're cute.
But, if you're trying to train on issues surrounding performance testing,
having a much larger database would be advantageous.
Is there any resources to get larger sample databases from?
Thanks!
http://www.microsoft.com/downloads/d...8-2BFB66F0ABDC
For performance testing there is no substitute for using data that matches
or approximates your own production data. Test data generation ought to be
part of your project plan for new projects.
David Portas
SQL Server MVP
|||David,
Thanks, this is just what I was looking for! Since I'm still working on
an MCDBA cert, I don't really have any "production data" I can use yet. But,
this Adventure Works DB looks like what I needed.
I guess why I need it is that as I train, I want to compare various
options. For instance, which is faster, using subqueries or joins between
tables in T-SQL statements? When you only have 16 records in a table, it's a
little difficult to do "real world analysis" to answer performance questions
like that.
Thanks again!
"David Portas" wrote:

> http://www.microsoft.com/downloads/d...8-2BFB66F0ABDC
> For performance testing there is no substitute for using data that matches
> or approximates your own production data. Test data generation ought to be
> part of your project plan for new projects.
> --
> David Portas
> SQL Server MVP
> --
>
>
|||Joel wrote:
> I like Northwind and Pubs. They're cute.
> But, if you're trying to train on issues surrounding performance
> testing, having a much larger database would be advantageous.
> Is there any resources to get larger sample databases from?
> Thanks!
BigNW Script attached. Scott's web site is down. See file for comments
related to new database size and file / backup locations.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||I get to this newsgroup by browsing to:
http://msdn.microsoft.com/newsgroups...6-099a858cd211
...and find this post currently on page 4. I don't see anything for
attachments, just the text you wrote. How do I get the attachment?
Thanks!
"David Gugick" wrote:

> Joel wrote:
> BigNW Script attached. Scott's web site is down. See file for comments
> related to new database size and file / backup locations.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest
|||Joel wrote:
> I get to this newsgroup by browsing to:
> http://msdn.microsoft.com/newsgroups...6-099a858cd211
> ...and find this post currently on page 4. I don't see anything for
> attachments, just the text you wrote. How do I get the attachment?
>
Use a real news reader :-)
I see it from Outlook Express... The ng server name is
msnews.microsoft.com
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||David,
Well, our company uses a standard desktop configuration, that doesn't
have Outlook or Outlook Express. There are no Exchange servers, as they use
Lotus Notes / Domino as their e-mail platform (Grrrr...). They seem to have
Internet news groups in Notes blocked as well (Grrrr....).
Is there any other way to get the script you're talking about? A web or
ftp site perhaps?
Thanks again...
"David Gugick" wrote:

> Joel wrote:
> Use a real news reader :-)
> I see it from Outlook Express... The ng server name is
> msnews.microsoft.com
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>
|||Joel wrote:
> David,
> Well, our company uses a standard desktop configuration, that
> doesn't have Outlook or Outlook Express. There are no Exchange
> servers, as they use Lotus Notes / Domino as their e-mail platform
> (Grrrr...). They seem to have Internet news groups in Notes blocked
> as well (Grrrr....).
>
Send me an email. Remove the nospam from the email address.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||Joel wrote:
> Is there any other way to get the script you're talking about?
> A web or ftp site perhaps?
Use Google Groups as a newsreader:
http://groups-beta.google.com/group/...be2b7e84054e82
Razvan
|||David,
Razvan Socol's post about using the Google news groups helped me. I
was able to get the script from your previous post.
Thanks for your help and your patience!
Joel
David Gugick wrote:
> Joel wrote:
> Send me an email. Remove the nospam from the email address.
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com

Bigger sample databases

I like Northwind and Pubs. They're cute.
But, if you're trying to train on issues surrounding performance testing,
having a much larger database would be advantageous.
Is there any resources to get larger sample databases from?
Thanks!http://www.microsoft.com/downloads/details.aspx?familyid=487C9C23-2356-436E-94A8-2BFB66F0ABDC
For performance testing there is no substitute for using data that matches
or approximates your own production data. Test data generation ought to be
part of your project plan for new projects.
--
David Portas
SQL Server MVP
--|||David,
Thanks, this is just what I was looking for! Since I'm still working on
an MCDBA cert, I don't really have any "production data" I can use yet. But,
this Adventure Works DB looks like what I needed.
I guess why I need it is that as I train, I want to compare various
options. For instance, which is faster, using subqueries or joins between
tables in T-SQL statements? When you only have 16 records in a table, it's a
little difficult to do "real world analysis" to answer performance questions
like that.
Thanks again!
"David Portas" wrote:
> http://www.microsoft.com/downloads/details.aspx?familyid=487C9C23-2356-436E-94A8-2BFB66F0ABDC
> For performance testing there is no substitute for using data that matches
> or approximates your own production data. Test data generation ought to be
> part of your project plan for new projects.
> --
> David Portas
> SQL Server MVP
> --
>
>|||This is a multi-part message in MIME format.
--=_NextPart_000_01FD_01C58875.18FCF7B0
Content-Type: text/plain;
format=flowed;
charset="Utf-8";
reply-type=original
Content-Transfer-Encoding: 7bit
Joel wrote:
> I like Northwind and Pubs. They're cute.
> But, if you're trying to train on issues surrounding performance
> testing, having a much larger database would be advantageous.
> Is there any resources to get larger sample databases from?
> Thanks!
BigNW Script attached. Scott's web site is down. See file for comments
related to new database size and file / backup locations.
David Gugick
Quest Software
www.imceda.com
www.quest.com
--=_NextPart_000_01FD_01C58875.18FCF7B0
Content-Type: text/plain;
format=flowed;
name="Create BigNW Script.sql";
reply-type=original
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Create BigNW Script.sql"
set quoted_identifier off
go
--begin pgp signed message--
/*
*************************************************************************=******
* l i c e n s e *
*************************************************************************=******
(c) copyright 1998-2000, scott mauvais
the software is provided "as-is" and without warranty of any kind, =expressed,
implied or otherwise, including and without limitation, any warranty of
merchantability or fitness for a particular purpose. in no event shall =the
author be liable for any special, incidental, indirect or consequential
damages whatsoever (including, without limitation, damages for loss of
profits,business interruption, loss of information, or any other loss),
whether or not advised of the possibility of damage, and on any theory =of
liability, arisingout of or in connection with the use or inability to =use
this software.
this is an unsupported script. that said, i appreciate hearing about =bugs so i
can address them in future releases. if you have questions or wish to =report a
bug, please send e-mail to sm@.mauvais.com with the word bignw in the
subject. while i can't respond to all messages i will do my best to help =out.
updates, if any, will be posted to =http://www.mauvais.com/downloads/bignw.htm
*************************************************************************=******
* r e l e a s e h i s t o r y *
*************************************************************************=******
0.80 11/14/1999 scott mauvais created.
0.90 02/22/1999 scott mauvais o use temp tables
o add Orders and [Order Details] tables
1.00 03/15/1999 scott mauvais o drop indices/contraints
o store variables in temp table
o configure growth factor
o update db options
2.00 01/23/2000 scott mauvais o clean up formatting and add comments =for
o parallel query article for ziff =davis.
2.10 02/24/2000 scott mauvais o dump/load Northwind rather than =require dts
o test for temp tables before drop
o allow change of source db
o add more robust comments for bignw =article
for ziff davis
*************************************************************************=******
* n o t e s *
*************************************************************************=******
purpose: creates a large copy of the Northwind database for =testing.
input params: none
output params: none
returns: none
usage: execute in isql
called by: interactive user
calls: none
ddl/dml: several. creates new database
local vars: @.sdbname
@.ssourcedb
@.sbackupname
@.sdatapath
@.slogpath
@.sbackuppath
@.sdbsize
@.ssql
@.lhowbig
files created: bignw.mdf in path specified by @.sdatapath
bignw_log.ldf in path specified by @.sdatapath
[backup file] in path specified by @.sbackuppath
files deleted: all files listed in files created
*************************************************************************=******
* c o n f i g u r a t i o n *
*************************************************************************=******
search for "todo:" (no quotes) for areas you need to change to match =your
system. below is a quick overview.
first, you must have the Northwind sample database installed. if you do =not
it installed on your system you can create by running the instnwnd.sql =script
located in the mssql7\install directory.
i called my copy bignw. if you used a different name you will need to =change
the change the name in two places (lines 79 and 276). they are both =marked
with todo:
finally, you need to specify how large you want to make the new =database. you
do this by chaning the @.lhowbig variable (around line 155) which is
marked with a todo: by default, this script increases the customer, =Orders,
and Order Details tables by a factor of 100 and will require around 60 m
if you received or downloaded this from an untrusted source, please =verify
the pgp signature. my finger print is
80a6 3e8b 7a39 4264 e576 2ce5 85e5 7ea2
*************************************************************************=******
*/
set nocount on
declare @.sdbname sysname
declare @.ssourcedb sysname
declare @.sbackupname sysname
declare @.sdatapath varchar(255)
declare @.slogpath varchar(255)
declare @.sbackuppath varchar(255)
declare @.sdbsize varchar(8)
declare @.ssql varchar(2047)
declare @.lhowbig int
-- todo: change these variables
select @.sdbname =3D 'bignw' -- change this to the =name of
-- of the database you =want to
-- create. if you change =this
-- the default 'bignw' =you will
-- also have to change =line 276
select @.lhowbig =3D 100 -- change this to your =desired
-- growth factor. a =factor of 100
-- requires =approximatelym 60 m.
select @.ssourcedb =3D 'Northwind' -- name of source =database.
-- this must have the =same
-- structure of the =standard
-- 'Northwind' database.
select @.sbackupname =3D 'Northwindtobignw' -- *** do not ** use the =name
-- of an existing backup =device
-- because the script =will drop
-- it!
-- name of backup device =the
-- script will drop and =recreate
-- to store its backup =of
-- Northwind.
select @.sdatapath =3D 'c:\program files\microsoft sql =server\mssql$sp2_650Patch\data\' -- 'c:\mssql7\data\' -- path where you =want to
-- place the data file =for
-- bignw
select @.slogpath =3D 'c:\program files\microsoft sql =server\mssql$sp2_650Patch\data\' -- 'c:\mssql7\data\' -- path where you =want to
-- place the log for =bignw
select @.sbackuppath =3D 'c:\program files\microsoft sql =server\mssql$sp2_650Patch\backup\' -- 'c:\mssql7\backup\' -- path your =backup location.
-- the script makes a =copy of
-- Northwind and will =place it
-- here.
select @.sdbsize =3D '60' -- size in mb to use =when
-- the new database.
/*
/////////////////////////////////////////////////////////////////////////=//////
make sure temp tables deleted
/////////////////////////////////////////////////////////////////////////=//////
*/
if object_id('tempdb..#bignw_vars') is not null
drop table #bignw_vars
if object_id('tempdb..#bignw_orddetorig') is not null
drop table #bignw_orddetorig
if object_id('tempdb..#bignw_orddet') is not null
drop table #bignw_orddet
if object_id('tempdb..#bignw_ord') is not null
drop table #bignw_ord
if object_id('tempdb..#bignw_cust') is not null
drop table #bignw_cust
-- save db name and how big so we can use it later
create table #bignw_vars (dbname sysname, howbig int)
insert into #bignw_vars (dbname, howbig) values (@.sdbname, @.lhowbig)
/*
/////////////////////////////////////////////////////////////////////////=//////
create database
/////////////////////////////////////////////////////////////////////////=//////
*/
-- drop the database if it already exists
-- notice that i am dynmaically building the sql statement and use exec =to
-- avoid an 226
use tempdb
select @.ssql =3D "if exists (select * from master..sysdatabases
where name =3D '" + @.sdbname + "' )
exec (""drop database " + @.sdbname + """) "
exec (@.ssql )
-- start off with just 3mb because that is all that Northwind uses and =the
-- load will make the new database the same size as the old one. we =will
-- expand it later.
select @.ssql =3D "
create database " + @.sdbname + "
on (
name =3D 'bignw_data',
filename =3D '" + @.sdatapath + @.sdbname + "_data.mdf',
size =3D 3mb
)
log on (
name =3D 'bignw_log',
filename =3D '" + @.slogpath + @.sdbname + "_log.ldf',
size =3D 5mb
)"
exec (@.ssql)
-- drop dump device if it exists
select @.ssql =3D "if exists (select * from master.dbo.sysdevices
where name =3D '" + @.sbackupname + "'
and status =3D 16)
exec (""sp_dropdevice '" + @.sbackupname + "'"")"
exec (@.ssql)
-- add dump device
select @.ssql =3D "sp_addumpdevice 'disk', '" + @.sbackupname + "',
'" + @.sbackuppath + @.sbackupname + =".bak'"
exec (@.ssql)
-- dump Northwind to new device
select @.ssql =3D "dump database " + @.ssourcedb + " to " + @.sbackupname + =" with init"
exec (@.ssql)
-- restore the original Northwind
select @.ssql =3D
"load database " + @.sdbname + " from disk =3D
'" + @.sbackuppath + @.sbackupname + ".bak' with replace,
move '" + @.ssourcedb + "_log' to '" + @.sdatapath + =@.sdbname + "_log.ldf',
move '" + @.ssourcedb + "' to '" + @.sdatapath + =@.sdbname + ".mdf'"
exec (@.ssql)
-- set the db options to maximize performance as we insert lots of data
select @.ssql =3D 'sp_dboption "' + @.sdbname + '",
"auto update statistics", "false" '
exec (@.ssql)
select @.ssql =3D 'sp_dboption "' + @.sdbname + '",
"select into/bulkcopy", "false" '
exec (@.ssql)
select @.ssql =3D 'sp_dboption "' + @.sdbname + '",
"trunc. log on chkpt", ="false" '
exec (@.ssql)
-- alter database to increase to desired size.
-- notice that the file name is back to Northwind because of the =restore.
select @.ssql =3D "alter database " + @.sdbname + " modify file
(name =3D " + @.ssourcedb + ", size =3D " + =@.sdbsize + ")"
exec (@.ssql)
go
/*
/////////////////////////////////////////////////////////////////////////=//////
make bignw the current db
/////////////////////////////////////////////////////////////////////////=//////
*/
-- todo:
-- if you changed default the name of the database this script creates =you
-- must update the line to use that database. make sure the name here =matches
-- the on on line 79
use bignw
/*
/////////////////////////////////////////////////////////////////////////=//////
drop indices and constraints
/////////////////////////////////////////////////////////////////////////=//////
*/
-- Order Details
drop index [Order Details].OrderID
drop index [Order Details].OrdersOrder_Details
drop index [Order Details].ProductID
drop index [Order Details].ProductsOrder_Details
alter table [Order Details] drop constraint PK_Order_Details
alter table [Order Details] drop constraint FK_Order_Details_Orders
alter table [Order Details] drop constraint FK_Order_Details_Products
-- Orders
drop index Orders.CustomerID
drop index Orders.CustomersOrders
drop index Orders.EmployeeID
drop index Orders.EmployeesOrders
drop index Orders.OrderDate
drop index Orders.ShippedDate
drop index Orders.ShippersOrders
drop index Orders.ShipPostalCode
alter table Orders drop constraint PK_Orders
alter table Orders drop constraint FK_Orders_Customers
alter table Orders drop constraint FK_Orders_Employees
alter table Orders drop constraint FK_Orders_Shippers
--custmercustomerdemo
alter table CustomerCustomerDemo
drop constraint FK_CustomerCustomerDemo_Customers
alter table CustomerCustomerDemo
drop constraint PK_CustomerCustomerDemo
-- Customers
alter table Customers drop constraint PK_Customers
drop index Customers.City
drop index Customers.CompanyName
drop index Customers.PostalCode
drop index Customers.Region
/*
/////////////////////////////////////////////////////////////////////////=//////
alter tables
/////////////////////////////////////////////////////////////////////////=//////
*/
-- Customers
if exists (select * from syscolumns w
where name =3D 'cycle' and id =3D =object_id('Customers'))
alter table Customers drop column cycle
alter table Customers add cycle int
alter table Customers alter column CustomerID varchar(11) not null
--CustomerCustomerDemo
alter table CustomerCustomerDemo alter column CustomerID varchar(11) =not null
-- Orders
if exists (select * from syscolumns
where name =3D 'cycle' and id =3D =object_id('Orders'))
alter table Orders drop column cycle
alter table Orders add cycle int
alter table Orders alter column CustomerID varchar(11) not null
-- Order Details
if exists (select * from syscolumns
where name =3D 'cycle' and id =3D object_id('Order =Details'))
alter table [Order Details] drop column cycle
alter table [Order Details] add cycle int
go
/*
/////////////////////////////////////////////////////////////////////////=//////
increase size of tables
/////////////////////////////////////////////////////////////////////////=//////
*/
declare @.i int
declare @.lhowbig int
select @.lhowbig =3D howbig from #bignw_vars
-- start counter off at zero
select @.i =3D 0
delete from Customers where cycle is not null
select * into #bignw_cust from Customers
update #bignw_cust set cycle =3D @.i
while @.i < @.lhowbig
begin
select @.i =3D @.i + 1
update #bignw_cust set CustomerID =3D left(CustomerID, 5)
+ cast(@.i as varchar(5)), cycle ==3D @.i
insert Customers select * from #bignw_cust
print 'customer passes complete: ' + cast(@.i as varchar(5))
end
-- Orders
select @.i =3D 0
delete from Orders where cycle is not null
select CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, =ShipVia,
Freight, ShipName, ShipAddress, ShipCity, ShipRegion, =ShipPostalCode,
ShipCountry, cycle
into #bignw_ord from Orders
update #bignw_ord set cycle =3D @.i
while @.i < @.lhowbig
begin
select @.i =3D @.i + 1
update #bignw_ord set CustomerID =3D left(CustomerID, 5)
+ cast(@.i as varchar(5)), cycle ==3D @.i
insert Orders select * from #bignw_ord
print 'Orders passes complete: ' + cast(@.i as varchar(5))
end
-- Order Details
select @.i =3D 0
delete from [Order Details] where cycle is not null
-- make two copies of Order Details
-- one, orddet, that we will update and insert back into
-- the original table. we will use the other, orddetorig,
-- to refresh orddet after each cycle
select * into #bignw_orddet from [Order Details]
select * into #bignw_orddetorig from [Order Details]
update #bignw_orddet set cycle =3D @.i
while @.i < @.lhowbig
begin
select @.i =3D @.i + 1
-- refresh orddet temp table with original [Order Details]
-- table. we need to do this because we need the original values in
-- the OrderID column
truncate table #bignw_orddet
insert into #bignw_orddet select * from #bignw_orddetorig where =cycle is null
-- 830 Orders
update #bignw_orddet set OrderID =3D (OrderID + (830 * @.i)), cycle ==3D @.i
insert [Order Details] select * from #bignw_orddet
print 'Order Details passes complete: ' + cast(@.i as varchar(5))
-- if you are short on disk space, you can issue a
-- checkpoint here to truncate the log
--checkpoint
end
/*
/////////////////////////////////////////////////////////////////////////=//////
re-create indices and contraints
/////////////////////////////////////////////////////////////////////////=//////
*/
-- customer
alter table Customers with check add constraint PK_Customers
primary key clustered (CustomerID) on [default]
create index City on Customers (City) on [default]
create index CompanyName on Customers (CompanyName) on [default]
create index PostalCode on Customers (PostalCode) on [default]
create index Region on Customers (Region) on [default]
-- Orders
alter table Orders with check add constraint PK_Orders
primary key clustered (OrderID) on =[default]
create index CustomerID on Orders (CustomerID) on =[default]
create index CustomersOrders on Orders (CustomerID) on =[default]
create index EmployeeID on Orders (EmployeeID) on =[default]
create index EmployeesOrders on Orders (EmployeeID) on =[default]
create index OrderDate on Orders (OrderDate) on =[default]
create index ShippedDate on Orders (ShippedDate) on =[default]
create index ShippersOrders on Orders (ShipVia) on =[default]
create index ShipPostalCode on Orders (ShipPostalCode) on =[default]
alter table Orders with check add constraint FK_Orders_Customers
foreign key (CustomerID) references Customers (CustomerID)
alter table Orders with check add constraint FK_Orders_Employees
foreign key (EmployeeID) references Employees (EmployeeID)
alter table Orders with check add constraint FK_Orders_Shippers
foreign key (ShipVia) references Shippers (ShipperID)
-- Order Details
alter table [Order Details] with check add constraint PK_Order_Details
primary key clustered (OrderID, =ProductID)
on [default]
create index OrderID on [Order Details] (OrderID) on =[default]
create index OrdersOrder_Details on [Order Details] (OrderID) on =[default]
create index ProductID on [Order Details] (ProductID) on =[default]
create index ProductsOrder_Details on [Order Details] (ProductID) on =[default]
alter table [Order Details] with check add constraint =FK_Order_Details_Orders
foreign key (OrderID) references Orders (OrderID)
alter table [Order Details] with check add constraint =FK_Order_Details_Products
foreign key (ProductID) references Products (ProductID)
-- CustomerCustomerDemo
alter table CustomerCustomerDemo with check add constraint =PK_CustomerCustomerDemo
primary key nonclustered (CustomerID, CustomerTypeID) on =[default]
alter table CustomerCustomerDemo add constraint =FK_CustomerCustomerDemo_Customers
foreign key (CustomerID) references Customers (CustomerID)
/*
/////////////////////////////////////////////////////////////////////////=//////
reset db options and clean up
/////////////////////////////////////////////////////////////////////////=//////
*/
declare @.sdbname sysname
declare @.ssql varchar(255)
-- retrieve database name from temp table
select @.sdbname =3D dbname from #bignw_vars
select @.ssql =3D 'sp_dboption "'+ @.sdbname + '", "auto update =statistics", "true" '
exec (@.ssql)
select @.ssql =3D 'sp_dboption "'+ @.sdbname + '", "select =into/bulkcopy", "true" '
exec (@.ssql)
select @.ssql =3D 'sp_dboption "'+ @.sdbname + '", "trunc. log on chkpt", = "true" '
exec (@.ssql)
exec ('sp_updatestats')
-- drop temp tables
if object_id('tempdb..#bignw_vars') is not null
drop table #bignw_vars
if object_id('tempdb..#bignw_orddetorig') is not null
drop table #bignw_orddetorig
if object_id('tempdb..#bignw_orddet') is not null
drop table #bignw_orddet
if object_id('tempdb..#bignw_ord') is not null
drop table #bignw_ord
if object_id('tempdb..#bignw_cust') is not null
drop table #bignw_cust
-- return a to a "safe" location
use tempdb
--begin pgp signature--
/*
iqcvawubolbdevzh9pyexhmzaqgscwp9fonrtcqzpcjitqgsolhrmzm6gyfen8hp
s3xbqybxn4yybe7djecestq7tyxagle3m7whjmkg3oxino8iqm77ngmgun2h26q1
mpn1spcnps1sptblzwhneitf7wu5slyev/dfj2npghxfegfxx5wmdnssujrgxmei
lel9dwlyoam=3D
=3Doss8
*/
--end pgp signature--
--=_NextPart_000_01FD_01C58875.18FCF7B0--|||I get to this newsgroup by browsing to:
http://msdn.microsoft.com/newsgroups/default.aspx?pg=4&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.sqlserver.server&fltr=&mid=336fd7f5-5023-4c73-b24e-2e34cd6ed6f7&tid=974e2c9a-2bc0-4dcc-b6c6-099a858cd211
...and find this post currently on page 4. I don't see anything for
attachments, just the text you wrote. How do I get the attachment?
Thanks!
"David Gugick" wrote:
> Joel wrote:
> > I like Northwind and Pubs. They're cute.
> >
> > But, if you're trying to train on issues surrounding performance
> > testing, having a much larger database would be advantageous.
> >
> > Is there any resources to get larger sample databases from?
> >
> > Thanks!
> BigNW Script attached. Scott's web site is down. See file for comments
> related to new database size and file / backup locations.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest|||Joel wrote:
> I get to this newsgroup by browsing to:
> http://msdn.microsoft.com/newsgroups/default.aspx?pg=4&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.sqlserver.server&fltr=&mid=336fd7f5-5023-4c73-b24e-2e34cd6ed6f7&tid=974e2c9a-2bc0-4dcc-b6c6-099a858cd211
> ...and find this post currently on page 4. I don't see anything for
> attachments, just the text you wrote. How do I get the attachment?
>
Use a real news reader :-)
I see it from Outlook Express... The ng server name is
msnews.microsoft.com
--
David Gugick
Quest Software
www.imceda.com
www.quest.com|||David,
Well, our company uses a standard desktop configuration, that doesn't
have Outlook or Outlook Express. There are no Exchange servers, as they use
Lotus Notes / Domino as their e-mail platform (Grrrr...). They seem to have
Internet news groups in Notes blocked as well (Grrrr....).
Is there any other way to get the script you're talking about? A web or
ftp site perhaps?
Thanks again...
"David Gugick" wrote:
> Joel wrote:
> > I get to this newsgroup by browsing to:
> >
> > http://msdn.microsoft.com/newsgroups/default.aspx?pg=4&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.sqlserver.server&fltr=&mid=336fd7f5-5023-4c73-b24e-2e34cd6ed6f7&tid=974e2c9a-2bc0-4dcc-b6c6-099a858cd211
> >
> > ...and find this post currently on page 4. I don't see anything for
> > attachments, just the text you wrote. How do I get the attachment?
> >
> Use a real news reader :-)
> I see it from Outlook Express... The ng server name is
> msnews.microsoft.com
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>|||Joel wrote:
> David,
> Well, our company uses a standard desktop configuration, that
> doesn't have Outlook or Outlook Express. There are no Exchange
> servers, as they use Lotus Notes / Domino as their e-mail platform
> (Grrrr...). They seem to have Internet news groups in Notes blocked
> as well (Grrrr....).
>
Send me an email. Remove the nospam from the email address.
--
David Gugick
Quest Software
www.imceda.com
www.quest.com|||Joel wrote:
> Is there any other way to get the script you're talking about?
> A web or ftp site perhaps?
Use Google Groups as a newsreader:
http://groups-beta.google.com/group/microsoft.public.sqlserver.server/msg/7cbe2b7e84054e82
Razvan|||David,
Razvan Socol's post about using the Google news groups helped me. I
was able to get the script from your previous post.
Thanks for your help and your patience!
Joel
David Gugick wrote:
> Joel wrote:
> > David,
> > Well, our company uses a standard desktop configuration, that
> > doesn't have Outlook or Outlook Express. There are no Exchange
> > servers, as they use Lotus Notes / Domino as their e-mail platform
> > (Grrrr...). They seem to have Internet news groups in Notes blocked
> > as well (Grrrr....).
> >
> Send me an email. Remove the nospam from the email address.
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com

Big performance problem with reports

Hello everyone!
I have major performance problems with reports that I have deployed in
Reporting Services.
I have an Sql database with millions of rows, and I have created a cube in
Analysis Services that is run against a view in the database.
My reports get data from the cube and the dataset is created with Sql syntax.
I need to filter the report and needed to create parameters, but only
prameters that give the option of choosing "all", i.e. being optional
parameters. The only way I can do that, as far as I know, is by creating the
filter parameter datasets in Sql Syntax. That is to be able to use union as
in
"select 'All'
union
select the real dataset
group by value" syntax. And it seems that I can't use union when running the
sql statement on a cube, so I have to run the statement on the original
database view.
Now the problem I have is that it takes about half an hour or more to view
the report, after choosing values in some filter parameters!
As far as I can see, the group by, is the statement that takes such a long
time. But that can't be the only problem.
So... does anyone know what I can do to reduce the time it takes to process
a report and what performance enhancements I can do?
I also have a problem with a specific report that gets a
System.OutOfMemoryException when I try to view it in the preview pane. But
when I run the dataset generating the report data, there are no problems.
Does anybody know what the problem might be?
I'm in a tight place and would appreciate any fast responses.
Thanks a lot,
TaraDo you have a stored procedure or is the sql code inside the RDL?
If you put as much as possible on the SQL Server, you can run it
through Query Analyzer and look at query plans etc. It does sound like
you are passing a lot more data around than you need, so get all the
SQL code out of the RDL and see where that gets you.

Sunday, March 11, 2012

BI Studio: Poor Performance When Opening a Solution

When I am opening a Business Intelligence Solution it takes up to 6 minutes
until the system is ready to work.
The first 4 minutes I see Visual Studio with the grey background. In the
remaining time the packages appear but don't accept any input. Meanwhile
Visual Studio is reporting that it is busy and is waiting for an internal
operation to complete.
Any idea how to speed up this process?
Stefan Bublitz
does your cube metadata is big?
My metadata takes 10Mb and required few minutes to be opened.
"SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
news:095B0A32-78DE-418B-854B-243798CAF2C0@.microsoft.com...
> When I am opening a Business Intelligence Solution it takes up to 6
> minutes
> until the system is ready to work.
> The first 4 minutes I see Visual Studio with the grey background. In the
> remaining time the packages appear but don't accept any input. Meanwhile
> Visual Studio is reporting that it is busy and is waiting for an internal
> operation to complete.
> Any idea how to speed up this process?
> Stefan Bublitz
|||I browsed the newsgroups in the meantime and I found a hint that I tried out:
I uninstalled the SSIS SP1 and I re-installed SSIS without SP1.
I don't know if this has been the cause of the problem but obviously it
solved it...
(I found entries in the event log regarding DCOM and MsDtsServer).
Stefan Bublitz
"Jeje" wrote:

> does your cube metadata is big?
> My metadata takes 10Mb and required few minutes to be opened.
> "SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
> news:095B0A32-78DE-418B-854B-243798CAF2C0@.microsoft.com...
>
|||oh you talk about an SSIS solution not an SSAS one.
Sorry for this mistake.
and what about the SP2?
with SSIS I suffer slow opening only if my solution was closed and if my
some packages are opened. When I reopen the solution, this reopen all these
packages and takes few times because SSIS validate each package.
You can improve this by changing the validate metadata option of your
connection to false (true by default until SP2, but after a package is
created you have to change this your self)
You can also check the "work offline" option before opening your big
solution.
"SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
news:3A16F4D2-5655-43DD-ACD7-1035EFBBA835@.microsoft.com...[vbcol=seagreen]
>I browsed the newsgroups in the meantime and I found a hint that I tried
>out:
> I uninstalled the SSIS SP1 and I re-installed SSIS without SP1.
> I don't know if this has been the cause of the problem but obviously it
> solved it...
> (I found entries in the event log regarding DCOM and MsDtsServer).
> --
> Stefan Bublitz
>
> "Jeje" wrote:

BI Studio: Poor Performance When Opening a Solution

When I am opening a Business Intelligence Solution it takes up to 6 minutes
until the system is ready to work.
The first 4 minutes I see Visual Studio with the grey background. In the
remaining time the packages appear but don't accept any input. Meanwhile
Visual Studio is reporting that it is busy and is waiting for an internal
operation to complete.
Any idea how to speed up this process?
Stefan Bublitzdoes your cube metadata is big?
My metadata takes 10Mb and required few minutes to be opened.
"SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
news:095B0A32-78DE-418B-854B-243798CAF2C0@.microsoft.com...
> When I am opening a Business Intelligence Solution it takes up to 6
> minutes
> until the system is ready to work.
> The first 4 minutes I see Visual Studio with the grey background. In the
> remaining time the packages appear but don't accept any input. Meanwhile
> Visual Studio is reporting that it is busy and is waiting for an internal
> operation to complete.
> Any idea how to speed up this process?
> Stefan Bublitz|||I browsed the newsgroups in the meantime and I found a hint that I tried out
:
I uninstalled the SSIS SP1 and I re-installed SSIS without SP1.
I don't know if this has been the cause of the problem but obviously it
solved it...
(I found entries in the event log regarding DCOM and MsDtsServer).
Stefan Bublitz
"Jeje" wrote:

> does your cube metadata is big?
> My metadata takes 10Mb and required few minutes to be opened.
> "SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
> news:095B0A32-78DE-418B-854B-243798CAF2C0@.microsoft.com...
>|||oh you talk about an SSIS solution not an SSAS one.
Sorry for this mistake.
and what about the SP2?
with SSIS I suffer slow opening only if my solution was closed and if my
some packages are opened. When I reopen the solution, this reopen all these
packages and takes few times because SSIS validate each package.
You can improve this by changing the validate metadata option of your
connection to false (true by default until SP2, but after a package is
created you have to change this your self)
You can also check the "work offline" option before opening your big
solution.
"SBublitz" <SBublitz@.discussions.microsoft.com> wrote in message
news:3A16F4D2-5655-43DD-ACD7-1035EFBBA835@.microsoft.com...[vbcol=seagreen]
>I browsed the newsgroups in the meantime and I found a hint that I tried
>out:
> I uninstalled the SSIS SP1 and I re-installed SSIS without SP1.
> I don't know if this has been the cause of the problem but obviously it
> solved it...
> (I found entries in the event log regarding DCOM and MsDtsServer).
> --
> Stefan Bublitz
>
> "Jeje" wrote:
>

Saturday, February 25, 2012

Better performance without an index?

I have a small table (600 rows) that is used in a query with a relatively large table (200,000 rows). Strangely, I get the best performance from the query by removing all indexes from the small table (including the primary key). This seems a little odd to me, and I'm wondering if this is a common scenario, and if there is some general rule that can be applied when indexing small tables.

I have tried changing the primary key index (clustered vs nonclustered) and adding other indexes to both tables, but I always get the best performance by removing all indexes from the small table. The performance difference is significant, execution time goes from 2 seconds to just over 1 second, and this is a query that gets executed quite a bit.

I can't delete the PK index as the table needs a PK for data integrity reasons. So I'm not sure how to achieve the non-index performance without removing the index.

Any suggestions would be much appreciated. By the way it's SQL Server 2005 Express.

Without indexes, you will always do a table scan. However, with such a small table, a table scan is probably much better than hopping through the index tree to get data. Though, I do not see how a clustered index would be a bad thing here. Can you show us some code (ddl for both table, including all keys/constraints)?

|||

The small table:

create table EmployeeOffice (

EmployeeID uniqueidentifier not null,

OfficeID uniqueidentifier not null,

Sequence smallint not null,

CanAccessAllCases bit default 0 not null,

IsManager bit default 0 not null)

go

alter table EmployeeOffice

add constraint EmployeeOffice_PK primary key nonclustered (EmployeeID, OfficeID)

The large table:

create table CaseInfo (

CaseNumber int not null,

OfficeID uniqueidentifier not null,

EmployeeID uniqueidentifier null,

TeamID uniqueidentifier null,

... - there's about another 20 columns

InvoiceRequired" bit default 0 not null,

LastChanged" timestamp not null)

go

alter table CaseInfo

add constraint CaseInfo_PK primary key clustered (CaseNumber)

There's an Employee and an Office table as well with RI contraints between the four tables but they are not used in this particular query. The query is fairly large and involves other tables but this particular behaviour is specific to these two tables.

The query (simplified):

SELECT CaseNumber, InvoiceRequired,...

FROM CaseInfo

WHERE EmployeeID = 'BCA6F76E-A2EF-4FDA-AB38-061047ADBFDE'

or OfficeID in (Select OfficeID From EmployeeOffice Where EmployeeID = 'BCA6F76E-A2EF-4FDA-AB38-061047ADBFDE'

and (CanAccessAllCases=1 or IsManager=1))

In the test database ALL the records in the CaseInfo table have the same office, and the sub query returns no rows. The execution plan shows that when the index exists, it creates an "Index Spool" with 131,992 rows (which is the number of rows in CaseInfo where EmployeeID does not match. If I use a table hint to ignore the index on this table (or delete it) the "Index Spool" is not created.

|||

A few things:

1. I would rewrite the query to use join instead of subquery.

e.g.

Code Snippet

SELECT CaseNumber, InvoiceRequired

FROM CaseInfo ci JOIN EmployeeOffice eo ON ci.EmployeeID=eo.EmployeeID

WHERE ci.EmployeeID = 'BCA6F76E-A2EF-4FDA-AB38-061047ADBFDE'

union all

SELECT CaseNumber, InvoiceRequired

FROM CaseInfo ci JOIN EmployeeOffice eo ON ci.OfficeID=eo.OfficeID

WHERE eo.EmployeeID = 'BCA6F76E-A2EF-4FDA-AB38-061047ADBFDE'

and (eo.CanAccessAllCases|eo.IsManager=1)

2. Create an index on CaseInfo(EmployeeID,OfficeID)

3. Index spool is used to cache the data to allow faster lookup. This is not neccessarily a bad thing.

Thursday, February 16, 2012

Best way to Learn T-SQL Performance Tuning

Hi,
I want to learn how to get the most performance out of T-SQL code.
essentially I want to learn to be able to rewrite T-SQL code to get better
performance out of stored procedures. What would you recommend is the best
AND fastest way to learn that? I am more interested in leaning performance
tuning of the code rather than SQL server itself.
Any recommendations on the site, books, software, etc would be good.
Thank you.
http://www.sql-server-performance.com/transact_sql.asp
Regards,
Jamie
"Dragon" wrote:

> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>
>
|||The problem you face in learning tuning of the code, rather than of
SQL Server, is that the biggest part of tuning is in the database
design and the indexing. The optimizer often turns many different
coding approaches into the same thing internally. What remaind for
tuning the code means understanding the optimizer. That is a bit of a
moving target as each new release and even service pack changes the
rules to some degree.
Roy Harvey
Beacon Falls, CT
On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
<noSpam_baadil@.hotmail.com> wrote:

>Hi,
>I want to learn how to get the most performance out of T-SQL code.
>essentially I want to learn to be able to rewrite T-SQL code to get better
>performance out of stored procedures. What would you recommend is the best
>AND fastest way to learn that? I am more interested in leaning performance
>tuning of the code rather than SQL server itself.
>Any recommendations on the site, books, software, etc would be good.
>Thank you.
>
|||Thank you Roy.
the main reason I want to lean code optimization is because we are facing a
lot of slow code. for example, we recently encounter a stored procedure that
processed a particular function in over 60 hours. When it was rewritten with
some additional indexes and temp tables, total time came down to 30 minutes.
I want to learn this so that I can help in future occurrences of the same.
Thanks.
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:7i14c35a2f46914f27j6gft8fh170k82cl@.4ax.com... [vbcol=seagreen]
> The problem you face in learning tuning of the code, rather than of
> SQL Server, is that the biggest part of tuning is in the database
> design and the indexing. The optimizer often turns many different
> coding approaches into the same thing internally. What remaind for
> tuning the code means understanding the optimizer. That is a bit of a
> moving target as each new release and even service pack changes the
> rules to some degree.
> Roy Harvey
> Beacon Falls, CT
> On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
> <noSpam_baadil@.hotmail.com> wrote:
|||On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
I would recommend "Inside SQL Server 2005" book series. These books
come from authors with well established reputations and the books are
great. You do not want to waste your time reading less than perfect
and/or incorrect stuff that is is published on some web sites.
Alex Kuznetsov, SQL Server MVP
http://sqlserver-tips.blogspot.com/
|||On Aug 14, 4:04 pm, Alex Kuznetsov <AK_TIREDOFS...@.hotmail.COM> wrote:
> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
>
>
> I would recommend "Inside SQL Server 2005" book series. These books
> come from authors with well established reputations and the books are
> great. You do not want to waste your time reading less than perfect
> and/or incorrect stuff that is is published on some web sites.
> Alex Kuznetsov, SQL Server MVPhttp://sqlserver-tips.blogspot.com/
Learn how to understand and read the Execution Plan for your SQL,
that's a great place to start.
Good Luck,
Mark
|||Thank you. That link did not work but I have been to that site before. It is
an excellent site with tons of usefull information. I think the only problem
is that it is more geared towards someone who is either looking for
particular information or is already an expert and needs confirmation. I am
not sure if it is good for a start-to-finish learning method. I could be
wrong.
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:A60F1359-98FB-41F2-9578-CA86E5A165DF@.microsoft.com...[vbcol=seagreen]
> http://www.sql-server-performance.com/transact_sql.asp
>
> --
> Regards,
> Jamie
>
> "Dragon" wrote:
|||Thank you Mark. Any recommendation on a good source for leanring about
Execution Plans?
<mygolf51@.gmail.com> wrote in message
news:1187122016.610745.92110@.22g2000hsm.googlegrou ps.com...
> On Aug 14, 4:04 pm, Alex Kuznetsov <AK_TIREDOFS...@.hotmail.COM> wrote:
> Learn how to understand and read the Execution Plan for your SQL,
> that's a great place to start.
> Good Luck,
> Mark
>
|||Thank you Alex.
"Alex Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1187121848.781330.112210@.i38g2000prf.googlegr oups.com...
> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> I would recommend "Inside SQL Server 2005" book series. These books
> come from authors with well established reputations and the books are
> great. You do not want to waste your time reading less than perfect
> and/or incorrect stuff that is is published on some web sites.
> Alex Kuznetsov, SQL Server MVP
> http://sqlserver-tips.blogspot.com/
>
|||Actually it sounds like you have already learned one of the most important
lessons. When you are optimizing long running queries, look for slow views
and especially slow views that are called repeatedly. Something else to be
aware of is whether the tables being called are wide tables. Faster views
consist of fewer fields. I have run across times when I could optimize a
view somewhat by joining only specific fields - for example instead of a
union of a current table with a history tables using select * from, change it
to select myID,CreateDate,myrequiredfield, myjoinfield from union (ditto) in
archive table. Other speedups may consist of regular rewrites of table
indexes (reindexing which defrags the index), creating non-clustered indexes
that are more pertinent to the larger queries and are wide enough to include
all the columns of a slower view - actually, this is something the tuning
optimizer (profiler) will give you when you run it.
Regards,
Jamie
"Dragon" wrote:

> Thank you Roy.
> the main reason I want to lean code optimization is because we are facing a
> lot of slow code. for example, we recently encounter a stored procedure that
> processed a particular function in over 60 hours. When it was rewritten with
> some additional indexes and temp tables, total time came down to 30 minutes.
> I want to learn this so that I can help in future occurrences of the same.
> Thanks.
>
> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
> news:7i14c35a2f46914f27j6gft8fh170k82cl@.4ax.com...
>
>

Best way to Learn T-SQL Performance Tuning

Hi,
I want to learn how to get the most performance out of T-SQL code.
essentially I want to learn to be able to rewrite T-SQL code to get better
performance out of stored procedures. What would you recommend is the best
AND fastest way to learn that? I am more interested in leaning performance
tuning of the code rather than SQL server itself.
Any recommendations on the site, books, software, etc would be good.
Thank you.http://www.sql-server-performance.com/transact_sql.asp
Regards,
Jamie
"Dragon" wrote:

> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>
>|||The problem you face in learning tuning of the code, rather than of
SQL Server, is that the biggest part of tuning is in the database
design and the indexing. The optimizer often turns many different
coding approaches into the same thing internally. What remaind for
tuning the code means understanding the optimizer. That is a bit of a
moving target as each new release and even service pack changes the
rules to some degree.
Roy Harvey
Beacon Falls, CT
On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
<noSpam_baadil@.hotmail.com> wrote:

>Hi,
>I want to learn how to get the most performance out of T-SQL code.
>essentially I want to learn to be able to rewrite T-SQL code to get better
>performance out of stored procedures. What would you recommend is the best
>AND fastest way to learn that? I am more interested in leaning performance
>tuning of the code rather than SQL server itself.
>Any recommendations on the site, books, software, etc would be good.
>Thank you.
>|||Thank you Roy.
the main reason I want to lean code optimization is because we are facing a
lot of slow code. for example, we recently encounter a stored procedure that
processed a particular function in over 60 hours. When it was rewritten with
some additional indexes and temp tables, total time came down to 30 minutes.
I want to learn this so that I can help in future occurrences of the same.
Thanks.
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:7i14c35a2f46914f27j6gft8fh170k82cl@.
4ax.com...[vbcol=seagreen]
> The problem you face in learning tuning of the code, rather than of
> SQL Server, is that the biggest part of tuning is in the database
> design and the indexing. The optimizer often turns many different
> coding approaches into the same thing internally. What remaind for
> tuning the code means understanding the optimizer. That is a bit of a
> moving target as each new release and even service pack changes the
> rules to some degree.
> Roy Harvey
> Beacon Falls, CT
> On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
> <noSpam_baadil@.hotmail.com> wrote:
>|||On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
I would recommend "Inside SQL Server 2005" book series. These books
come from authors with well established reputations and the books are
great. You do not want to waste your time reading less than perfect
and/or incorrect stuff that is is published on some web sites.
Alex Kuznetsov, SQL Server MVP
http://sqlserver-tips.blogspot.com/|||Thank you. That link did not work but I have been to that site before. It is
an excellent site with tons of usefull information. I think the only problem
is that it is more geared towards someone who is either looking for
particular information or is already an expert and needs confirmation. I am
not sure if it is good for a start-to-finish learning method. I could be
wrong.
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:A60F1359-98FB-41F2-9578-CA86E5A165DF@.microsoft.com...[vbcol=seagreen]
> http://www.sql-server-performance.com/transact_sql.asp
>
> --
> Regards,
> Jamie
>
> "Dragon" wrote:
>|||Thank you Mark. Any recommendation on a good source for leanring about
Execution Plans?
<mygolf51@.gmail.com> wrote in message
news:1187122016.610745.92110@.22g2000hsm.googlegroups.com...
> On Aug 14, 4:04 pm, Alex Kuznetsov <AK_TIREDOFS...@.hotmail.COM> wrote:
> Learn how to understand and read the Execution Plan for your SQL,
> that's a great place to start.
> Good Luck,
> Mark
>|||Thank you Alex.
"Alex Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1187121848.781330.112210@.i38g2000prf.googlegroups.com...
> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> I would recommend "Inside SQL Server 2005" book series. These books
> come from authors with well established reputations and the books are
> great. You do not want to waste your time reading less than perfect
> and/or incorrect stuff that is is published on some web sites.
> Alex Kuznetsov, SQL Server MVP
> http://sqlserver-tips.blogspot.com/
>|||Actually it sounds like you have already learned one of the most important
lessons. When you are optimizing long running queries, look for slow views
and especially slow views that are called repeatedly. Something else to be
aware of is whether the tables being called are wide tables. Faster views
consist of fewer fields. I have run across times when I could optimize a
view somewhat by joining only specific fields - for example instead of a
union of a current table with a history tables using select * from, change i
t
to select myID,CreateDate,myrequiredfield, myjoinfield from union (ditto) in
archive table. Other speedups may consist of regular rewrites of table
indexes (reindexing which defrags the index), creating non-clustered indexes
that are more pertinent to the larger queries and are wide enough to include
all the columns of a slower view - actually, this is something the tuning
optimizer (profiler) will give you when you run it.
--
Regards,
Jamie
"Dragon" wrote:

> Thank you Roy.
> the main reason I want to lean code optimization is because we are facing
a
> lot of slow code. for example, we recently encounter a stored procedure th
at
> processed a particular function in over 60 hours. When it was rewritten wi
th
> some additional indexes and temp tables, total time came down to 30 minute
s.
> I want to learn this so that I can help in future occurrences of the same.
> Thanks.
>
> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
> news:7i14c35a2f46914f27j6gft8fh170k82cl@.
4ax.com...
>
>|||Dragon wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
I am not sure what you are after.
One approach is to approach performance optimizing generically, as if it
were a job. Using this approach, you learn how to find out where
performance bottlenecks are, and where there is the most to gain. This
could be anywhere. It could be the use of the database by the
application(s), the way the client connects to the database, the network
traffic, the database structure, the way the queries are written, the
way the hardware is configured, etc. etc.
Using this approach, you mostly have to learn the methodology, and a
good judgement of different approaches towards the most cost effective
action.
The other approach is to specialize in a specific area, such as writing
efficient SQL statements. In poorly written code, a lot can be gained
with rewrites. The same is true for database tuning. In poorly designed
or poorly indexed database, a lot can be gained.
Obviously, you can't be an expert overnight. If you want to write good
SQL statements, you need to know SQL and the theory behind it and behind
RDBMS's and know things like how to change procedural code (such as
cursors) into set oriented code (SQL). If you want to write the most
efficient SQL statements, then you need to know about SQL Server
architecture, the query optimizer, the storage engine, know why UDF's
work the way they do, know about indexes and statistics, know about the
available physical operators, join methods, index strategies, etc. etc.
Gert-Jan

Best way to Learn T-SQL Performance Tuning

Hi,
I want to learn how to get the most performance out of T-SQL code.
essentially I want to learn to be able to rewrite T-SQL code to get better
performance out of stored procedures. What would you recommend is the best
AND fastest way to learn that? I am more interested in leaning performance
tuning of the code rather than SQL server itself.
Any recommendations on the site, books, software, etc would be good.
Thank you.http://www.sql-server-performance.com/transact_sql.asp
Regards,
Jamie
"Dragon" wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>
>|||The problem you face in learning tuning of the code, rather than of
SQL Server, is that the biggest part of tuning is in the database
design and the indexing. The optimizer often turns many different
coding approaches into the same thing internally. What remaind for
tuning the code means understanding the optimizer. That is a bit of a
moving target as each new release and even service pack changes the
rules to some degree.
Roy Harvey
Beacon Falls, CT
On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
<noSpam_baadil@.hotmail.com> wrote:
>Hi,
>I want to learn how to get the most performance out of T-SQL code.
>essentially I want to learn to be able to rewrite T-SQL code to get better
>performance out of stored procedures. What would you recommend is the best
>AND fastest way to learn that? I am more interested in leaning performance
>tuning of the code rather than SQL server itself.
>Any recommendations on the site, books, software, etc would be good.
>Thank you.
>|||On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
I would recommend "Inside SQL Server 2005" book series. These books
come from authors with well established reputations and the books are
great. You do not want to waste your time reading less than perfect
and/or incorrect stuff that is is published on some web sites.
Alex Kuznetsov, SQL Server MVP
http://sqlserver-tips.blogspot.com/|||Thank you Roy.
the main reason I want to lean code optimization is because we are facing a
lot of slow code. for example, we recently encounter a stored procedure that
processed a particular function in over 60 hours. When it was rewritten with
some additional indexes and temp tables, total time came down to 30 minutes.
I want to learn this so that I can help in future occurrences of the same.
Thanks.
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:7i14c35a2f46914f27j6gft8fh170k82cl@.4ax.com...
> The problem you face in learning tuning of the code, rather than of
> SQL Server, is that the biggest part of tuning is in the database
> design and the indexing. The optimizer often turns many different
> coding approaches into the same thing internally. What remaind for
> tuning the code means understanding the optimizer. That is a bit of a
> moving target as each new release and even service pack changes the
> rules to some degree.
> Roy Harvey
> Beacon Falls, CT
> On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
> <noSpam_baadil@.hotmail.com> wrote:
>>Hi,
>>I want to learn how to get the most performance out of T-SQL code.
>>essentially I want to learn to be able to rewrite T-SQL code to get better
>>performance out of stored procedures. What would you recommend is the best
>>AND fastest way to learn that? I am more interested in leaning performance
>>tuning of the code rather than SQL server itself.
>>Any recommendations on the site, books, software, etc would be good.
>>Thank you.|||On Aug 14, 4:04 pm, Alex Kuznetsov <AK_TIREDOFS...@.hotmail.COM> wrote:
> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
> > Hi,
> > I want to learn how to get the most performance out of T-SQL code.
> > essentially I want to learn to be able to rewrite T-SQL code to get better
> > performance out of stored procedures. What would you recommend is the best
> > AND fastest way to learn that? I am more interested in leaning performance
> > tuning of the code rather than SQL server itself.
> > Any recommendations on the site, books, software, etc would be good.
> > Thank you.
> I would recommend "Inside SQL Server 2005" book series. These books
> come from authors with well established reputations and the books are
> great. You do not want to waste your time reading less than perfect
> and/or incorrect stuff that is is published on some web sites.
> Alex Kuznetsov, SQL Server MVPhttp://sqlserver-tips.blogspot.com/
Learn how to understand and read the Execution Plan for your SQL,
that's a great place to start.
Good Luck,
Mark|||Thank you. That link did not work but I have been to that site before. It is
an excellent site with tons of usefull information. I think the only problem
is that it is more geared towards someone who is either looking for
particular information or is already an expert and needs confirmation. I am
not sure if it is good for a start-to-finish learning method. I could be
wrong.
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:A60F1359-98FB-41F2-9578-CA86E5A165DF@.microsoft.com...
> http://www.sql-server-performance.com/transact_sql.asp
>
> --
> Regards,
> Jamie
>
> "Dragon" wrote:
>> Hi,
>> I want to learn how to get the most performance out of T-SQL code.
>> essentially I want to learn to be able to rewrite T-SQL code to get
>> better
>> performance out of stored procedures. What would you recommend is the
>> best
>> AND fastest way to learn that? I am more interested in leaning
>> performance
>> tuning of the code rather than SQL server itself.
>> Any recommendations on the site, books, software, etc would be good.
>> Thank you.
>>|||Thank you Mark. Any recommendation on a good source for leanring about
Execution Plans?
<mygolf51@.gmail.com> wrote in message
news:1187122016.610745.92110@.22g2000hsm.googlegroups.com...
> On Aug 14, 4:04 pm, Alex Kuznetsov <AK_TIREDOFS...@.hotmail.COM> wrote:
>> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
>> > Hi,
>> > I want to learn how to get the most performance out of T-SQL code.
>> > essentially I want to learn to be able to rewrite T-SQL code to get
>> > better
>> > performance out of stored procedures. What would you recommend is the
>> > best
>> > AND fastest way to learn that? I am more interested in leaning
>> > performance
>> > tuning of the code rather than SQL server itself.
>> > Any recommendations on the site, books, software, etc would be good.
>> > Thank you.
>> I would recommend "Inside SQL Server 2005" book series. These books
>> come from authors with well established reputations and the books are
>> great. You do not want to waste your time reading less than perfect
>> and/or incorrect stuff that is is published on some web sites.
>> Alex Kuznetsov, SQL Server MVPhttp://sqlserver-tips.blogspot.com/
> Learn how to understand and read the Execution Plan for your SQL,
> that's a great place to start.
> Good Luck,
> Mark
>|||Thank you Alex.
"Alex Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1187121848.781330.112210@.i38g2000prf.googlegroups.com...
> On Aug 14, 2:32 pm, "Dragon" <noSpam_baa...@.hotmail.com> wrote:
>> Hi,
>> I want to learn how to get the most performance out of T-SQL code.
>> essentially I want to learn to be able to rewrite T-SQL code to get
>> better
>> performance out of stored procedures. What would you recommend is the
>> best
>> AND fastest way to learn that? I am more interested in leaning
>> performance
>> tuning of the code rather than SQL server itself.
>> Any recommendations on the site, books, software, etc would be good.
>> Thank you.
> I would recommend "Inside SQL Server 2005" book series. These books
> come from authors with well established reputations and the books are
> great. You do not want to waste your time reading less than perfect
> and/or incorrect stuff that is is published on some web sites.
> Alex Kuznetsov, SQL Server MVP
> http://sqlserver-tips.blogspot.com/
>|||Actually it sounds like you have already learned one of the most important
lessons. When you are optimizing long running queries, look for slow views
and especially slow views that are called repeatedly. Something else to be
aware of is whether the tables being called are wide tables. Faster views
consist of fewer fields. I have run across times when I could optimize a
view somewhat by joining only specific fields - for example instead of a
union of a current table with a history tables using select * from, change it
to select myID,CreateDate,myrequiredfield, myjoinfield from union (ditto) in
archive table. Other speedups may consist of regular rewrites of table
indexes (reindexing which defrags the index), creating non-clustered indexes
that are more pertinent to the larger queries and are wide enough to include
all the columns of a slower view - actually, this is something the tuning
optimizer (profiler) will give you when you run it.
--
Regards,
Jamie
"Dragon" wrote:
> Thank you Roy.
> the main reason I want to lean code optimization is because we are facing a
> lot of slow code. for example, we recently encounter a stored procedure that
> processed a particular function in over 60 hours. When it was rewritten with
> some additional indexes and temp tables, total time came down to 30 minutes.
> I want to learn this so that I can help in future occurrences of the same.
> Thanks.
>
> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
> news:7i14c35a2f46914f27j6gft8fh170k82cl@.4ax.com...
> > The problem you face in learning tuning of the code, rather than of
> > SQL Server, is that the biggest part of tuning is in the database
> > design and the indexing. The optimizer often turns many different
> > coding approaches into the same thing internally. What remaind for
> > tuning the code means understanding the optimizer. That is a bit of a
> > moving target as each new release and even service pack changes the
> > rules to some degree.
> >
> > Roy Harvey
> > Beacon Falls, CT
> >
> > On Tue, 14 Aug 2007 12:32:41 -0700, "Dragon"
> > <noSpam_baadil@.hotmail.com> wrote:
> >
> >>Hi,
> >>
> >>I want to learn how to get the most performance out of T-SQL code.
> >>essentially I want to learn to be able to rewrite T-SQL code to get better
> >>performance out of stored procedures. What would you recommend is the best
> >>AND fastest way to learn that? I am more interested in leaning performance
> >>tuning of the code rather than SQL server itself.
> >>
> >>Any recommendations on the site, books, software, etc would be good.
> >>
> >>Thank you.
> >>
>
>|||Dragon wrote:
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
I am not sure what you are after.
One approach is to approach performance optimizing generically, as if it
were a job. Using this approach, you learn how to find out where
performance bottlenecks are, and where there is the most to gain. This
could be anywhere. It could be the use of the database by the
application(s), the way the client connects to the database, the network
traffic, the database structure, the way the queries are written, the
way the hardware is configured, etc. etc.
Using this approach, you mostly have to learn the methodology, and a
good judgement of different approaches towards the most cost effective
action.
The other approach is to specialize in a specific area, such as writing
efficient SQL statements. In poorly written code, a lot can be gained
with rewrites. The same is true for database tuning. In poorly designed
or poorly indexed database, a lot can be gained.
Obviously, you can't be an expert overnight. If you want to write good
SQL statements, you need to know SQL and the theory behind it and behind
RDBMS's and know things like how to change procedural code (such as
cursors) into set oriented code (SQL). If you want to write the most
efficient SQL statements, then you need to know about SQL Server
architecture, the query optimizer, the storage engine, know why UDF's
work the way they do, know about indexes and statistics, know about the
available physical operators, join methods, index strategies, etc. etc.
Gert-Jan|||Below are some resources that will help.
Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/recomp.mspx
Statistics Used by the Query Optimizer in Microsoft SQL Server 2000
http://msdn2.microsoft.com/en-us/library/aa902688(SQL.80).aspx
Query Recompilation in SQL Server 2000
http://msdn2.microsoft.com/en-us/library/aa902682(SQL.80).aspx
Troubleshooting Performance Problems in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx
--
Umachandar Jayachandran
Microsoft SQL Server Performance Team
SQL Server Engine Team Tips Blog at
http://blogs.msdn.com/sqltips/default.aspx
SQL Server Performance Engineering Team Blog at
http://blogs.msdn.com/sqlperf/default.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.
Dragon wrote on Tue, 14 Aug 2007 12:32:41 -0700:
D> Hi,
D> I want to learn how to get the most performance out of T-SQL code.
D> essentially I want to learn to be able to rewrite T-SQL code to get
D> better performance out of stored procedures. What would you
D> recommend is the best
D> AND fastest way to learn that? I am more interested in leaning
D> performance tuning of the code rather than SQL server itself.
D> Any recommendations on the site, books, software, etc would be good.
D> Thank you.|||Hi Dragon
Query tuning has very little to do with re-writing code. Whilst it is true
that sometimes you do need to change code, it is crucial to understand that
SQL Server doesn't execute "code", it analyses code, turns it into execution
plans & executes the plans. The #1 rule for getting execution plans out of
SQL Server is that it can only work with the indexes you give it. Without
good indexes, SQL Server has no option other than to fully scan tables.
Once you understand these basic concepts, you will understand:
(a) The tuning game is mainly about indexes
and
(b) Re-writing SQL code is mainly about making sure that SQL Server
generates plans that use the correct indexes in the most efficient order.
This usually means using join or index hints and force ordering by
re-ordering names of tables in statements.
Structurally changing query expressions can also yield benefits, but only
because the change has influenced a more efficient execution plan. It is
also very common that changing the structure of query expressions will at
least slightly alter the actual meaning of the query & therefore potentially
the output of the query. This also means that tuning by changing query
syntax also creates more testing overhead than via indexing.
HTH
Regards,
Greg Linwood
SQL Server MVP
http://blogs.sqlserver.org.au/blogs/greg_linwood
Benchmark your query performance
http://www.SQLBenchmarkPro.com
"Dragon" <noSpam_baadil@.hotmail.com> wrote in message
news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>|||On Wed, 15 Aug 2007 11:02:39 +1000, "Greg Linwood"
<g_linwood@.hotmail.com> wrote:
>Once you understand these basic concepts, you will understand:
>(a) The tuning game is mainly about indexes
>and
...
Aaargh! It drives me nuts when people say that. Hey, half my
"tuning" work is running the wizard and restoring the PKs that have
mysteriously been dropped from major tables, but even so! :)
And half the rest is putting on new covering indexes for particular
expensive queries, but still! :)
The tuning game is as much about making sure your data model is
correct in general so that it even makes sense to build the indexes
that will let the compiler and optimizer have a chance at giving you a
good plan.
It's also about learning to use profiler (etc) just to see where the
friggin' thing is wasting its time, then you can work on the model or
the indexes or the coding and stand a chance of turning a profit.
I've outlined a SQLServer Performance cookbook, but I put it aside
because I needed some more hands-on with SQL2005. Maybe in six months
I'll be in sync with the releases and give it a shot.
J.|||I think that we tend to look at "Query tuning" from a perspective where you tune a query. This is
what many of the answers here has been focusing on. But lets not forget the slightly bigger picture,
say at the stored procedure level.
I'm thinking about things like cursors, populating a temp table and then select from it (can be a
good thing or a bad thing). Or just doing things in several TSQL statements where the logic can be
combined into one or fewer TSQL statements. Here the optimizer of course cannot re-write that logic
for us.
...just one additional thing to keep in mind.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Greg Linwood" <g_linwood@.hotmail.com> wrote in message
news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
> Hi Dragon
> Query tuning has very little to do with re-writing code. Whilst it is true that sometimes you do
> need to change code, it is crucial to understand that SQL Server doesn't execute "code", it
> analyses code, turns it into execution plans & executes the plans. The #1 rule for getting
> execution plans out of SQL Server is that it can only work with the indexes you give it. Without
> good indexes, SQL Server has no option other than to fully scan tables.
> Once you understand these basic concepts, you will understand:
> (a) The tuning game is mainly about indexes
> and
> (b) Re-writing SQL code is mainly about making sure that SQL Server generates plans that use the
> correct indexes in the most efficient order. This usually means using join or index hints and
> force ordering by re-ordering names of tables in statements.
> Structurally changing query expressions can also yield benefits, but only because the change has
> influenced a more efficient execution plan. It is also very common that changing the structure of
> query expressions will at least slightly alter the actual meaning of the query & therefore
> potentially the output of the query. This also means that tuning by changing query syntax also
> creates more testing overhead than via indexing.
> HTH
> Regards,
> Greg Linwood
> SQL Server MVP
> http://blogs.sqlserver.org.au/blogs/greg_linwood
> Benchmark your query performance
> http://www.SQLBenchmarkPro.com
> "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
> news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
>> Hi,
>> I want to learn how to get the most performance out of T-SQL code. essentially I want to learn to
>> be able to rewrite T-SQL code to get better performance out of stored procedures. What would you
>> recommend is the best AND fastest way to learn that? I am more interested in leaning performance
>> tuning of the code rather than SQL server itself.
>> Any recommendations on the site, books, software, etc would be good.
>> Thank you.
>|||On Aug 15, 1:46 am, thejamie <theja...@.discussions.microsoft.com>
wrote:
> http://www.sql-server-performance.com/transact_sql.asp
> --
> Regards,
> Jamie
>
> "Dragon" wrote:
> > Hi,
> > I want to learn how to get the most performance out of T-SQL code.
> > essentially I want to learn to be able to rewrite T-SQL code to get better
> > performance out of stored procedures. What would you recommend is the best
> > AND fastest way to learn that? I am more interested in leaning performance
> > tuning of the code rather than SQL server itself.
> > Any recommendations on the site, books, software, etc would be good.
> > Thank you.- Hide quoted text -
> - Show quoted text -
The problem is BOL don't come with the manuals like they used to
before. Now they have internet and all that and you don't have those
books anymore. I would recommend picking up manuals (T-SQL)
specifically catered to 'Query Optimization and Performance Tuning'.
It's a huge and very complex concept and I can barely can scratch it.|||Microsoft and other entities have classes dedicated to perf tuning. That
will give you your quickest return I think.
--
TheSQLGuru
President
Indicium Resources, Inc.
"Dragon" <noSpam_baadil@.hotmail.com> wrote in message
news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>|||Karen Delaney is working on a book
http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969/ref=pd_bbs_sr_2/002-3675746-5484807?ie=UTF8&s=books&qid=1187195868&sr=8-2
Also Itzik Ben Gan and Tom Moreau did an excellent job in their book for SQL
2000.
http://www.amazon.com/Advanced-Transact-SQL-SQL-Server-2000/dp/1893115828/ref=sr_1_1/002-3675746-5484807?ie=UTF8&s=books&qid=1187195908&sr=1-1
You also might want to look at:
http://www.amazon.com/Server-Performance-Tuning-Distilled-Second/dp/1590594215/ref=sr_1_1/002-3675746-5484807?ie=UTF8&s=books&qid=1187195950&sr=1-1
relevantNoise - dedicated to mining blogs for business intelligence.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dragon" <noSpam_baadil@.hotmail.com> wrote in message
news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>|||Thank you Tibor.
This is exactly what I am trying to learn. Most of our SQL usage is
stored-procedure based and my goal is work look at the existing as well as
new SPs and make sure they are not causing any table scan, they don't use
cursor unless they have to and they use temp tables where appropriate.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OgXrI2w3HHA.4712@.TK2MSFTNGP04.phx.gbl...
>I think that we tend to look at "Query tuning" from a perspective where you
>tune a query. This is what many of the answers here has been focusing on.
>But lets not forget the slightly bigger picture, say at the stored
>procedure level.
> I'm thinking about things like cursors, populating a temp table and then
> select from it (can be a good thing or a bad thing). Or just doing things
> in several TSQL statements where the logic can be combined into one or
> fewer TSQL statements. Here the optimizer of course cannot re-write that
> logic for us.
> ...just one additional thing to keep in mind.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
>> Hi Dragon
>> Query tuning has very little to do with re-writing code. Whilst it is
>> true that sometimes you do need to change code, it is crucial to
>> understand that SQL Server doesn't execute "code", it analyses code,
>> turns it into execution plans & executes the plans. The #1 rule for
>> getting execution plans out of SQL Server is that it can only work with
>> the indexes you give it. Without good indexes, SQL Server has no option
>> other than to fully scan tables.
>> Once you understand these basic concepts, you will understand:
>> (a) The tuning game is mainly about indexes
>> and
>> (b) Re-writing SQL code is mainly about making sure that SQL Server
>> generates plans that use the correct indexes in the most efficient order.
>> This usually means using join or index hints and force ordering by
>> re-ordering names of tables in statements.
>> Structurally changing query expressions can also yield benefits, but only
>> because the change has influenced a more efficient execution plan. It is
>> also very common that changing the structure of query expressions will at
>> least slightly alter the actual meaning of the query & therefore
>> potentially the output of the query. This also means that tuning by
>> changing query syntax also creates more testing overhead than via
>> indexing.
>> HTH
>> Regards,
>> Greg Linwood
>> SQL Server MVP
>> http://blogs.sqlserver.org.au/blogs/greg_linwood
>> Benchmark your query performance
>> http://www.SQLBenchmarkPro.com
>> "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
>> news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
>> Hi,
>> I want to learn how to get the most performance out of T-SQL code.
>> essentially I want to learn to be able to rewrite T-SQL code to get
>> better performance out of stored procedures. What would you recommend is
>> the best AND fastest way to learn that? I am more interested in leaning
>> performance tuning of the code rather than SQL server itself.
>> Any recommendations on the site, books, software, etc would be good.
>> Thank you.
>>
>|||I have to say I really disagree with that Greg!
Tuning to me is about "best practice", although of course this means lots of
things, I believe well designed databases and code will perform.
Try the MSDN SQL Server best practice site:
http://technet.microsoft.com/en-us/sqlserver/bb331794.aspx
I could mention many techniques I consider to be best practice, I'll try a
few:-
Break it up - avoid massive procs, huge queries. It's easier to identify
bottlenecks ( eg using the Profiler Duration template )
Write "good" SQL - avoid CURSORs if at all possible, avoid overuse of
subqueries, overly complex expressions, know when to use temp tables and temp
variables, avoid use of VIEWs on VIEWs on VIEWs the optimizer isn't great
with these. Nice compact statements, well formatted and well commented ( it
matters! ). When to use the different constructs at your disposal eg LEFT
JOIN, IF ... ELSE, the new stuff in 2005 eg INTERSECT and EXCEPT, CTEs (
they're really cool ! ).
Know your data - I see so much use of DISTINCT / GROUP BY or ORDER BY when
there's no need.
Something really common I see is use of cursors to call stored procs
multiple times. "This is the only way to do this" I hear said. I love
converting these to set logic and seeing them run 10 times faster. Any data
which is available to a cursor to call a proc many times must surely be
available in a set.
Of course indexes.
Space - got your database file and log sizes right? Growths are costly!
Hardware - got it set up right? Got your tempdb set up right?
So as you can see "best practice" is a combination of all sorts of things.
Finally, it should include knowing your tools - I count knowing how to read
execution plans and knowing when to use the different Profiler templates
under that heading.
Hope some of that helps!
wBob|||On Wed, 15 Aug 2007 12:40:32 -0400, "Hilary Cotter"
<hilary.cotter@.gmail.com> wrote:
>Karen Delaney is working on a book
>http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969/ref=pd_bbs_sr_2/002-3675746-5484807?ie=UTF8&s=books&qid=1187195868&sr=8-2
Well, that should be worth waiting for!
J.|||In article <#WIrUs13HHA.1164@.TK2MSFTNGP02.phx.gbl>,
hilary.cotter@.gmail.com says...
> You also might want to look at:
> http://www.amazon.com/Server-Performance-Tuning-Distilled-Second/dp/1590594215/ref=sr_1_1/002-3675746-5484807?ie=UTF8&s=books&qid=1187195950&sr=1-1
>
>
Excellent resource to walk hands-on through to learn some principles. I
found it especially helpful for relative newbies as a learning tool.
The code samples are also all available online.
--
Graham (Pete) Berry
PeteBerry@.Caltech.edu
MCT2007|||Kalen Delaney is also working on a book... ;-)
Actually, she is done working on it, and it is in the hands of the printers
now...
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"JXStern" <JXSternChangeX2R@.gte.net> wrote in message
news:qcq8c3tehip3oj5fa5441f4et3o14c3u6g@.4ax.com...
> On Wed, 15 Aug 2007 12:40:32 -0400, "Hilary Cotter"
> <hilary.cotter@.gmail.com> wrote:
>>Karen Delaney is working on a book
>>http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969/ref=pd_bbs_sr_2/002-3675746-5484807?ie=UTF8&s=books&qid=1187195868&sr=8-2
> Well, that should be worth waiting for!
>
> J.
>|||You got a lot of really good advice in this thread, in particular:
Tibor's comment:
>I'm thinking about things like cursors, populating a temp table and then
>select >from it (can be a good thing or a bad thing). Or just doing things
>in several TSQL statements >where the logic can be combined into one or
>fewer TSQL statements. Here the optimizer of course >cannot re-write that
>logic for us.
Note he only referenced stored procedures, this was the meat.
Mark's comment:
>Learn how to understand and read the Execution Plan for your SQL,
>that's a great place to start.
Just start by doing it.
Gert-Jen's comment:
>Using this approach, you mostly have to learn the methodology, and a
>good judgment of different approaches towards the most cost effective
>action.
Yes, methodology is possibly the most important.
Greg's comment:
>(b) Re-writing SQL code is mainly about making sure that SQL Server
>generates plans that use the correct indexes in the most efficient order.
>This usually means using join or index hints and force ordering by
>re-ordering names of tables in statements.
JXStern's comment:
>The tuning game is as much about making sure your data model is
>correct in general so that it even makes sense to build the indexes
>that will let the compiler and optimizer have a chance at giving you a
>good plan.
True, very very true.
>It's also about learning to use profiler (etc) just to see where the
>friggin' thing is wasting its time, then you can work on the model or
>the indexes or the coding and stand a chance of turning a profit.
The profiler can be a bitch to learn effectively, but it is your window into
the system where you get to see what is happening.
...
Beyond all of that fantastic advice, you were pointed to some really good
resources. Hey, I may buy Kalen's book.
What it all comes down to though is: can look at something and "see" what
kind of things are wrong. If you can do that, you will achieve your goal.
The two items I can think of that weren't highlighted were: improper, or
excessive use of temp tables (note Tibor's comment) and use of functions in
the WHERE clause.
Good Luck,
Good Skill,
Good Studying,
Jay
"Dragon" <noSpam_baadil@.hotmail.com> wrote in message
news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I want to learn how to get the most performance out of T-SQL code.
> essentially I want to learn to be able to rewrite T-SQL code to get better
> performance out of stored procedures. What would you recommend is the best
> AND fastest way to learn that? I am more interested in leaning performance
> tuning of the code rather than SQL server itself.
> Any recommendations on the site, books, software, etc would be good.
> Thank you.
>|||I'm really eager for that Kalen! :)
When will it be published? What's its name?
Thanks,
Leila
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:uu15SQg4HHA.4476@.TK2MSFTNGP06.phx.gbl...
> Kalen Delaney is also working on a book... ;-)
> Actually, she is done working on it, and it is in the hands of the
> printers now...
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://sqlblog.com
>
> "JXStern" <JXSternChangeX2R@.gte.net> wrote in message
> news:qcq8c3tehip3oj5fa5441f4et3o14c3u6g@.4ax.com...
>> On Wed, 15 Aug 2007 12:40:32 -0400, "Hilary Cotter"
>> <hilary.cotter@.gmail.com> wrote:
>>Karen Delaney is working on a book
>>http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969/ref=pd_bbs_sr_2/002-3675746-5484807?ie=UTF8&s=books&qid=1187195868&sr=8-2
>> Well, that should be worth waiting for!
>>
>> J.
>|||Must be this one:
http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969
available September 29, 2007.
--
Gert-Jan
Leila wrote:
> I'm really eager for that Kalen! :)
> When will it be published? What's its name?
> Thanks,
> Leila
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:uu15SQg4HHA.4476@.TK2MSFTNGP06.phx.gbl...
> > Kalen Delaney is also working on a book... ;-)
> >
> > Actually, she is done working on it, and it is in the hands of the
> > printers now...
> >
> > --
> > HTH
> > Kalen Delaney, SQL Server MVP
> > www.InsideSQLServer.com
> > http://sqlblog.com
> >
> >
> > "JXStern" <JXSternChangeX2R@.gte.net> wrote in message
> > news:qcq8c3tehip3oj5fa5441f4et3o14c3u6g@.4ax.com...
> >> On Wed, 15 Aug 2007 12:40:32 -0400, "Hilary Cotter"
> >> <hilary.cotter@.gmail.com> wrote:
> >>
> >>Karen Delaney is working on a book
> >>
> >>http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735621969/ref=pd_bbs_sr_2/002-3675746-5484807?ie=UTF8&s=books&qid=1187195868&sr=8-2
> >>
> >> Well, that should be worth waiting for!
> >>
> >>
> >> J.
> >>
> >
> >|||Hey All,
I would like to be able to write efficient SQL Statements (queries for
reporting purposes and sprocs for DB maintenance as well). I may, or may not
have the option of creating/modifying indicies. I understand that there may
be many ways to design a query to solve a problem, so I would like to be in a
position where I am aware of all my options and able to select the most
efficient design strategies to test. I suppose this means having a
theoretical understanding of how SQLServer processes SQL statements.
Can someone recommend a good resource I could use?
Thanks,
"Tibor Karaszi" wrote:
> I think that we tend to look at "Query tuning" from a perspective where you tune a query. This is
> what many of the answers here has been focusing on. But lets not forget the slightly bigger picture,
> say at the stored procedure level.
> I'm thinking about things like cursors, populating a temp table and then select from it (can be a
> good thing or a bad thing). Or just doing things in several TSQL statements where the logic can be
> combined into one or fewer TSQL statements. Here the optimizer of course cannot re-write that logic
> for us.
> ...just one additional thing to keep in mind.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
> > Hi Dragon
> >
> > Query tuning has very little to do with re-writing code. Whilst it is true that sometimes you do
> > need to change code, it is crucial to understand that SQL Server doesn't execute "code", it
> > analyses code, turns it into execution plans & executes the plans. The #1 rule for getting
> > execution plans out of SQL Server is that it can only work with the indexes you give it. Without
> > good indexes, SQL Server has no option other than to fully scan tables.
> >
> > Once you understand these basic concepts, you will understand:
> >
> > (a) The tuning game is mainly about indexes
> >
> > and
> >
> > (b) Re-writing SQL code is mainly about making sure that SQL Server generates plans that use the
> > correct indexes in the most efficient order. This usually means using join or index hints and
> > force ordering by re-ordering names of tables in statements.
> >
> > Structurally changing query expressions can also yield benefits, but only because the change has
> > influenced a more efficient execution plan. It is also very common that changing the structure of
> > query expressions will at least slightly alter the actual meaning of the query & therefore
> > potentially the output of the query. This also means that tuning by changing query syntax also
> > creates more testing overhead than via indexing.
> >
> > HTH
> >
> > Regards,
> > Greg Linwood
> > SQL Server MVP
> > http://blogs.sqlserver.org.au/blogs/greg_linwood
> > Benchmark your query performance
> > http://www.SQLBenchmarkPro.com
> >
> > "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
> > news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> >> Hi,
> >>
> >> I want to learn how to get the most performance out of T-SQL code. essentially I want to learn to
> >> be able to rewrite T-SQL code to get better performance out of stored procedures. What would you
> >> recommend is the best AND fastest way to learn that? I am more interested in leaning performance
> >> tuning of the code rather than SQL server itself.
> >>
> >> Any recommendations on the site, books, software, etc would be good.
> >>
> >> Thank you.
> >>
> >
> >
>|||> I would like to be able to write efficient SQL Statements (queries for
> reporting purposes and sprocs for DB maintenance as well). I may, or may
> not
> have the option of creating/modifying indicies. I understand that there
> may
> be many ways to design a query to solve a problem, so I would like to be
> in a
> position where I am aware of all my options and able to select the most
> efficient design strategies to test.
Proper schema design and indexing is the most important part of query
performance. Much of efficient query development involves leveraging
existing indexes.
> I suppose this means having a
> theoretical understanding of how SQLServer processes SQL statements.
> Can someone recommend a good resource I could use?
A good books is "Inside SQL Server 2005: T-SQL Querying".
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Hafeez Esmail" <HafeezEsmail@.discussions.microsoft.com> wrote in message
news:3707829A-5E4A-4B30-932D-4464CDEC1283@.microsoft.com...
> Hey All,
> I would like to be able to write efficient SQL Statements (queries for
> reporting purposes and sprocs for DB maintenance as well). I may, or may
> not
> have the option of creating/modifying indicies. I understand that there
> may
> be many ways to design a query to solve a problem, so I would like to be
> in a
> position where I am aware of all my options and able to select the most
> efficient design strategies to test. I suppose this means having a
> theoretical understanding of how SQLServer processes SQL statements.
> Can someone recommend a good resource I could use?
> Thanks,
> "Tibor Karaszi" wrote:
>> I think that we tend to look at "Query tuning" from a perspective where
>> you tune a query. This is
>> what many of the answers here has been focusing on. But lets not forget
>> the slightly bigger picture,
>> say at the stored procedure level.
>> I'm thinking about things like cursors, populating a temp table and then
>> select from it (can be a
>> good thing or a bad thing). Or just doing things in several TSQL
>> statements where the logic can be
>> combined into one or fewer TSQL statements. Here the optimizer of course
>> cannot re-write that logic
>> for us.
>> ...just one additional thing to keep in mind.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
>> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
>> > Hi Dragon
>> >
>> > Query tuning has very little to do with re-writing code. Whilst it is
>> > true that sometimes you do
>> > need to change code, it is crucial to understand that SQL Server
>> > doesn't execute "code", it
>> > analyses code, turns it into execution plans & executes the plans. The
>> > #1 rule for getting
>> > execution plans out of SQL Server is that it can only work with the
>> > indexes you give it. Without
>> > good indexes, SQL Server has no option other than to fully scan tables.
>> >
>> > Once you understand these basic concepts, you will understand:
>> >
>> > (a) The tuning game is mainly about indexes
>> >
>> > and
>> >
>> > (b) Re-writing SQL code is mainly about making sure that SQL Server
>> > generates plans that use the
>> > correct indexes in the most efficient order. This usually means using
>> > join or index hints and
>> > force ordering by re-ordering names of tables in statements.
>> >
>> > Structurally changing query expressions can also yield benefits, but
>> > only because the change has
>> > influenced a more efficient execution plan. It is also very common that
>> > changing the structure of
>> > query expressions will at least slightly alter the actual meaning of
>> > the query & therefore
>> > potentially the output of the query. This also means that tuning by
>> > changing query syntax also
>> > creates more testing overhead than via indexing.
>> >
>> > HTH
>> >
>> > Regards,
>> > Greg Linwood
>> > SQL Server MVP
>> > http://blogs.sqlserver.org.au/blogs/greg_linwood
>> > Benchmark your query performance
>> > http://www.SQLBenchmarkPro.com
>> >
>> > "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
>> > news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
>> >> Hi,
>> >>
>> >> I want to learn how to get the most performance out of T-SQL code.
>> >> essentially I want to learn to
>> >> be able to rewrite T-SQL code to get better performance out of stored
>> >> procedures. What would you
>> >> recommend is the best AND fastest way to learn that? I am more
>> >> interested in leaning performance
>> >> tuning of the code rather than SQL server itself.
>> >>
>> >> Any recommendations on the site, books, software, etc would be good.
>> >>
>> >> Thank you.
>> >>
>> >
>> >
>>|||You didn't state your initial level of training/experience. If total
newbie, check out some of the beginner series books from WROX dealing with
sql server and transact sql. If knowledgeable, try some of the books by
Itzik Ben-Gan.
If your company will hire a professional for some performance
tuning/mentoring work your skills will grow by leaps and bounds very quickly
and the company will benefit at the same time.
--
Kevin G. Boles
TheSQLGuru
Indicium Resources, Inc.
"Hafeez Esmail" <HafeezEsmail@.discussions.microsoft.com> wrote in message
news:3707829A-5E4A-4B30-932D-4464CDEC1283@.microsoft.com...
> Hey All,
> I would like to be able to write efficient SQL Statements (queries for
> reporting purposes and sprocs for DB maintenance as well). I may, or may
> not
> have the option of creating/modifying indicies. I understand that there
> may
> be many ways to design a query to solve a problem, so I would like to be
> in a
> position where I am aware of all my options and able to select the most
> efficient design strategies to test. I suppose this means having a
> theoretical understanding of how SQLServer processes SQL statements.
> Can someone recommend a good resource I could use?
> Thanks,
> "Tibor Karaszi" wrote:
>> I think that we tend to look at "Query tuning" from a perspective where
>> you tune a query. This is
>> what many of the answers here has been focusing on. But lets not forget
>> the slightly bigger picture,
>> say at the stored procedure level.
>> I'm thinking about things like cursors, populating a temp table and then
>> select from it (can be a
>> good thing or a bad thing). Or just doing things in several TSQL
>> statements where the logic can be
>> combined into one or fewer TSQL statements. Here the optimizer of course
>> cannot re-write that logic
>> for us.
>> ...just one additional thing to keep in mind.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
>> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
>> > Hi Dragon
>> >
>> > Query tuning has very little to do with re-writing code. Whilst it is
>> > true that sometimes you do
>> > need to change code, it is crucial to understand that SQL Server
>> > doesn't execute "code", it
>> > analyses code, turns it into execution plans & executes the plans. The
>> > #1 rule for getting
>> > execution plans out of SQL Server is that it can only work with the
>> > indexes you give it. Without
>> > good indexes, SQL Server has no option other than to fully scan tables.
>> >
>> > Once you understand these basic concepts, you will understand:
>> >
>> > (a) The tuning game is mainly about indexes
>> >
>> > and
>> >
>> > (b) Re-writing SQL code is mainly about making sure that SQL Server
>> > generates plans that use the
>> > correct indexes in the most efficient order. This usually means using
>> > join or index hints and
>> > force ordering by re-ordering names of tables in statements.
>> >
>> > Structurally changing query expressions can also yield benefits, but
>> > only because the change has
>> > influenced a more efficient execution plan. It is also very common that
>> > changing the structure of
>> > query expressions will at least slightly alter the actual meaning of
>> > the query & therefore
>> > potentially the output of the query. This also means that tuning by
>> > changing query syntax also
>> > creates more testing overhead than via indexing.
>> >
>> > HTH
>> >
>> > Regards,
>> > Greg Linwood
>> > SQL Server MVP
>> > http://blogs.sqlserver.org.au/blogs/greg_linwood
>> > Benchmark your query performance
>> > http://www.SQLBenchmarkPro.com
>> >
>> > "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
>> > news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
>> >> Hi,
>> >>
>> >> I want to learn how to get the most performance out of T-SQL code.
>> >> essentially I want to learn to
>> >> be able to rewrite T-SQL code to get better performance out of stored
>> >> procedures. What would you
>> >> recommend is the best AND fastest way to learn that? I am more
>> >> interested in leaning performance
>> >> tuning of the code rather than SQL server itself.
>> >>
>> >> Any recommendations on the site, books, software, etc would be good.
>> >>
>> >> Thank you.
>> >>
>> >
>> >
>>|||Thanks for the advice guys.
I've been writing SQL statements in Access (not the GUI query
builder...actually writing the SQL) for a few years now. I've also read the
Learn T-SQL in 10 minutes book (I think it was SAMS), which, other than
introducing me to triggers and views, didn't teach me anything new as far as
understanding which query designs are fastest and why.
Hiring a professional to do a personal lesson would be my favourite option,
but that would require flying someone into town...and that alone is way too
expensive.
"TheSQLGuru" wrote:
> You didn't state your initial level of training/experience. If total
> newbie, check out some of the beginner series books from WROX dealing with
> sql server and transact sql. If knowledgeable, try some of the books by
> Itzik Ben-Gan.
> If your company will hire a professional for some performance
> tuning/mentoring work your skills will grow by leaps and bounds very quickly
> and the company will benefit at the same time.
> --
> Kevin G. Boles
> TheSQLGuru
> Indicium Resources, Inc.
>
> "Hafeez Esmail" <HafeezEsmail@.discussions.microsoft.com> wrote in message
> news:3707829A-5E4A-4B30-932D-4464CDEC1283@.microsoft.com...
> > Hey All,
> >
> > I would like to be able to write efficient SQL Statements (queries for
> > reporting purposes and sprocs for DB maintenance as well). I may, or may
> > not
> > have the option of creating/modifying indicies. I understand that there
> > may
> > be many ways to design a query to solve a problem, so I would like to be
> > in a
> > position where I am aware of all my options and able to select the most
> > efficient design strategies to test. I suppose this means having a
> > theoretical understanding of how SQLServer processes SQL statements.
> > Can someone recommend a good resource I could use?
> >
> > Thanks,
> >
> > "Tibor Karaszi" wrote:
> >
> >> I think that we tend to look at "Query tuning" from a perspective where
> >> you tune a query. This is
> >> what many of the answers here has been focusing on. But lets not forget
> >> the slightly bigger picture,
> >> say at the stored procedure level.
> >>
> >> I'm thinking about things like cursors, populating a temp table and then
> >> select from it (can be a
> >> good thing or a bad thing). Or just doing things in several TSQL
> >> statements where the logic can be
> >> combined into one or fewer TSQL statements. Here the optimizer of course
> >> cannot re-write that logic
> >> for us.
> >>
> >> ...just one additional thing to keep in mind.
> >>
> >> --
> >> Tibor Karaszi, SQL Server MVP
> >> http://www.karaszi.com/sqlserver/default.asp
> >> http://sqlblog.com/blogs/tibor_karaszi
> >>
> >>
> >> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
> >> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
> >> > Hi Dragon
> >> >
> >> > Query tuning has very little to do with re-writing code. Whilst it is
> >> > true that sometimes you do
> >> > need to change code, it is crucial to understand that SQL Server
> >> > doesn't execute "code", it
> >> > analyses code, turns it into execution plans & executes the plans. The
> >> > #1 rule for getting
> >> > execution plans out of SQL Server is that it can only work with the
> >> > indexes you give it. Without
> >> > good indexes, SQL Server has no option other than to fully scan tables.
> >> >
> >> > Once you understand these basic concepts, you will understand:
> >> >
> >> > (a) The tuning game is mainly about indexes
> >> >
> >> > and
> >> >
> >> > (b) Re-writing SQL code is mainly about making sure that SQL Server
> >> > generates plans that use the
> >> > correct indexes in the most efficient order. This usually means using
> >> > join or index hints and
> >> > force ordering by re-ordering names of tables in statements.
> >> >
> >> > Structurally changing query expressions can also yield benefits, but
> >> > only because the change has
> >> > influenced a more efficient execution plan. It is also very common that
> >> > changing the structure of
> >> > query expressions will at least slightly alter the actual meaning of
> >> > the query & therefore
> >> > potentially the output of the query. This also means that tuning by
> >> > changing query syntax also
> >> > creates more testing overhead than via indexing.
> >> >
> >> > HTH
> >> >
> >> > Regards,
> >> > Greg Linwood
> >> > SQL Server MVP
> >> > http://blogs.sqlserver.org.au/blogs/greg_linwood
> >> > Benchmark your query performance
> >> > http://www.SQLBenchmarkPro.com
> >> >
> >> > "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
> >> > news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
> >> >> Hi,
> >> >>
> >> >> I want to learn how to get the most performance out of T-SQL code.
> >> >> essentially I want to learn to
> >> >> be able to rewrite T-SQL code to get better performance out of stored
> >> >> procedures. What would you
> >> >> recommend is the best AND fastest way to learn that? I am more
> >> >> interested in leaning performance
> >> >> tuning of the code rather than SQL server itself.
> >> >>
> >> >> Any recommendations on the site, books, software, etc would be good.
> >> >>
> >> >> Thank you.
> >> >>
> >> >
> >> >
> >>
> >>
>
>|||Hafeez Esmail (HafeezEsmail@.discussions.microsoft.com) writes:
> I've been writing SQL statements in Access (not the GUI query
> builder...actually writing the SQL) for a few years now. I've also
> read the Learn T-SQL in 10 minutes book (I think it was SAMS), which,
> other than introducing me to triggers and views, didn't teach me
> anything new as far as understanding which query designs are fastest and
> why. Hiring a professional to do a personal lesson would be my favourite
> option, but that would require flying someone into town...and that
> alone is way too expensive.
With that background, the "Inside SQL Server 2005" books by Itzik Ben-Gan
and Kalen Delaney should definitely be a good option.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx|||also you may browse through the articles on this site:
http://www.sql-server-performance.com/
--
http://elsasoft.org
"Hafeez Esmail" <HafeezEsmail@.discussions.microsoft.com> wrote in message
news:3707829A-5E4A-4B30-932D-4464CDEC1283@.microsoft.com...
> Hey All,
> I would like to be able to write efficient SQL Statements (queries for
> reporting purposes and sprocs for DB maintenance as well). I may, or may
> not
> have the option of creating/modifying indicies. I understand that there
> may
> be many ways to design a query to solve a problem, so I would like to be
> in a
> position where I am aware of all my options and able to select the most
> efficient design strategies to test. I suppose this means having a
> theoretical understanding of how SQLServer processes SQL statements.
> Can someone recommend a good resource I could use?
> Thanks,
> "Tibor Karaszi" wrote:
>> I think that we tend to look at "Query tuning" from a perspective where
>> you tune a query. This is
>> what many of the answers here has been focusing on. But lets not forget
>> the slightly bigger picture,
>> say at the stored procedure level.
>> I'm thinking about things like cursors, populating a temp table and then
>> select from it (can be a
>> good thing or a bad thing). Or just doing things in several TSQL
>> statements where the logic can be
>> combined into one or fewer TSQL statements. Here the optimizer of course
>> cannot re-write that logic
>> for us.
>> ...just one additional thing to keep in mind.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Greg Linwood" <g_linwood@.hotmail.com> wrote in message
>> news:uj$Ppft3HHA.2208@.TK2MSFTNGP06.phx.gbl...
>> > Hi Dragon
>> >
>> > Query tuning has very little to do with re-writing code. Whilst it is
>> > true that sometimes you do
>> > need to change code, it is crucial to understand that SQL Server
>> > doesn't execute "code", it
>> > analyses code, turns it into execution plans & executes the plans. The
>> > #1 rule for getting
>> > execution plans out of SQL Server is that it can only work with the
>> > indexes you give it. Without
>> > good indexes, SQL Server has no option other than to fully scan tables.
>> >
>> > Once you understand these basic concepts, you will understand:
>> >
>> > (a) The tuning game is mainly about indexes
>> >
>> > and
>> >
>> > (b) Re-writing SQL code is mainly about making sure that SQL Server
>> > generates plans that use the
>> > correct indexes in the most efficient order. This usually means using
>> > join or index hints and
>> > force ordering by re-ordering names of tables in statements.
>> >
>> > Structurally changing query expressions can also yield benefits, but
>> > only because the change has
>> > influenced a more efficient execution plan. It is also very common that
>> > changing the structure of
>> > query expressions will at least slightly alter the actual meaning of
>> > the query & therefore
>> > potentially the output of the query. This also means that tuning by
>> > changing query syntax also
>> > creates more testing overhead than via indexing.
>> >
>> > HTH
>> >
>> > Regards,
>> > Greg Linwood
>> > SQL Server MVP
>> > http://blogs.sqlserver.org.au/blogs/greg_linwood
>> > Benchmark your query performance
>> > http://www.SQLBenchmarkPro.com
>> >
>> > "Dragon" <noSpam_baadil@.hotmail.com> wrote in message
>> > news:eDBQinq3HHA.5316@.TK2MSFTNGP04.phx.gbl...
>> >> Hi,
>> >>
>> >> I want to learn how to get the most performance out of T-SQL code.
>> >> essentially I want to learn to
>> >> be able to rewrite T-SQL code to get better performance out of stored
>> >> procedures. What would you
>> >> recommend is the best AND fastest way to learn that? I am more
>> >> interested in leaning performance
>> >> tuning of the code rather than SQL server itself.
>> >>
>> >> Any recommendations on the site, books, software, etc would be good.
>> >>
>> >> Thank you.
>> >>
>> >
>> >
>>|||"Hafeez Esmail" <HafeezEsmail@.discussions.microsoft.com> wrote in message
news:3707829A-5E4A-4B30-932D-4464CDEC1283@.microsoft.com...
> Hey All,
> I would like to be able to write efficient SQL Statements (queries for
> reporting purposes and sprocs for DB maintenance as well). I may, or may
> not
> have the option of creating/modifying indicies. I understand that there
> may
> be many ways to design a query to solve a problem, so I would like to be
> in a
> position where I am aware of all my options and able to select the most
> efficient design strategies to test. I suppose this means having a
> theoretical understanding of how SQLServer processes SQL statements.
> Can someone recommend a good resource I could use?
if you cannot create or modify indices this may prove to be an *extremely*
frustrating exercise, if not an impossible one; that said, one piece of
advice: learn to read and understand execution plans ... they will tell you
a lot about how SQL Server is processing your query ... and they will also
serve as a segue into "theoretical understanding" if you are inclined to go
down that road ...
but really, if you are being constrained by company policy re
creation/modification of indices, either use your own machine or ask if your
DBA can set up an offline database where you *can* create and modify indices