Efficient Searching

  • 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

  • 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

  • No reason to store it twice. It was included in the index only because it seemed faster.

  • 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[/url]
    Before posting a performance problem please read[/url]

  • 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

  • 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

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply