Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to improve performance on a query Expand / Collapse
Author
Message
Posted Friday, April 11, 2014 1:50 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 8:29 AM
Points: 163, Visits: 470
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.
Post #1561123
Posted Friday, April 11, 2014 4:10 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 9:31 AM
Points: 3,910, Visits: 7,138
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"
Post #1561143
Posted Monday, April 14, 2014 7:14 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 8:29 AM
Points: 163, Visits: 470
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.

Post #1561462
Posted Monday, April 14, 2014 7:39 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:49 AM
Points: 5,336, Visits: 9,791
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
Post #1561471
Posted Monday, April 14, 2014 8:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, August 29, 2014 2:32 PM
Points: 13,302, Visits: 12,168
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)
Post #1561486
Posted Monday, April 14, 2014 10:15 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 8:29 AM
Points: 163, Visits: 470
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.
Post #1561555
Posted Monday, April 14, 2014 10:21 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, August 29, 2014 2:32 PM
Points: 13,302, Visits: 12,168
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)
Post #1561558
Posted Monday, April 14, 2014 10:37 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 9:04 PM
Points: 23,302, Visits: 32,057
I have to ask this question, what is the batch process doing?



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)
Post #1561571
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse