Skip to content

Commit 6efca23

Browse files
committed
Add regression tests exercising the non-hashed code paths in nodeSetop.c.
Perusal of the code coverage report shows that the existing regression test cases for INTERSECT and EXCEPT seemingly all prefer the SETOP_HASHED implementation. Add some test cases in which we force use of the SETOP_SORTED mode.
1 parent ee844bb commit 6efca23

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

src/test/regress/expected/union.out

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,96 @@ ERROR: FOR NO KEY UPDATE is not allowed with UNION/INTERSECT/EXCEPT
345345
1 | 2 | 3
346346
(1 row)
347347

348+
-- exercise both hashed and sorted implementations of INTERSECT/EXCEPT
349+
set enable_hashagg to on;
350+
explain (costs off)
351+
select count(*) from
352+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
353+
QUERY PLAN
354+
------------------------------------------------------------------------------------
355+
Aggregate
356+
-> Subquery Scan on ss
357+
-> HashSetOp Intersect
358+
-> Append
359+
-> Subquery Scan on "*SELECT* 2"
360+
-> Seq Scan on tenk1
361+
-> Subquery Scan on "*SELECT* 1"
362+
-> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1
363+
(8 rows)
364+
365+
select count(*) from
366+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
367+
count
368+
-------
369+
5000
370+
(1 row)
371+
372+
explain (costs off)
373+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
374+
QUERY PLAN
375+
------------------------------------------------------------------------
376+
HashSetOp Except
377+
-> Append
378+
-> Subquery Scan on "*SELECT* 1"
379+
-> Index Only Scan using tenk1_unique1 on tenk1
380+
-> Subquery Scan on "*SELECT* 2"
381+
-> Index Only Scan using tenk1_unique2 on tenk1 tenk1_1
382+
Filter: (unique2 <> 10)
383+
(7 rows)
384+
385+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
386+
unique1
387+
---------
388+
10
389+
(1 row)
390+
391+
set enable_hashagg to off;
392+
explain (costs off)
393+
select count(*) from
394+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
395+
QUERY PLAN
396+
------------------------------------------------------------------------------------------
397+
Aggregate
398+
-> Subquery Scan on ss
399+
-> SetOp Intersect
400+
-> Sort
401+
Sort Key: "*SELECT* 2".fivethous
402+
-> Append
403+
-> Subquery Scan on "*SELECT* 2"
404+
-> Seq Scan on tenk1
405+
-> Subquery Scan on "*SELECT* 1"
406+
-> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1
407+
(10 rows)
408+
409+
select count(*) from
410+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
411+
count
412+
-------
413+
5000
414+
(1 row)
415+
416+
explain (costs off)
417+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
418+
QUERY PLAN
419+
------------------------------------------------------------------------------
420+
SetOp Except
421+
-> Sort
422+
Sort Key: "*SELECT* 1".unique1
423+
-> Append
424+
-> Subquery Scan on "*SELECT* 1"
425+
-> Index Only Scan using tenk1_unique1 on tenk1
426+
-> Subquery Scan on "*SELECT* 2"
427+
-> Index Only Scan using tenk1_unique2 on tenk1 tenk1_1
428+
Filter: (unique2 <> 10)
429+
(9 rows)
430+
431+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
432+
unique1
433+
---------
434+
10
435+
(1 row)
436+
437+
reset enable_hashagg;
348438
--
349439
-- Mixed types
350440
--

src/test/regress/sql/union.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@ SELECT q1 FROM int8_tbl EXCEPT ALL SELECT q1 FROM int8_tbl FOR NO KEY UPDATE;
118118
(SELECT 1,2,3 UNION SELECT 4,5,6) EXCEPT SELECT 4,5,6;
119119
(SELECT 1,2,3 UNION SELECT 4,5,6 ORDER BY 1,2) EXCEPT SELECT 4,5,6;
120120

121+
-- exercise both hashed and sorted implementations of INTERSECT/EXCEPT
122+
123+
set enable_hashagg to on;
124+
125+
explain (costs off)
126+
select count(*) from
127+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
128+
select count(*) from
129+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
130+
131+
explain (costs off)
132+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
133+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
134+
135+
set enable_hashagg to off;
136+
137+
explain (costs off)
138+
select count(*) from
139+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
140+
select count(*) from
141+
( select unique1 from tenk1 intersect select fivethous from tenk1 ) ss;
142+
143+
explain (costs off)
144+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
145+
select unique1 from tenk1 except select unique2 from tenk1 where unique2 != 10;
146+
147+
reset enable_hashagg;
148+
121149
--
122150
-- Mixed types
123151
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy