timo2oo8
timo2oo8

Reputation: 176

Increasing performance with setting indices on fields used in a group by clause?

I create a view with many joins. I want to group the resultset by some of the fields I selected.

Does setting indices on these fields increases the performance of the query? I'm using MS SQL Server, but it should be nearly the same for all dbs, shouldn't it?

SELECT table1.field1, table1.field2, table2.field1
FROM table1
INNER JOIN table2 ON table1.primkey = table2.tablekey
GROUP BY table1.field1, table1.field2, table2.field1

Upvotes: 1

Views: 172

Answers (1)

Fenton
Fenton

Reputation: 250922

If you run a query with "Show Execution Plan" switched on, you can ask MS SQL server to suggest indices. It will indicate potential optimising indices to you by creating a hypothetical index on a column it thinks is holding things up and comparing that against your query.

Upvotes: 2

Related Questions