Pergunta

How to measure selectivity for composite index. I know how to measure selectivity of a single column for a index. But if I want to use multiple columns to create composite index, how do I measure the selectivity in order to decide.

Foi útil?

Solução

If, by "selectivity for composite index", you mean, how many rows, on average, will be returned when I specify values for Col1, Col2, ... ColN, then you can calculate that with:

SELECT COUNT(*) / SUM(C) FROM 
  (
    SELECT COL1, COL2, ... COLN, COUNT(*) C
    FROM TABLE
    GROUP BY COL1, COL2, ... COLN
  )
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top