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

Efficient Searching Expand / Collapse
Author
Message
Posted Wednesday, November 11, 2009 12:30 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, June 29, 2010 1:08 PM
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
Post #817391
Posted Wednesday, November 11, 2009 12:47 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
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
Post #817407
Posted Wednesday, November 11, 2009 12:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, June 29, 2010 1:08 PM
Points: 4, Visits: 12
No reason to store it twice. It was included in the index only because it seemed faster.
Post #817415
Posted Wednesday, November 11, 2009 1:10 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:55 PM
Points: 5,333, Visits: 25,266
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
Post #817416
Posted Wednesday, November 11, 2009 1:13 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, November 4, 2012 12:23 PM
Points: 1,893, Visits: 3,932
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
Post #817419
Posted Wednesday, November 11, 2009 1:17 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
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
Post #817421
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse