Question : Improving SQL Server 2005 performance (Database re-vamping help needed)

I have a sql server 2005 database and I am starting to get alot of performance problems lately. I will try to be as accurate in my description as possible

Each table have a primary key (uniqueidentifier, Guid) that is linked to a foreign key in a 1:N relationship.

I have a total of 4 tables and they are defined as follow (I am skipping some properties for clarity).

-Table dbo.Accounts
*pkAccount (primary key)
*Realm (varchar(50))
***Clustered index of pkAccount

1:N relation with the following table

-Table dbo.Characters
*pkCharacter (primary key)
*fkAccount (foreign key to dbo.Accounts table)
*Mode (byte)
***Clustered index on pk_character
***non-clustered index on fkAccount
***non-clustered index of Mode

1:N relationship with the following table:

-Table dbo.Items
*pkItem (primary key)
*fkCharacter(foreign key to table dbo.characters)
*Int1
*Int2
***Clustered index on pkItem
***Non clustered indexes on fkCharacter, int1 and int2

1:N relationship with the following table:

-Table dbo.Stats
*pkStat(primary key)
*fkItem(foreign key to dbo.items table)
*int1
*int2
*int3
***Clustered index on pkStat
***Non clustered indexes on fkItem, int1 and int2

Pretty much all indexes are search criteria except the last table "int3" wich is pretty much optional and while it can be included in some search, 50% of the time it is not.

Each account have ~ 8 characters wich each have ~10 items wich each have ~5-15 stats

After I defrag the indexes the queries run super-fast (there is approximately 1.5 millions records in the items table) and I can return pretty much anything in less than 1 second.

The problem is that as things goes now, we seem to add more and more entries to the database each day and after less than 1 day the queries start to be slow again and I have to re-defrag the indexes every day. After a 24-hour periode a query that normally takes 1 second is taking 10+ (that is 1000% more!).

I am really not a DBA and I when I started this database I knew absolutly nothing about how to design them. With time I figured out adding indexes on key search criteria drastically decreased the search time.

I know someone who helped me alot optimize my query and he had some interesting suggestions to help with performances and I will probably apply them eventually but since it will require re-working alot of the interal parts, it will take alot of time to achieve and I would like some tips that could be applied right away.
Here are his suggestions:
-On the dbo.Accounts table, completly remove realm and make different databases OR replace the realm string with a byte/int/etc. That would make 1 database per different realm (there is a max of 6 realms). Right now the realm is ALWAYS a search criteria.
-Do the same thing as above for the dbo.Characters table and the Mode row, since there is a max of 10 modes, this could also be an option.
That is it for his suggestions, while they are really interesting, I need to improve performances really fast and find a way that I do not have to defrag the indexes every day (about 50% of the indexes get a 90%+ fragmentation after 1day, and the other 50% of the indexes get about 50% fragmentation).

Thank you for reading my post. I don't know if I provided enough information so if I missed to include something just ask and I will be happy to provide more information.

Answer : Improving SQL Server 2005 performance (Database re-vamping help needed)

as you pointed out earlier your query gets about 200 times worse within 24 hours so you should expect that every second gained when testing after all indexes have been rebuilt will give you about 3 minutes of difference next day.

Another thing I thought about is ordering. Try removing it tomorrow for testing only.
Fragmented indexes will cause ordering last forever.
Random Solutions  
 
programming4us programming4us