Best way to get distinct values from large table

Posted by derivation on Stack Overflow See other posts from Stack Overflow or by derivation
Published on 2010-04-21T18:16:19Z Indexed on 2010/04/21 18:23 UTC
Read the original article Hit count: 141

Filed under:
|

I have a db table with about 10 or so columns, two of which are month and year. The table has about 250k rows now, and we expect it to grow by about 100-150k records a month. A lot of queries involve the month and year column (ex, all records from march 2010), and so we frequently need to get the available month and year combinations (ie do we have records for april 2010?).

A coworker thinks that we should have a separate table from our main one that only contains the months and years we have data for. We only add records to our main table once a month, so it would just be a small update on the end of our scripts to add the new entry to this second table. This second table would be queried whenever we need to find the available month/year entries on the first table. This solution feels kludgy to me and a violation of DRY.

What do you think is the correct way of solving this problem? Is there a better way than having two tables?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about Performance