diff options
| author | Tom Lane | 2011-11-09 02:14:21 +0000 |
|---|---|---|
| committer | Tom Lane | 2011-11-09 02:14:21 +0000 |
| commit | 57664ed25e5dea117158a2e663c29e60b3546e1c (patch) | |
| tree | fa7d1fb4b6fae1fa81452ac7bb1f58042b26c9c9 /src/test | |
| parent | 3b8161723c645853021b57330dd2ea0484ec6131 (diff) | |
Wrap appendrel member outputs in PlaceHolderVars in additional cases.
Add PlaceHolderVar wrappers as needed to make UNION ALL sub-select output
expressions appear non-constant and distinct from each other. This makes
the world safe for add_child_rel_equivalences to do what it does. Before,
it was possible for that function to add identical expressions to different
EquivalenceClasses, which logically should imply merging such ECs, which
would be wrong; or to improperly add a constant to an EquivalenceClass,
drastically changing its behavior. Per report from Teodor Sigaev.
The only currently known consequence of this bug is "MergeAppend child's
targetlist doesn't match MergeAppend" planner failures in 9.1 and later.
I am suspicious that there may be other failure modes that could affect
older release branches; but in the absence of any hard evidence, I'll
refrain from back-patching further than 9.1.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/inherit.out | 58 | ||||
| -rw-r--r-- | src/test/regress/sql/inherit.sql | 31 |
2 files changed, 89 insertions, 0 deletions
diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 0948974d9ad..3e2ab9ac5b8 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -1242,3 +1242,61 @@ NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to table matest1 drop cascades to table matest2 drop cascades to table matest3 +-- +-- Test merge-append for UNION ALL append relations +-- Check handling of duplicated, constant, or volatile targetlist items +-- +set enable_seqscan = off; +set enable_indexscan = on; +set enable_bitmapscan = off; +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT thousand, thousand FROM tenk1 +ORDER BY thousand, tenthous; + QUERY PLAN +----------------------------------------------------------------------- + Result + -> Merge Append + Sort Key: public.tenk1.thousand, public.tenk1.tenthous + -> Index Only Scan using tenk1_thous_tenthous on tenk1 + -> Sort + Sort Key: public.tenk1.thousand, public.tenk1.thousand + -> Index Only Scan using tenk1_thous_tenthous on tenk1 +(7 rows) + +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT 42, 42 FROM tenk1 +ORDER BY thousand, tenthous; + QUERY PLAN +----------------------------------------------------------------------- + Result + -> Merge Append + Sort Key: public.tenk1.thousand, public.tenk1.tenthous + -> Index Only Scan using tenk1_thous_tenthous on tenk1 + -> Sort + Sort Key: (42), (42) + -> Index Only Scan using tenk1_thous_tenthous on tenk1 +(7 rows) + +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT thousand, random()::integer FROM tenk1 +ORDER BY thousand, tenthous; + QUERY PLAN +----------------------------------------------------------------------- + Result + -> Merge Append + Sort Key: public.tenk1.thousand, public.tenk1.tenthous + -> Index Only Scan using tenk1_thous_tenthous on tenk1 + -> Sort + Sort Key: public.tenk1.thousand, ((random())::integer) + -> Index Only Scan using tenk1_thous_tenthous on tenk1 +(7 rows) + +reset enable_seqscan; +reset enable_indexscan; +reset enable_bitmapscan; diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 3087a14b729..6e5a1d1c8ee 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -406,3 +406,34 @@ select * from matest0 order by 1-id; reset enable_seqscan; drop table matest0 cascade; + +-- +-- Test merge-append for UNION ALL append relations +-- Check handling of duplicated, constant, or volatile targetlist items +-- + +set enable_seqscan = off; +set enable_indexscan = on; +set enable_bitmapscan = off; + +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT thousand, thousand FROM tenk1 +ORDER BY thousand, tenthous; + +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT 42, 42 FROM tenk1 +ORDER BY thousand, tenthous; + +explain (costs off) +SELECT thousand, tenthous FROM tenk1 +UNION ALL +SELECT thousand, random()::integer FROM tenk1 +ORDER BY thousand, tenthous; + +reset enable_seqscan; +reset enable_indexscan; +reset enable_bitmapscan; |
