SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Efficient Searching


Efficient Searching

Author
Message
mjackson-1128654
mjackson-1128654
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 12
We have very large tables of price data that need to be searched efficiently. The table consists of

id - bigint (Primary Key w/ clustered index)
iCurve - bigint - links to a small table defining price curves
dtFwdDate - forward date
dtEffDate - effective date
fValue - price

The usual search is
SELECT fValue FROM table WHERE iCurve = 1 AND dtFwdDate='01/01/2010' AND dtEffDate='11/11/2009'

I created an index that keys on iCurve, dtFwdDate, dtEffDate and includes fValue.

It works okay but the index size is now larger than the data.

We have to update this table daily with very large numbers of data points (100,000+)

Questions -

What is the best way to index this table for fast searches?
How can we keep the index size small?
How can we optimize this so insertions are not painful?

In terms of performance, I would rather have performance problems inserting data.

thx
GSquared
GSquared
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23667 Visits: 9730
Is there a reason to store the data twice? That's what you're doing since you have a clustered index on the ID column, and a non-clustered index on every other column.

Do you really need an ID column on this table? If so, does it really need to be the clustered index key?

The other issue, of the index getting larger than the table, is probably due to fragmentation. You might want to look into that and see if you can reasonably defragment it. Might need to adjust the fill factor to make it do fewer page splits. That's applicable whether it stays as a non-clustered index or becomes the clustered index.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
mjackson-1128654
mjackson-1128654
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 12
No reason to store it twice. It was included in the index only because it seemed faster.
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)

Group: General Forum Members
Points: 7853 Visits: 25280
Suggest you read the articles on indexing written by Gail Shaw the 2nd of which is the featured article today

http://www.sqlservercentral.com/articles/Indexing/68563/

You also might want to spend time looking at these videos on indexing by Kimberly L. Tripp

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032278595

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032278599

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Florian Reischl
Florian Reischl
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3533 Visits: 3934
Hi

If you always query data equal to all three columns you can add a computed column as BINARY_CHECKSUM over all three columns. Put an index only on this column and use it in your SELECT statements combined with your usual columns as:

DECLARE
@checkSum INT
,@fwdDate DATETIME
,@effDate DATETIME
,@curve INT;

SELECT
@fwdDate = '01/01/2010'
,@effDate = '11/11/2009'
,@curve = 1;

SELECT @checkSum = BINARY_CHECKSUM(@fwdDate, @effDate, @curve);

SELECT fValue
FROM yourTable
-- query the checkSum column
WHERE checkSumColumn = @checkSum
AND iCurve = @curve
AND dtFwdDate=@fwdDate
AND dtEffDate=@effDate;



Consider, this only works for equality queries over all columns within the index and ensure that you specify all values of your query in correct data type. If you provide your date values as '01/01/2009', the checksum would be calculated as VARCHAR and you will never get a result.

Greets
Flo


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
GSquared
GSquared
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23667 Visits: 9730
mjackson-1128654 (11/11/2009)
No reason to store it twice. It was included in the index only because it seemed faster.


What I meant was, why not make those columns the clustered index, so you only store the data once? Sorry I wasn't clear enough on that.

Doesn't have anything to do with the include column of the non-clustered index. Has to do with defining the clustered index for best efficiency.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
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