Hello. I have a table of 2'500'000 tuples and 100'000 pages, and an index on non-unique field, to each key value corresponds approximately 50'000 tuples.
Due to the updating algorithm the physical order of tuples in the table happens to be such that all equal keys are placed together, but not ordered globally. Correlation computed by "VACUUM ANALYZE" is 0.15. When computing indexscan cost for query with clause "key = ?" the planner makes it closer to "Mackert and Lohman formula" value than to "selectivity * pages". As a result it chooses seqscan rather than indexscan while in fact indexscan is 20 times faster. The question is, which is the best way to correct this behavior? Maybe "VACUUM ANALYZE" could calculate some average of "field correlation per page" and even use this value somewhere inside (not outside) "Mackert and Lohman formula"? Are there any better ideas? ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org