@@ -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--
0 commit comments