My Kingdom for a DBA
January 31, 2007 5:18 PM
Subscribe
Databasefilter: I'm a self-taught 'DBA' (I use quotes so as to not offend those who have this knowledge through a paid education). I'm having an efficiency problem with a few of my tables, and I thought maybe one or two of you could help.
I've got a table that looks like this in SQL 2000:
UnitValue (
dts smalldatetime,
fund_id int,
price decimal(10,4)
)
Here's the problem: For the last 10 years or so, we've been tracking anywhere up to 150 fund values on a daily basis. The table size is now unweildy, and indexes don't seem to help me.
A thought presented itself to me today, but I'm having some trouble figuring on how I'd use it. I thought, perhaps, that I'd structure the table in this manner:
UnitValue (
dts smalldatetime,
fundAname decimal(10,4),
fundBname decimal(10,4),
....
)
...where each column name relates to a particular fund. Then, I'd create indexes for each column relating to a date.
I'm thinking this would greatly reduce the size of my table, and the indexes would do a great deal in reducing query time.
My question is: How do I query against this table? Take, for example, the fact that participants in specific plans that I'm managing could have 1 to X number of funds, so to acquire their total balance for any given day, I have to join against the UnitValue table to find their particular mix of fund values for that day.
I could use "dynamic SQL", I suppose (by building the query programmatically in a large string variable) and then evaluate the SQL code after I've built it up, but wouldn't that offset any performance gains I'm getting from structuring the table in this manner? I was under the assumption that a stored procedure couldn't optimize queries built in such a manner. Besides, coding that way is hell on my inner debugger.
Is there a way to join against the SQL database tables in a generic manner to figure out to which columns I need to pay attention for any given participant?
posted by thanotopsis to computers & internet (20 comments total)
However, there's a similar technique that may help: partitioning the table. Basically the idea is to take your one large table, and split it into several tables. One might hold only dates for 2000, the next for 2001, etc. I wouldn't do this manually unless you have no other choice, but your database may have the ability to transparently do it for you.
But before you do that, let's examine the indices your actually using, and the queries you're actually making. I suspect that we could come up with better indices and speed up your queries significantly.
Please post both the queries you're making, the showplan for them, and the indices on those tables for further assistance.
posted by orthogonality at 5:36 PM on January 31, 2007