diff options
| author | Tom Lane | 2007-03-21 22:18:12 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-03-21 22:18:12 +0000 |
| commit | 54d20024c1dad339acc8624d7ca902b762fe0844 (patch) | |
| tree | 107270059759b4e114b661838d896da4f4df8ada /src/test | |
| parent | 2b49e5d3cb8b6a71797969c50f5c247f232de989 (diff) | |
Fix some problems with selectivity estimation for partial indexes.
First, genericcostestimate() was being way too liberal about including
partial-index conditions in its selectivity estimate, resulting in
substantial underestimates for situations such as an indexqual "x = 42"
used with an index on x "WHERE x >= 40 AND x < 50". While the code is
intentionally set up to favor selecting partial indexes when available,
this was too much...
Second, choose_bitmap_and() was likewise easily fooled by cases of this
type, since it would similarly think that the partial index had selectivity
independent of the indexqual.
Fixed by using predicate_implied_by() rather than simple equality checks
to determine redundancy. This is a good deal more expensive but I don't
see much alternative. At least the extra cost is only paid when there's
actually a partial index under consideration.
Per report from Jeff Davis. I'm not going to risk back-patching this,
though.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/select.out | 9 | ||||
| -rw-r--r-- | src/test/regress/sql/select.sql | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/test/regress/expected/select.out b/src/test/regress/expected/select.out index 0b3f546bdfb..d58c8d2811b 100644 --- a/src/test/regress/expected/select.out +++ b/src/test/regress/expected/select.out @@ -209,9 +209,13 @@ SELECT onek.unique1, onek.string4 FROM onek -- test partial btree indexes -- -- As of 7.2, planner probably won't pick an indexscan without stats, --- so ANALYZE first. +-- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan +-- followed by sort, because that could hide index ordering problems. -- ANALYZE onek2; +SET enable_seqscan TO off; +SET enable_bitmapscan TO off; +SET enable_sort TO off; -- -- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 -- @@ -288,6 +292,9 @@ SELECT onek2.unique1, onek2.stringu1 FROM onek2 999 | LMAAAA (19 rows) +RESET enable_seqscan; +RESET enable_bitmapscan; +RESET enable_sort; SELECT two, stringu1, ten, string4 INTO TABLE tmp FROM onek; diff --git a/src/test/regress/sql/select.sql b/src/test/regress/sql/select.sql index f23cccd24f9..8c92168c9b8 100644 --- a/src/test/regress/sql/select.sql +++ b/src/test/regress/sql/select.sql @@ -59,10 +59,15 @@ SELECT onek.unique1, onek.string4 FROM onek -- test partial btree indexes -- -- As of 7.2, planner probably won't pick an indexscan without stats, --- so ANALYZE first. +-- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan +-- followed by sort, because that could hide index ordering problems. -- ANALYZE onek2; +SET enable_seqscan TO off; +SET enable_bitmapscan TO off; +SET enable_sort TO off; + -- -- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 -- @@ -81,6 +86,10 @@ SELECT onek2.unique1, onek2.stringu1 FROM onek2 SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 > 980; +RESET enable_seqscan; +RESET enable_bitmapscan; +RESET enable_sort; + SELECT two, stringu1, ten, string4 INTO TABLE tmp |
