Question

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.

Was it helpful?

Solution

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
  )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top