troubleshooting Question

When to use a compound index and how to determine order of fields

Avatar of xersoft
xersoft asked on
Microsoft SQL Server 2005Microsoft SQL Server
10 Comments3 Solutions2026 ViewsLast Modified:
I have  fact table defined in part like this
[id] [int] IDENTITY(1,1) NOT NULL,
[Date] [datetime] NOT NULL, --default GetDate()
[UserID] [int] NOT NULL,

I query this table a lot as you can imagine. In the vast majority of cases I query with a date range and a user id. In most cases I then filter based on other fields in the table but a constant is filtering on date range and the user id.

My question is what would be the best index to place on this table and why?
I could put a single index on both the userID and Date separately.
I could put a compound index on UserID, Date or on Date, UserID

My thought is that Date, UserID would be best.

My reasoning is that since items will be added with the current date in most cases the index shouldn't need to reorder itself as much. If the compound index was on UserID, Date then every time a row was added it would need to insert into the proper users section of the index and then in the proper date range.

Am I thinking about this correctly? Please provide details regarding any advice offered.
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 3 Answers and 10 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 3 Answers and 10 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004