Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to improve performance on a query


how to improve performance on a query

Author
Message
HildaJ
HildaJ
SSC-Enthusiastic
SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)

Group: General Forum Members
Points: 177 Visits: 571
This is the case:

We have an accounting vendor package that is required to run a transaction against a table to search for a particular set of rows. The query is very simple but it takes about 7.30 minutes to run. Apparently, this process needs to run several times a day, therefore it's slowing other users down as soon as it hits the server.

Here are the particulars:
The table: it has 10.5 million records with about 50 columns and only expected to grow about 150,000 records per month.
The query: Select * from tablename where columnname = 'ON' (please don't shoot yet), I'm working on getting their developer team to tell me why they need all the columns and if not which ones are the ones they need.
The filtering column by has only two values ON or OFF and it's a varchar(15).
The primary key on the table is a varchar(15) and it seems to be all integers (don't ask me why they didn't use an integer data type from the beginning, vendor package remember, I know.)

The primary key has a clustered index key
There are four other non-clustered keys present in the table
The filtering column does not have an index key at all.

Also, the server has 2 CPU and 12GB of RAM (9GB are assigned to SQL), running SQL Server 2008 R2
My question is how can we improve this simple query. I tried adding a separate column using bit/integer to filter by this and still is very slow.

Any advise would be very appreciated.

Thank you.
MyDoggieJessie
MyDoggieJessie
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4862 Visits: 7363
If you can, please post the exact query, as well as the index definitions.

Most importantly, please attached the execution plan...

To start, add a non clustered index on the filtered column and see if that helps.

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
HildaJ
HildaJ
SSC-Enthusiastic
SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)

Group: General Forum Members
Points: 177 Visits: 571
The actual select statement is as follows:

Select * from tablename where columnname = 'OFF' (this value is either ON/OFF).

The only index set on the table is on the primary key defined as a clustered index.

I added a non-clustered index to the table and didn't seem to make a difference.
John Mitchell-245523
John Mitchell-245523
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7383 Visits: 15095
An index on a dual-valued column isn't likely to be of much use, unless one of the values occurs significantly less often than the other, and that's the value you search for in your query.

Here are some things that spring to mind that you could try. You'll need to test thoroughly, because even if one of these things improves the performance of the query in question, it might make things worse elsewhere.
* Make sure you're rebuilding your clustered index regularly. This will keep wasted space to a minimum and therefore reduce the IO needed for a clustered index scan
* Review the design of your table so that, for example, "On" and "Off" are stored as char(3) instead of varchar(20). This should mean that more rows can fit on each page, which will also reduce IO
* Consider creating an indexed view that includes the columns you need for your query (once you find out what those columns are)
* Consider creating a covering index consisting of only the columns you need for your query

John
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16542 Visits: 16997
Honestly from what you described the time sounds about as good as it is going to get. Assuming roughly 50% of your rows are "ON" then you are selecting about 5 million rows with 50 columns. 7 1/2 minutes sounds about like what I would expect. Why all columns and what in the world are you doing with 5 million rows?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
HildaJ
HildaJ
SSC-Enthusiastic
SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)

Group: General Forum Members
Points: 177 Visits: 571
Honestly from what you described the time sounds about as good as it is going to get. Assuming roughly 50% of your rows are "ON" then you are selecting about 5 million rows with 50 columns. 7 1/2 minutes sounds about like what I would expect. Why all columns and what in the world are you doing with 5 million rows?


Why all columns?

The SQL statement in question is from a "batch" process that runs against our database during the day, a few times a day, it's a vendor package that runs this statement. We're trying to get the vendor to change this query to only select the columns needed. That on its own it has been a good argument and challenge.

Why 5 millions rows?

It's all the transaction history that we have in our accounting system. After the selection, depending on the results return, there's another set of events that are happening afterwards.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16542 Visits: 16997
HildaJ (4/14/2014)


It's all the transaction history that we have in our accounting system. After the selection, depending on the results return, there's another set of events that are happening afterwards.


Can you change the process so that you don't keep processing rows that have already been processed? If downstream these already processed rows are going to be ignored it would greatly help performance to eliminate them from this query too.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24171 Visits: 37936
I have to ask this question, what is the batch process doing?

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search