Pergunta

I have a table with format below. And I also know the most common used sql on it, so my question is how to create index on my table thus this sql query can have best performance. Btw, my db is sybase ASE 12.5.

Table t: bu, name, date, score_a, score_b

SQL:

SELECT bu, name, max(score_a), max(score_b)
FROM
t
WHERE date > '20110101' AND date < '20110901'
GROUP BY bu, name

Thanks for any suggestions.

Foi útil?

Solução

Basically you need to add indexes to fields used by WHERE and GROUP BY clause, so I'd go with code, bu and name. How to create an index:
CREATE INDEX index_name ON table_name (column_name);
In your case:
CREATE INDEX idate ON t (date);

Outras dicas

The index on Date suggested by Matino will make sure Sybase only hit rows contributing to the result. As all fields from each row is used in the query, any other indexes won't help. The only way to speed up the query some more would be to include all columns in the date index. But that would normally be overkill!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top