Things I've tried so far:
After reading Postgres sometimes uses inferior index for WHERE a IN (…) ORDER BY b LIMIT N I have checked
n_distinct
- but is not that far off, pg_stats says623
whileSELECT COUNT(*) FROM (SELECT DISTINCT function FROM "functionCall")
returns1065
.I've increased the table
SET STATISTICS
to 10k and ranANALYZE
. That cuts the time in half (9s) but still won't use the index I created.
Why is this? And how can I fix this?
I've checked https://dba.stackexchange.com/a/249676/106982 but n_distinct is not that far off, pg_stats says n_distinct: 623
while SELECT COUNT(*) FROM (SELECT DISTINCT function FROM "functionCall")
returns 1065