Question

There is a user table which has 10 million records, following is the schema of the table user (user_id, user_name, first_name, last_name, address)

when following select is run on the above table it takes 18 minutes to run the query and the entire database slows down during this time.

select * from user where user_id=1000 and username='test';

how do we speed up the select and/or improve database performance in this case?

Was it helpful?

Solution

here are some tips for you,

1.Add index on userid and username (grouped index) if userid is not unique/primary key that will improve performance for sure

2.if possible make userid autogenerated and primary key,if you do that your query will reduce to

"select * from user where user_id=1000" which will faster with single index (userid which is default as its a primary key) and that will save space compared to grouped index

3.basic rule for perfomance improvement, always fetch required columns only (select * from is worst always)

do not forget to run runstats and reorg after index creation

clustered index mentioned above will also help but more space is required for clustered index.(why waste more space if your query could be improved or reduced in your case)

hope this helps..

OTHER TIPS

Make sure you have a clustered index on user_id, and a non_clustered index on 'test'.

Guaranteed performance boost of 10,000%

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top