Lets say I have a table with columns a and b. I want to do a query like SELECT count(distinct b) WHERE a = 2; Should I have an index on a or an index on (a,b)? -- Joseph Shraibman jks@selectacast.net Increase signal to noise ratio. http://www.targabot.com
Joseph Shraibman <jks@selectacast.net> writes:
> Lets say I have a table with columns a and b. I want to do a query like
> SELECT count(distinct b) WHERE a = 2;
> Should I have an index on a or an index on (a,b)?
At present, only an index on a will help any. Our implementation of
count(distinct ...) isn't bright enough to make use of indexes.
Now an index on (a,b) can substitute for an index on a, so if you
have other queries that could use both columns of the (a,b) index
then it might be worth making that instead of an index on a.
regards, tom lane
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера