سؤال

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.

هل كانت مفيدة؟

المحلول

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
  )
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top