Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Improving Speed of Query

Author  Topic 

redbrad0
Posting Yak Master

176 Posts

Posted - 2005-12-04 : 19:52:02
I am not sure the best way to get you guys to help me so hopefully this will be enough info. I am running about 1 million SP's that are the exact same a day with a different value. This is taking 187 CPU, 402 Reads, 0 Writes & 266 Duration. I took out the SP and hard coded in the values (only thing pass thru is domain-name.com thru the SP). Here is the image of what is returned. What should I look at to improve this Query?



Quality NT Web Hosting & Design

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-12-04 : 21:41:57
The best way to speed this up would be getting rid of the like '%value%'. If you can capture the domain name seperately and just query directly against it, you would get a lot better results. You might also try forcing a loop join (not sure I would do this). :) You can change the inner join to INNER LOOP JOIN if you want to try it though.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

redbrad0
Posting Yak Master

176 Posts

Posted - 2005-12-04 : 22:22:43
Well the reason why I use like is because in the field it has full paths to folders. A example would be

http://www.domain-name.com/folder/

and I am searching for just the domain names.

Quality NT Web Hosting & Design
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-12-04 : 23:13:40
The best way to speed this up would be getting rid of the like '%value%'. If you can capture the domain name seperately and just query directly against it, you would get a lot better results.



MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

SQLServerDBA_Dan
Aged Yak Warrior

752 Posts

Posted - 2005-12-05 : 15:09:08
You also want to make sure your datatypes all match up. If User_id is varchar(150) and the Usersjobs_userid is varchar(100) then you will have some more time spent in the hashing of the two tables because sql server will first cast the datatypes to make them the same. I can't tell if your datatypes match or not... I'm just giving a general statement. Be sure to always mouse over the "hash" and see what join sql server actually used to join the tables.
Go to Top of Page

redbrad0
Posting Yak Master

176 Posts

Posted - 2005-12-07 : 04:36:44
Well I changed the query from using % to just a direct search and it went from
cpu 140, reads 402, writes 0, duration 140
to
cpu 0, reads 6, writes 0, duration 0

So yes that was a big help... Thanks a ton

Another question is when inserting or searching via dates. Lets say I have the following query
UPDATE Users SET LastLoggedIn = '12/7/2005 3:29:36 AM' WHERE Users_ID = 1
If I type this query into Enterprise Manager then it changes it to this..
UPDATE Users SET LastLoggedIn = CONVERT(DATETIME, '2005-12-07 03:29:36', 102) WHERE Users_ID = 1

Is that the correct way to insert the date? I just want to make sure I am inserting it so SQL Server does not have to convert it to the format that want.

Quality NT Web Hosting & Design
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-07 : 09:21:30
"Is that the correct way to insert the date"

If you need to pass a date/time in "string format" then either use 'yyyymmdd' or 'yyyymmdd hh:mm:ss' or 'yyyy-mm-ddThh:mm:ss'.

SQL Server will NOT treat these ambiguously

Alternatively pass it using a variable of the appropriate date/time datatype in your application language - and then the translation should be done automatically for you.

Kristen
Go to Top of Page
   

- Advertisement -