Imagine two indexes:
idx_1 (urlId, name) idx_2 (urlId) Where urlId is bigint and name is nvarchar(320). And a query which use urlId for filtering and does not affect in any way column name.
- Does second index will improve performance? Will the difference be significant?
- when single column index used instead of compound multiple column index can boost query performance?
I appreciate answers based on examples.
EDIT:
From the answers I've learned that it isn't so simple. It's not 'black and white'. So I change my question a bit. I assume the second one should be a bit faster because it is smaller. But it seems not in all cases. So WHEN there can be no difference in performance and WHY in these situations it happens.
WHEREclause that also includename, then idx_1 is pointless and only wastes space and cycles.namecolumn. Is single column index better or it is irrelevantWITH (INDEX)hint to force it). You also need to test your write workload to see how much more expensive the maintenance becomes relative to how much performance (if any) is gained by the second index for certain queries. I don't think anybody here can tell you whether it is worth having both indexes.