From 9f897722fbcc7d12cd1e2da95a1c6121060859cb Mon Sep 17 00:00:00 2001 From: Sandeep Kumawat Date: Fri, 1 Dec 2023 10:07:09 +0000 Subject: [PATCH] add expected output fil parallel query mode in case of pgr test casres Signed-off-by: Sandeep Kumawat --- .../expected/parallel_query/pgr_select.out | 1047 +++++++++++++++++ .../parallel_query/pgr_select_distinct.out | 632 ++++++++++ .../parallel_query/pgr_select_into.out | 419 +++++++ 3 files changed, 2098 insertions(+) create mode 100644 test/JDBC/expected/parallel_query/pgr_select.out create mode 100644 test/JDBC/expected/parallel_query/pgr_select_distinct.out create mode 100644 test/JDBC/expected/parallel_query/pgr_select_into.out diff --git a/test/JDBC/expected/parallel_query/pgr_select.out b/test/JDBC/expected/parallel_query/pgr_select.out new file mode 100644 index 00000000000..e82ac4f355d --- /dev/null +++ b/test/JDBC/expected/parallel_query/pgr_select.out @@ -0,0 +1,1047 @@ + +-- +-- SELECT +-- +-- btree index +-- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1 +-- +SELECT * FROM onek + WHERE onek.unique1 < 10 + ORDER BY onek.unique1; +GO +~~START~~ +int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#varchar#!#varchar#!#varchar +0#!#998#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#1#!#AAAAAA#!#KMBAAA#!#OOOOxx +1#!#214#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#2#!#3#!#BAAAAA#!#GIAAAA#!#OOOOxx +2#!#326#!#0#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#4#!#5#!#CAAAAA#!#OMAAAA#!#OOOOxx +3#!#431#!#1#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#6#!#7#!#DAAAAA#!#PQAAAA#!#VVVVxx +4#!#833#!#0#!#0#!#4#!#4#!#4#!#4#!#4#!#4#!#4#!#8#!#9#!#EAAAAA#!#BGBAAA#!#HHHHxx +5#!#541#!#1#!#1#!#5#!#5#!#5#!#5#!#5#!#5#!#5#!#10#!#11#!#FAAAAA#!#VUAAAA#!#HHHHxx +6#!#978#!#0#!#2#!#6#!#6#!#6#!#6#!#6#!#6#!#6#!#12#!#13#!#GAAAAA#!#QLBAAA#!#OOOOxx +7#!#647#!#1#!#3#!#7#!#7#!#7#!#7#!#7#!#7#!#7#!#14#!#15#!#HAAAAA#!#XYAAAA#!#VVVVxx +8#!#653#!#0#!#0#!#8#!#8#!#8#!#8#!#8#!#8#!#8#!#16#!#17#!#IAAAAA#!#DZAAAA#!#HHHHxx +9#!#49#!#1#!#1#!#9#!#9#!#9#!#9#!#9#!#9#!#9#!#18#!#19#!#JAAAAA#!#XBAAAA#!#HHHHxx +~~END~~ + + +-- +-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 +-- +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 desc; +GO +~~START~~ +int#!#varchar +19#!#TAAAAA +18#!#SAAAAA +17#!#RAAAAA +16#!#QAAAAA +15#!#PAAAAA +14#!#OAAAAA +13#!#NAAAAA +12#!#MAAAAA +11#!#LAAAAA +10#!#KAAAAA +9#!#JAAAAA +8#!#IAAAAA +7#!#HAAAAA +6#!#GAAAAA +5#!#FAAAAA +4#!#EAAAAA +3#!#DAAAAA +2#!#CAAAAA +1#!#BAAAAA +0#!#AAAAAA +~~END~~ + + +-- +-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 +-- +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 > 980 + ORDER BY stringu1 asc; +GO +~~START~~ +int#!#varchar +988#!#AMAAAA +989#!#BMAAAA +990#!#CMAAAA +991#!#DMAAAA +992#!#EMAAAA +993#!#FMAAAA +994#!#GMAAAA +995#!#HMAAAA +996#!#IMAAAA +997#!#JMAAAA +998#!#KMAAAA +999#!#LMAAAA +981#!#TLAAAA +982#!#ULAAAA +983#!#VLAAAA +984#!#WLAAAA +985#!#XLAAAA +986#!#YLAAAA +987#!#ZLAAAA +~~END~~ + + +-- +-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | +-- sort +1d -2 +0nr -1 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 asc, unique1 desc; +GO +~~START~~ +int#!#varchar +999#!#AAAAxx +995#!#AAAAxx +983#!#AAAAxx +982#!#AAAAxx +981#!#AAAAxx +998#!#HHHHxx +997#!#HHHHxx +993#!#HHHHxx +990#!#HHHHxx +986#!#HHHHxx +996#!#OOOOxx +991#!#OOOOxx +988#!#OOOOxx +987#!#OOOOxx +985#!#OOOOxx +994#!#VVVVxx +992#!#VVVVxx +989#!#VVVVxx +984#!#VVVVxx +~~END~~ + + +-- +-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | +-- sort +1dr -2 +0n -1 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 desc, unique1 asc; +GO +~~START~~ +int#!#varchar +984#!#VVVVxx +989#!#VVVVxx +992#!#VVVVxx +994#!#VVVVxx +985#!#OOOOxx +987#!#OOOOxx +988#!#OOOOxx +991#!#OOOOxx +996#!#OOOOxx +986#!#HHHHxx +990#!#HHHHxx +993#!#HHHHxx +997#!#HHHHxx +998#!#HHHHxx +981#!#AAAAxx +982#!#AAAAxx +983#!#AAAAxx +995#!#AAAAxx +999#!#AAAAxx +~~END~~ + + +-- +-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | +-- sort +0nr -1 +1d -2 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 desc, string4 asc; +GO +~~START~~ +int#!#varchar +19#!#OOOOxx +18#!#VVVVxx +17#!#HHHHxx +16#!#OOOOxx +15#!#VVVVxx +14#!#AAAAxx +13#!#OOOOxx +12#!#AAAAxx +11#!#OOOOxx +10#!#AAAAxx +9#!#HHHHxx +8#!#HHHHxx +7#!#VVVVxx +6#!#OOOOxx +5#!#HHHHxx +4#!#HHHHxx +3#!#VVVVxx +2#!#OOOOxx +1#!#OOOOxx +0#!#OOOOxx +~~END~~ + + +-- +-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | +-- sort +0n -1 +1dr -2 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 asc, string4 desc; +GO +~~START~~ +int#!#varchar +0#!#OOOOxx +1#!#OOOOxx +2#!#OOOOxx +3#!#VVVVxx +4#!#HHHHxx +5#!#HHHHxx +6#!#OOOOxx +7#!#VVVVxx +8#!#HHHHxx +9#!#HHHHxx +10#!#AAAAxx +11#!#OOOOxx +12#!#AAAAxx +13#!#OOOOxx +14#!#AAAAxx +15#!#VVVVxx +16#!#OOOOxx +17#!#HHHHxx +18#!#VVVVxx +19#!#OOOOxx +~~END~~ + + +-- psql +-- +-- test partial btree indexes +-- +-- As of 7.2, planner probably won't pick an indexscan without stats, +-- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan +-- followed by sort, because that could hide index ordering problems. +-- +ANALYZE master_dbo.onek2; +GO + +-- tsql +select set_config('enable_seqscan', 'off', false); +GO +~~START~~ +text +off +~~END~~ + +select set_config('enable_bitmapscan', 'off', false); +GO +~~START~~ +text +off +~~END~~ + +select set_config('enable_sort', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +-- +-- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 +-- +-- ORDER IS DIFFERENT compared with orginal regression test +SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10; +GO +~~START~~ +int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#int#!#varchar#!#varchar#!#varchar +9#!#49#!#1#!#1#!#9#!#9#!#9#!#9#!#9#!#9#!#9#!#18#!#19#!#JAAAAA#!#XBAAAA#!#HHHHxx +1#!#214#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#2#!#3#!#BAAAAA#!#GIAAAA#!#OOOOxx +2#!#326#!#0#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#4#!#5#!#CAAAAA#!#OMAAAA#!#OOOOxx +3#!#431#!#1#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#3#!#6#!#7#!#DAAAAA#!#PQAAAA#!#VVVVxx +5#!#541#!#1#!#1#!#5#!#5#!#5#!#5#!#5#!#5#!#5#!#10#!#11#!#FAAAAA#!#VUAAAA#!#HHHHxx +7#!#647#!#1#!#3#!#7#!#7#!#7#!#7#!#7#!#7#!#7#!#14#!#15#!#HAAAAA#!#XYAAAA#!#VVVVxx +8#!#653#!#0#!#0#!#8#!#8#!#8#!#8#!#8#!#8#!#8#!#16#!#17#!#IAAAAA#!#DZAAAA#!#HHHHxx +4#!#833#!#0#!#0#!#4#!#4#!#4#!#4#!#4#!#4#!#4#!#8#!#9#!#EAAAAA#!#BGBAAA#!#HHHHxx +6#!#978#!#0#!#2#!#6#!#6#!#6#!#6#!#6#!#6#!#6#!#12#!#13#!#GAAAAA#!#QLBAAA#!#OOOOxx +0#!#998#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#0#!#1#!#AAAAAA#!#KMBAAA#!#OOOOxx +~~END~~ + + +-- +-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 +-- +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 < 20 + ORDER BY unique1 desc; +GO +~~START~~ +int#!#varchar +19#!#TAAAAA +18#!#SAAAAA +17#!#RAAAAA +16#!#QAAAAA +15#!#PAAAAA +14#!#OAAAAA +13#!#NAAAAA +12#!#MAAAAA +11#!#LAAAAA +10#!#KAAAAA +9#!#JAAAAA +8#!#IAAAAA +7#!#HAAAAA +6#!#GAAAAA +5#!#FAAAAA +4#!#EAAAAA +3#!#DAAAAA +2#!#CAAAAA +1#!#BAAAAA +0#!#AAAAAA +~~END~~ + + +-- +-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 +-- +-- ORDER IS DIFFERENT compared with orginal regression test +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 > 980; +GO +~~START~~ +int#!#varchar +997#!#JMAAAA +995#!#HMAAAA +999#!#LMAAAA +983#!#VLAAAA +989#!#BMAAAA +986#!#YLAAAA +996#!#IMAAAA +982#!#ULAAAA +992#!#EMAAAA +990#!#CMAAAA +991#!#DMAAAA +984#!#WLAAAA +981#!#TLAAAA +998#!#KMAAAA +993#!#FMAAAA +994#!#GMAAAA +988#!#AMAAAA +987#!#ZLAAAA +985#!#XLAAAA +~~END~~ + + +-- RESET enable_seqscan; +-- RESET enable_bitmapscan; +-- RESET enable_sort; +select set_config('enable_seqscan', 'on', false); +GO +~~START~~ +text +on +~~END~~ + +select set_config('enable_bitmapscan', 'on', false); +GO +~~START~~ +text +on +~~END~~ + +select set_config('enable_sort', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +-- psql +-- +-- awk '{print $1,$2;}' person.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data | +-- awk 'BEGIN{FS=" ";}{if(NF!=2){print $4,$5;}else{print;}}' - stud_emp.data +-- +-- SELECT name, age FROM person*; ??? check if different +-- MISSING LAST 8 ROWS compared with orginal regression test +SELECT p.name, p.age FROM master_dbo.person* p; +GO +~~START~~ +"sys"."varchar"#!#int4 +mike#!#40 +joe#!#20 +sally#!#34 +sandra#!#19 +alex#!#30 +sue#!#50 +denise#!#24 +sarah#!#88 +teresa#!#38 +nan#!#28 +leah#!#68 +wendy#!#78 +melissa#!#28 +joan#!#18 +mary#!#8 +jane#!#58 +liza#!#38 +jean#!#28 +jenifer#!#38 +juanita#!#58 +susan#!#78 +zena#!#98 +martie#!#88 +chris#!#78 +pat#!#18 +zola#!#58 +louise#!#98 +edna#!#18 +bertha#!#88 +sumi#!#38 +koko#!#88 +gina#!#18 +rean#!#48 +sharon#!#78 +paula#!#68 +julie#!#68 +belinda#!#38 +karen#!#48 +carina#!#58 +diane#!#18 +esther#!#98 +trudy#!#88 +fanny#!#8 +carmen#!#78 +lita#!#25 +pamela#!#48 +sandy#!#38 +trisha#!#88 +uma#!#78 +velma#!#68 +~~END~~ + + +-- +-- awk '{print $1,$2;}' person.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data | +-- awk 'BEGIN{FS=" ";}{if(NF!=1){print $4,$5;}else{print;}}' - stud_emp.data | +-- sort +1nr -2 +-- +SELECT p.name, p.age FROM master_dbo.person* p ORDER BY age desc, name; +GO +~~START~~ +"sys"."varchar"#!#int4 +esther#!#98 +louise#!#98 +zena#!#98 +bertha#!#88 +koko#!#88 +martie#!#88 +sarah#!#88 +trisha#!#88 +trudy#!#88 +carmen#!#78 +chris#!#78 +sharon#!#78 +susan#!#78 +uma#!#78 +wendy#!#78 +julie#!#68 +leah#!#68 +paula#!#68 +velma#!#68 +carina#!#58 +jane#!#58 +juanita#!#58 +zola#!#58 +sue#!#50 +karen#!#48 +pamela#!#48 +rean#!#48 +mike#!#40 +belinda#!#38 +jenifer#!#38 +liza#!#38 +sandy#!#38 +sumi#!#38 +teresa#!#38 +sally#!#34 +alex#!#30 +jean#!#28 +melissa#!#28 +nan#!#28 +lita#!#25 +denise#!#24 +joe#!#20 +sandra#!#19 +diane#!#18 +edna#!#18 +gina#!#18 +joan#!#18 +pat#!#18 +fanny#!#8 +mary#!#8 +~~END~~ + + +-- psql +-- +-- Test some cases involving whole-row Var referencing a subquery +-- +select foo from (select 1 offset 0) as foo; +GO +~~START~~ +record +(1) +~~END~~ + +select foo from (select null offset 0) as foo; +GO +~~START~~ +record +() +~~END~~ + +select foo from (select 'xyzzy',1,null offset 0) as foo; +GO +~~START~~ +record +(xyzzy,1,) +~~END~~ + + +-- +-- Test VALUES lists +-- +select * from master_dbo.onek, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) + WHERE master_dbo.onek.unique1 = v.i and master_dbo.onek.stringu1 = v.j; +GO +~~START~~ +int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#name#!#name#!#name#!#int4#!#text +~~END~~ + +-- a more complex case +-- looks like we're coding lisp :-) +select * from master_dbo.onek, + (values ((select i from + (values(10000), (2), (389), (1000), (2000), ((select 10029))) as foo(i) + order by i asc limit 1))) bar (i) + where master_dbo.onek.unique1 = bar.i; +GO +~~START~~ +int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#name#!#name#!#name#!#int4 +2#!#326#!#0#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#2#!#4#!#5#!#CAAAAA#!#OMAAAA#!#OOOOxx#!#2 +~~END~~ + +-- try VALUES in a subquery +select * from master_dbo.onek + where (unique1,ten) in (values (1,1), (20,0), (99,9), (17,99)) + order by unique1; +GO +~~START~~ +int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#name#!#name#!#name +1#!#214#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#1#!#2#!#3#!#BAAAAA#!#GIAAAA#!#OOOOxx +20#!#306#!#0#!#0#!#0#!#0#!#0#!#20#!#20#!#20#!#20#!#0#!#1#!#UAAAAA#!#ULAAAA#!#OOOOxx +99#!#101#!#1#!#3#!#9#!#19#!#9#!#99#!#99#!#99#!#99#!#18#!#19#!#VDAAAA#!#XDAAAA#!#HHHHxx +~~END~~ + +-- VALUES is also legal as a standalone query or a set-operation member +VALUES (1,2), (3,4+4), (7,77.7); +GO +~~START~~ +int4#!#numeric +1#!#2 +3#!#8 +7#!#77.7 +~~END~~ + + +VALUES (1,2), (3,4+4), (7,77.7) +UNION ALL +SELECT 2+2, 57 +UNION ALL +TABLE master_dbo.int8_tbl; +GO +~~START~~ +int8#!#numeric +1#!#2 +3#!#8 +7#!#77.7 +4#!#57 +123#!#456 +123#!#4567890123456789 +4567890123456789#!#123 +4567890123456789#!#4567890123456789 +4567890123456789#!#-4567890123456789 +~~END~~ + + +-- corner case: VALUES with no columns +CREATE TEMP TABLE nocols(); +GO +INSERT INTO nocols DEFAULT VALUES; +GO +~~ROW COUNT: 1~~ + +SELECT * FROM nocols n, LATERAL (VALUES(n.*)) v; +GO +~~START~~ + + +~~END~~ + + +-- tsql +-- +-- Test ORDER BY options +-- +CREATE TABLE #foo (f1 int); +GO + +INSERT INTO #foo VALUES (42),(3),(10),(7),(null),(null),(1); +GO +~~ROW COUNT: 7~~ + + +SELECT * FROM #foo ORDER BY f1; +GO +~~START~~ +int + + +1 +3 +7 +10 +42 +~~END~~ + +SELECT * FROM #foo ORDER BY f1 ASC; -- same thing +GO +~~START~~ +int + + +1 +3 +7 +10 +42 +~~END~~ + +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- GO +SELECT * FROM #foo ORDER BY f1 DESC; +GO +~~START~~ +int +42 +10 +7 +3 +1 + + +~~END~~ + + +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- GO +-- check if indexscans do the right things +CREATE INDEX fooi ON #foo (f1); +GO +select set_config('enable_sort', 'false', false); +GO +~~START~~ +text +off +~~END~~ + + +SELECT * FROM #foo ORDER BY f1; +GO +~~START~~ +int + + +1 +3 +7 +10 +42 +~~END~~ + +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- GO +SELECT * FROM #foo ORDER BY f1 DESC; +GO +~~START~~ +int +42 +10 +7 +3 +1 + + +~~END~~ + + +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- GO +DROP INDEX fooi ON #foo; +GO +CREATE INDEX fooi ON #foo (f1 DESC); +GO + +SELECT * FROM #foo ORDER BY f1; +GO +~~START~~ +int + + +1 +3 +7 +10 +42 +~~END~~ + +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- GO +SELECT * FROM #foo ORDER BY f1 DESC; +GO +~~START~~ +int +42 +10 +7 +3 +1 + + +~~END~~ + + +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- GO +DROP INDEX fooi ON #foo; +GO +-- CREATE INDEX fooi ON foo (f1 DESC NULLS LAST); +GO + +SELECT * FROM #foo ORDER BY f1; +GO +~~START~~ +int + + +1 +3 +7 +10 +42 +~~END~~ + +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- GO +SELECT * FROM #foo ORDER BY f1 DESC; +GO +~~START~~ +int +42 +10 +7 +3 +1 + + +~~END~~ + + + +-- psql +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- GO +-- +-- Test planning of some cases with partial indexes +-- +-- partial index is usable +explain (costs off) +select * from master_dbo.onek2 where unique2 = 11 and stringu1 = 'ATAAAA' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((unique2 = 11) AND (stringu1 = 'ATAAAA'::name)) +~~END~~ + +select * from master_dbo.onek2 where unique2 = 11 and stringu1 = 'ATAAAA' COLLATE "C"; +GO +~~START~~ +int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#name#!#name#!#name +494#!#11#!#0#!#2#!#4#!#14#!#4#!#94#!#94#!#494#!#494#!#8#!#9#!#ATAAAA#!#LAAAAA#!#VVVVxx +~~END~~ + +-- actually run the query with an analyze to use the partial index +explain (costs off, analyze on, timing off, summary off) +select * from master_dbo.onek2 where unique2 = 11 and stringu1 = 'ATAAAA' COLLATE "C"; +GO +~~START~~ +text +Gather (actual rows=1 loops=1) + Workers Planned: 4 + Workers Launched: 4 + -> Parallel Seq Scan on onek2 (actual rows=0 loops=5) + Filter: ((unique2 = 11) AND (stringu1 = 'ATAAAA'::name)) + Rows Removed by Filter: 200 +~~END~~ + +explain (costs off) +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 = 'ATAAAA' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((unique2 = 11) AND (stringu1 = 'ATAAAA'::name)) +~~END~~ + +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 = 'ATAAAA' COLLATE "C"; +GO +~~START~~ +int4 +11 +~~END~~ + +-- partial index predicate implies clause, so no need for retest +explain (costs off) +select * from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((stringu1 < 'B'::name) AND (unique2 = 11)) +~~END~~ + +select * from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#int4#!#name#!#name#!#name +494#!#11#!#0#!#2#!#4#!#14#!#4#!#94#!#94#!#494#!#494#!#8#!#9#!#ATAAAA#!#LAAAAA#!#VVVVxx +~~END~~ + +explain (costs off) +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((stringu1 < 'B'::name) AND (unique2 = 11)) +~~END~~ + +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +int4 +11 +~~END~~ + +-- but if it's an update target, must retest anyway +explain (costs off) +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C" for update; +GO +~~START~~ +text +LockRows + -> Seq Scan on onek2 + Filter: ((stringu1 < 'B'::name) AND (unique2 = 11)) +~~END~~ + +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C" for update; +GO +~~START~~ +int4 +11 +~~END~~ + +-- partial index is not applicable +explain (costs off) +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'C' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((stringu1 < 'C'::name) AND (unique2 = 11)) +~~END~~ + +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'C' COLLATE "C"; +GO +~~START~~ +int4 +11 +~~END~~ + +-- partial index implies clause, but bitmap scan must recheck predicate anyway +SET enable_indexscan TO off; +GO +explain (costs off) +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((stringu1 < 'B'::name) AND (unique2 = 11)) +~~END~~ + +select unique2 from master_dbo.onek2 where unique2 = 11 and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +int4 +11 +~~END~~ + +RESET enable_indexscan; +GO +-- check multi-index cases too +explain (costs off) +select unique1, unique2 from master_dbo.onek2 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: ((stringu1 < 'B'::name) AND ((unique2 = 11) OR (unique1 = 0))) +~~END~~ + +select unique1, unique2 from master_dbo.onek2 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B' COLLATE "C"; +GO +~~START~~ +int4#!#int4 +494#!#11 +0#!#998 +~~END~~ + +explain (costs off) +select unique1, unique2 from master_dbo.onek2 + where (unique2 = 11 and stringu1 < 'B' COLLATE "C") or unique1 = 0; +GO +~~START~~ +text +Gather + Workers Planned: 4 + -> Parallel Seq Scan on onek2 + Filter: (((unique2 = 11) AND (stringu1 < 'B'::name)) OR (unique1 = 0)) +~~END~~ + +select unique1, unique2 from master_dbo.onek2 + where (unique2 = 11 and stringu1 < 'B' COLLATE "C") or unique1 = 0; +GO +~~START~~ +int4#!#int4 +494#!#11 +0#!#998 +~~END~~ + + + +-- +-- Test some corner cases that have been known to confuse the planner +-- +-- ORDER BY on a constant doesn't really need any sorting +SELECT 1 AS x ORDER BY x; +GO +~~START~~ +int4 +1 +~~END~~ + + +-- But ORDER BY on a set-valued expression does +create function sillysrf(int) returns setof int as + 'values (1),(10),(2),($1)' language sql immutable; +GO + +select sillysrf(42); +GO +~~START~~ +int4 +1 +10 +2 +42 +~~END~~ + +select sillysrf(-1) order by 1; +GO +~~START~~ +int4 +-1 +1 +2 +10 +~~END~~ + + +drop function sillysrf(int); +GO + +-- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict +-- (see bug #5084) +select * from (values (2),(null),(1)) v(k) where k = k order by k; +GO +~~START~~ +int4 +1 +2 +~~END~~ + +select * from (values (2),(null),(1)) v(k) where k = k; +GO +~~START~~ +int4 +2 +1 +~~END~~ + + +-- Test partitioned tables with no partitions, which should be handled the +-- same as the non-inheritance case when expanding its RTE. +create table list_parted_tbl (a int,b int) partition by list (a); +GO +create table list_parted_tbl1 partition of list_parted_tbl + for values in (1) partition by list(b); +GO +explain (costs off) select * from list_parted_tbl; +GO +~~START~~ +text +Gather + Workers Planned: 1 + Single Copy: true + -> Result + One-Time Filter: false +~~END~~ + +drop table list_parted_tbl; +GO diff --git a/test/JDBC/expected/parallel_query/pgr_select_distinct.out b/test/JDBC/expected/parallel_query/pgr_select_distinct.out new file mode 100644 index 00000000000..b8c205e2969 --- /dev/null +++ b/test/JDBC/expected/parallel_query/pgr_select_distinct.out @@ -0,0 +1,632 @@ + + +-- +-- SELECT_DISTINCT +-- +-- +-- awk '{print $3;}' onek.data | sort -n | uniq +-- +SELECT DISTINCT two FROM onek ORDER BY 1; +GO +~~START~~ +int +0 +1 +~~END~~ + + +-- +-- awk '{print $5;}' onek.data | sort -n | uniq +-- +SELECT DISTINCT ten FROM onek ORDER BY 1; +GO +~~START~~ +int +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +~~END~~ + + +-- +-- awk '{print $16;}' onek.data | sort -d | uniq +-- +SELECT DISTINCT string4 FROM onek ORDER BY 1; +GO +~~START~~ +varchar +AAAAxx +HHHHxx +OOOOxx +VVVVxx +~~END~~ + + +-- +-- awk '{print $3,$16,$5;}' onek.data | sort -d | uniq | +-- sort +0n -1 +1d -2 +2n -3 +-- +SELECT DISTINCT two, string4, ten + FROM onek + ORDER BY two asc, string4 asc, ten asc; +GO +~~START~~ +int#!#varchar#!#int +0#!#AAAAxx#!#0 +0#!#AAAAxx#!#2 +0#!#AAAAxx#!#4 +0#!#AAAAxx#!#6 +0#!#AAAAxx#!#8 +0#!#HHHHxx#!#0 +0#!#HHHHxx#!#2 +0#!#HHHHxx#!#4 +0#!#HHHHxx#!#6 +0#!#HHHHxx#!#8 +0#!#OOOOxx#!#0 +0#!#OOOOxx#!#2 +0#!#OOOOxx#!#4 +0#!#OOOOxx#!#6 +0#!#OOOOxx#!#8 +0#!#VVVVxx#!#0 +0#!#VVVVxx#!#2 +0#!#VVVVxx#!#4 +0#!#VVVVxx#!#6 +0#!#VVVVxx#!#8 +1#!#AAAAxx#!#1 +1#!#AAAAxx#!#3 +1#!#AAAAxx#!#5 +1#!#AAAAxx#!#7 +1#!#AAAAxx#!#9 +1#!#HHHHxx#!#1 +1#!#HHHHxx#!#3 +1#!#HHHHxx#!#5 +1#!#HHHHxx#!#7 +1#!#HHHHxx#!#9 +1#!#OOOOxx#!#1 +1#!#OOOOxx#!#3 +1#!#OOOOxx#!#5 +1#!#OOOOxx#!#7 +1#!#OOOOxx#!#9 +1#!#VVVVxx#!#1 +1#!#VVVVxx#!#3 +1#!#VVVVxx#!#5 +1#!#VVVVxx#!#7 +1#!#VVVVxx#!#9 +~~END~~ + + + + + +-- +-- awk '{print $2;}' person.data | +-- awk '{if(NF!=1){print $2;}else{print;}}' - emp.data | +-- awk '{if(NF!=1){print $2;}else{print;}}' - student.data | +-- awk 'BEGIN{FS=" ";}{if(NF!=1){print $5;}else{print;}}' - stud_emp.data | +-- sort -n -r | uniq +-- +-- SELECT DISTINCT p.age FROM person* p ORDER BY age using desc; +-- GO +-- +-- Check mentioning same column more than once +-- +select set_config('babelfishpg_tsql.explain_verbose', 'on', false); +GO +~~START~~ +text +on +~~END~~ + + +select set_config('babelfishpg_tsql.explain_costs', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL ON; +GO + +SELECT count(*) FROM (SELECT DISTINCT two, four, two FROM tenk1) ss; +GO +~~START~~ +text +Query Text: SELECT count(*) FROM (SELECT DISTINCT two, four, two FROM tenk1) ss +Aggregate + Output: count(*) + -> Unique + Output: tenk1.two, tenk1.four, tenk1.two + -> Sort + Output: tenk1.two, tenk1.four, tenk1.two + Sort Key: tenk1.two, tenk1.four + -> Gather + Output: tenk1.two, tenk1.four, tenk1.two + Workers Planned: 4 + -> HashAggregate + Output: tenk1.two, tenk1.four, tenk1.two + Group Key: tenk1.two, tenk1.four, tenk1.two + -> Parallel Seq Scan on master_dbo.tenk1 + Output: tenk1.two, tenk1.four, tenk1.two +~~END~~ + + +SELECT count(*) FROM + (SELECT DISTINCT two, four, two FROM tenk1) ss; +GO +~~START~~ +text +Query Text: SELECT count(*) FROM + (SELECT DISTINCT two, four, two FROM tenk1) ss +Aggregate + Output: count(*) + -> Unique + Output: tenk1.two, tenk1.four, tenk1.two + -> Sort + Output: tenk1.two, tenk1.four, tenk1.two + Sort Key: tenk1.two, tenk1.four + -> Gather + Output: tenk1.two, tenk1.four, tenk1.two + Workers Planned: 4 + -> HashAggregate + Output: tenk1.two, tenk1.four, tenk1.two + Group Key: tenk1.two, tenk1.four, tenk1.two + -> Parallel Seq Scan on master_dbo.tenk1 + Output: tenk1.two, tenk1.four, tenk1.two +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL OFF; +GO + + +-- +-- Compare results between plans using sorting and plans using hash +-- aggregation. Force spilling in both cases by setting work_mem low. +-- +select set_config('work_mem', '64kB', false); +GO +~~START~~ +text +64kB +~~END~~ + + +-- Produce results with sorting. +select set_config('enable_hashagg', 'FALSE', false); +GO +~~START~~ +text +off +~~END~~ + + + + +-- select set_config('jit_above_cost', '0', false); +-- GO +select set_config('babelfishpg_tsql.explain_costs', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL ON; +GO + +SELECT DISTINCT g%1000 FROM generate_series(0,9999) g; +GO +~~START~~ +text +Query Text: SELECT DISTINCT g%1000 FROM generate_series(0,9999) g +Gather + Output: ((g % 1000)) + Workers Planned: 1 + Single Copy: true + -> Unique + Output: ((g % 1000)) + -> Sort + Output: ((g % 1000)) + Sort Key: ((g.g % 1000)) + -> Function Scan on pg_catalog.generate_series g + Output: (g % 1000) + Function Call: generate_series(0, 9999) +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL OFF; +GO + +SELECT DISTINCT g%1000 INTO distinct_group_1 FROM generate_series(0,9999) g; +GO + + +-- -- SET jit_above_cost TO DEFAULT; +-- select set_config('jit_above_cost', 'DEFAULT', false); +-- GO +SELECT DISTINCT cast((g%1000) as varchar(max)) INTO distinct_group_2 FROM generate_series(0,9999) g; +GO + +select set_config('enable_hashagg', 'TRUE', false); +GO +~~START~~ +text +on +~~END~~ + + + +-- Produce results with hash aggregation. +select set_config('enable_sort', 'FALSE', false); +GO +~~START~~ +text +off +~~END~~ + + + +-- select set_config('jit_above_cost', '0', false); +select set_config('babelfishpg_tsql.explain_costs', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL ON; +GO + +SELECT DISTINCT g%1000 FROM generate_series(0,9999) g; +GO +~~START~~ +text +Query Text: SELECT DISTINCT g%1000 FROM generate_series(0,9999) g +Gather + Output: ((g % 1000)) + Workers Planned: 1 + Single Copy: true + -> HashAggregate + Output: ((g % 1000)) + Group Key: (g.g % 1000) + -> Function Scan on pg_catalog.generate_series g + Output: (g % 1000) + Function Call: generate_series(0, 9999) +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL OFF; +GO + +SELECT DISTINCT g%1000 INTO distinct_hash_1 FROM generate_series(0,9999) g; +GO + + + +-- select set_config('jit_above_cost', 'DEFAULT', false); +-- GO +SELECT DISTINCT cast((g%1000) as varchar(max)) INTO distinct_hash_2 FROM generate_series(0,9999) g; +GO + +select set_config('enable_sort', 'TRUE', false); +GO +~~START~~ +text +on +~~END~~ + + +-- psql +SET work_mem TO DEFAULT; +GO + + +-- tsql + +-- Compare results +(SELECT * FROM distinct_hash_1 EXCEPT SELECT * FROM distinct_group_1) + UNION ALL +(SELECT * FROM distinct_group_1 EXCEPT SELECT * FROM distinct_hash_1); +GO +~~START~~ +int +~~END~~ + + +(SELECT * FROM distinct_hash_1 EXCEPT SELECT * FROM distinct_group_1) + UNION ALL +(SELECT * FROM distinct_group_1 EXCEPT SELECT * FROM distinct_hash_1); +GO +~~START~~ +int +~~END~~ + + +DROP TABLE distinct_hash_1; +GO +DROP TABLE distinct_hash_2; +GO +DROP TABLE distinct_group_1; +GO +DROP TABLE distinct_group_2; +GO + + +-- Test parallel DISTINCT +select set_config('parallel_tuple_cost', '0', false); +GO +~~START~~ +text +0 +~~END~~ + +select set_config('parallel_setup_cost', '0', false); +GO +~~START~~ +text +0 +~~END~~ + +select set_config('min_parallel_table_scan_size', '0', false); +GO +~~START~~ +text +0 +~~END~~ + +select set_config('max_parallel_workers_per_gather', '2', false); +GO +~~START~~ +text +2 +~~END~~ + + + + +-- Ensure we get a parallel plan +select set_config('babelfishpg_tsql.explain_costs', 'off', false); +GO +~~START~~ +text +off +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL ON; +GO + +SELECT DISTINCT four FROM tenk1; +GO +~~START~~ +text +Query Text: SELECT DISTINCT four FROM tenk1 +Unique + -> Sort + Sort Key: four + -> Gather + Workers Planned: 2 + -> HashAggregate + Group Key: four + -> Parallel Seq Scan on tenk1 +~~END~~ + + +SET BABELFISH_SHOWPLAN_ALL OFF; +GO + +-- Ensure the parallel plan produces the correct results +SELECT DISTINCT four FROM tenk1; +GO +~~START~~ +int +0 +1 +2 +3 +~~END~~ + + + +-- psql +-- Since Tsql function does not support specify parallel safe mode, we execute the following tests in psql +-- Ensure the parallel plan produces the correct results +SELECT DISTINCT four FROM master_dbo.tenk1; +GO +~~START~~ +int4 +0 +1 +2 +3 +~~END~~ + + +CREATE OR REPLACE FUNCTION distinct_func(a INT) RETURNS INT AS $$ + BEGIN + RETURN a; + END; +$$ LANGUAGE plpgsql PARALLEL UNSAFE; +GO + +-- Ensure we don't do parallel distinct with a parallel unsafe function +EXPLAIN (COSTS OFF) +SELECT DISTINCT distinct_func(1) FROM master_dbo.tenk1; +GO +~~START~~ +text +Unique + -> Sort + Sort Key: (distinct_func(1)) + -> Seq Scan on tenk1 +~~END~~ + + +-- make the function parallel safe +CREATE OR REPLACE FUNCTION distinct_func(a INT) RETURNS INT AS $$ + BEGIN + RETURN a; + END; +$$ LANGUAGE plpgsql PARALLEL SAFE; +GO + +-- Ensure we do parallel distinct now that the function is parallel safe +EXPLAIN (COSTS OFF) +SELECT DISTINCT distinct_func(1) FROM master_dbo.tenk1; +GO +~~START~~ +text +Unique + -> Sort + Sort Key: (distinct_func(1)) + -> Gather + Workers Planned: 4 + -> Parallel Seq Scan on tenk1 +~~END~~ + + +RESET max_parallel_workers_per_gather; +GO +RESET min_parallel_table_scan_size; +GO +RESET parallel_setup_cost; +GO +RESET parallel_tuple_cost; +GO + + +-- +-- Also, some tests of IS DISTINCT FROM, which doesn't quite deserve its +-- very own regression file. +-- +CREATE TEMP TABLE disttable (f1 integer); +GO +INSERT INTO DISTTABLE VALUES(1); +GO +~~ROW COUNT: 1~~ + +INSERT INTO DISTTABLE VALUES(2); +GO +~~ROW COUNT: 1~~ + +INSERT INTO DISTTABLE VALUES(3); +GO +~~ROW COUNT: 1~~ + +INSERT INTO DISTTABLE VALUES(NULL); +GO +~~ROW COUNT: 1~~ + + +-- basic cases +SELECT f1, f1 IS DISTINCT FROM 2 as "not 2" FROM disttable; +GO +~~START~~ +int4#!#bool +1#!#t +2#!#f +3#!#t +#!#t +~~END~~ + +SELECT f1, f1 IS DISTINCT FROM NULL as "not null" FROM disttable; +GO +~~START~~ +int4#!#bool +1#!#t +2#!#t +3#!#t +#!#f +~~END~~ + +SELECT f1, f1 IS DISTINCT FROM f1 as "false" FROM disttable; +GO +~~START~~ +int4#!#bool +1#!#f +2#!#f +3#!#f +#!#f +~~END~~ + +SELECT f1, f1 IS DISTINCT FROM f1+1 as "not null" FROM disttable; +GO +~~START~~ +int4#!#bool +1#!#t +2#!#t +3#!#t +#!#f +~~END~~ + + +-- check that optimizer constant-folds it properly +SELECT 1 IS DISTINCT FROM 2 as "yes"; +GO +~~START~~ +bool +t +~~END~~ + +SELECT 2 IS DISTINCT FROM 2 as "no"; +GO +~~START~~ +bool +f +~~END~~ + +SELECT 2 IS DISTINCT FROM null as "yes"; +GO +~~START~~ +bool +t +~~END~~ + +SELECT null IS DISTINCT FROM null as "no"; +GO +~~START~~ +bool +f +~~END~~ + + +-- negated form +SELECT 1 IS NOT DISTINCT FROM 2 as "no"; +GO +~~START~~ +bool +f +~~END~~ + +SELECT 2 IS NOT DISTINCT FROM 2 as "yes"; +GO +~~START~~ +bool +t +~~END~~ + +SELECT 2 IS NOT DISTINCT FROM null as "no"; +GO +~~START~~ +bool +f +~~END~~ + +SELECT null IS NOT DISTINCT FROM null as "yes"; +GO +~~START~~ +bool +t +~~END~~ + diff --git a/test/JDBC/expected/parallel_query/pgr_select_into.out b/test/JDBC/expected/parallel_query/pgr_select_into.out new file mode 100644 index 00000000000..d643c437dc9 --- /dev/null +++ b/test/JDBC/expected/parallel_query/pgr_select_into.out @@ -0,0 +1,419 @@ + +-- psql + +-- +-- SELECT_INTO +-- +SELECT * + INTO TABLE sitmp1 + FROM master_dbo.onek + WHERE master_dbo.onek.unique1 < 2; +GO +~~ROW COUNT: 2~~ + + +DROP TABLE sitmp1; +GO + +SELECT * + INTO TABLE sitmp1 + FROM master_dbo.onek2 + WHERE master_dbo.onek2.unique1 < 2; +GO +~~ROW COUNT: 2~~ + + +DROP TABLE sitmp1; +GO + +-- +-- SELECT INTO and INSERT permission, if owner is not allowed to insert. +-- +CREATE SCHEMA selinto_schema; +GO +CREATE USER regress_selinto_user; +GO +ALTER DEFAULT PRIVILEGES FOR ROLE regress_selinto_user + REVOKE INSERT ON TABLES FROM regress_selinto_user; +GO +GRANT ALL ON SCHEMA selinto_schema TO public; +GO + +SET SESSION AUTHORIZATION regress_selinto_user; +GO +-- WITH DATA, passes. +CREATE TABLE selinto_schema.tbl_withdata1 (a) + AS SELECT generate_series(1,3) WITH DATA; +GO +~~ROW COUNT: 3~~ + +INSERT INTO selinto_schema.tbl_withdata1 VALUES (4); +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: permission denied for table tbl_withdata1 + Server SQLState: 42501)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE selinto_schema.tbl_withdata2 (a) AS + SELECT generate_series(1,3) WITH DATA; +GO +~~START~~ +text +Gather (actual rows=3 loops=1) + Workers Planned: 1 + Workers Launched: 1 + Single Copy: true + -> ProjectSet (actual rows=3 loops=1) + -> Result (actual rows=1 loops=1) +~~END~~ + +-- WITH NO DATA, passes. +CREATE TABLE selinto_schema.tbl_nodata1 (a) AS + SELECT generate_series(1,3) WITH NO DATA; +GO +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE selinto_schema.tbl_nodata2 (a) AS + SELECT generate_series(1,3) WITH NO DATA; +GO +~~START~~ +text +Gather (never executed) + Workers Planned: 1 + Workers Launched: 0 + Single Copy: true + -> ProjectSet (never executed) + -> Result (never executed) +~~END~~ + +-- EXECUTE and WITH DATA, passes. +PREPARE data_sel AS SELECT generate_series(1,3); +GO +CREATE TABLE selinto_schema.tbl_withdata3 (a) AS + EXECUTE data_sel WITH DATA; +GO +~~ROW COUNT: 3~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE selinto_schema.tbl_withdata4 (a) AS + EXECUTE data_sel WITH DATA; +GO +~~START~~ +text +Gather (actual rows=3 loops=1) + Workers Planned: 1 + Workers Launched: 1 + Single Copy: true + -> ProjectSet (actual rows=3 loops=1) + -> Result (actual rows=1 loops=1) +~~END~~ + +-- EXECUTE and WITH NO DATA, passes. +CREATE TABLE selinto_schema.tbl_nodata3 (a) AS + EXECUTE data_sel WITH NO DATA; +GO +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE selinto_schema.tbl_nodata4 (a) AS + EXECUTE data_sel WITH NO DATA; +GO +~~START~~ +text +Gather (never executed) + Workers Planned: 1 + Workers Launched: 0 + Single Copy: true + -> ProjectSet (never executed) + -> Result (never executed) +~~END~~ + +RESET SESSION AUTHORIZATION; +GO + +ALTER DEFAULT PRIVILEGES FOR ROLE regress_selinto_user + GRANT INSERT ON TABLES TO regress_selinto_user; +GO + +SET SESSION AUTHORIZATION regress_selinto_user; +GO +RESET SESSION AUTHORIZATION; +GO + +DEALLOCATE data_sel; +GO +DROP SCHEMA selinto_schema CASCADE; +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: drop cascades to 8 other objects Server SQLState: 00000)~~ + +DROP USER regress_selinto_user; +GO + +-- Tests for WITH NO DATA and column name consistency +CREATE TABLE ctas_base (i int, j int); +GO +INSERT INTO ctas_base VALUES (1, 2); +GO +~~ROW COUNT: 1~~ + +CREATE TABLE ctas_nodata (ii, jj, kk) AS SELECT i, j FROM ctas_base; -- Error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: too many column names were specified + Server SQLState: 42601)~~ + +CREATE TABLE ctas_nodata (ii, jj, kk) AS SELECT i, j FROM ctas_base WITH NO DATA; -- Error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: too many column names were specified + Server SQLState: 42601)~~ + +CREATE TABLE ctas_nodata (ii, jj) AS SELECT i, j FROM ctas_base; -- OK +GO +~~ROW COUNT: 1~~ + +CREATE TABLE ctas_nodata_2 (ii, jj) AS SELECT i, j FROM ctas_base WITH NO DATA; -- OK +GO +CREATE TABLE ctas_nodata_3 (ii) AS SELECT i, j FROM ctas_base; -- OK +GO +~~ROW COUNT: 1~~ + +CREATE TABLE ctas_nodata_4 (ii) AS SELECT i, j FROM ctas_base WITH NO DATA; -- OK +GO +SELECT * FROM ctas_nodata; +GO +~~START~~ +int4#!#int4 +1#!#2 +~~END~~ + +SELECT * FROM ctas_nodata_2; +GO +~~START~~ +int4#!#int4 +~~END~~ + +SELECT * FROM ctas_nodata_3; +GO +~~START~~ +int4#!#int4 +1#!#2 +~~END~~ + +SELECT * FROM ctas_nodata_4; +GO +~~START~~ +int4#!#int4 +~~END~~ + +DROP TABLE ctas_base; +GO +DROP TABLE ctas_nodata; +GO +DROP TABLE ctas_nodata_2; +GO +DROP TABLE ctas_nodata_3; +GO +DROP TABLE ctas_nodata_4; +GO + +-- +-- CREATE TABLE AS/SELECT INTO as last command in a SQL function +-- have been known to cause problems +-- +CREATE FUNCTION make_table() RETURNS VOID +AS $$ + CREATE TABLE created_table AS SELECT * FROM master_dbo.int8_tbl; +$$ LANGUAGE SQL; +GO + +SELECT make_table(); +GO +~~START~~ +void + +~~END~~ + + +SELECT * FROM created_table; +GO +~~START~~ +int8#!#int8 +123#!#456 +123#!#4567890123456789 +4567890123456789#!#123 +4567890123456789#!#4567890123456789 +4567890123456789#!#-4567890123456789 +~~END~~ + + +-- Try EXPLAIN ANALYZE SELECT INTO and EXPLAIN ANALYZE CREATE TABLE AS +-- WITH NO DATA, but hide the outputs since they won't be stable. +DO $$ +BEGIN + EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM master_dbo.int8_tbl'; + EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM master_dbo.int8_tbl WITH NO DATA'; +END$$; +GO + +DROP TABLE created_table; +GO +DROP TABLE easi, easi2; +GO + +-- +-- Disallowed uses of SELECT ... INTO. All should fail +-- +DECLARE foo CURSOR FOR SELECT 1 INTO master_dbo.int4_tbl; +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: SELECT ... INTO is not allowed here + Position: 100 + Server SQLState: 42601)~~ + +COPY (SELECT 1 INTO frak UNION SELECT 2) TO 'blob'; +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: COPY (SELECT INTO) is not supported + Server SQLState: 0A000)~~ + +SELECT * FROM (SELECT 1 INTO f) bar; +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: SELECT ... INTO is not allowed here + Position: 30 + Server SQLState: 42601)~~ + +CREATE VIEW foo AS SELECT 1 INTO master_dbo.int4_tbl; +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: views must not contain SELECT INTO + Server SQLState: 0A000)~~ + +INSERT INTO master_dbo.int4_tbl SELECT 1 INTO f; +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: SELECT ... INTO is not allowed here + Position: 47 + Server SQLState: 42601)~~ + + +-- Test CREATE TABLE AS ... IF NOT EXISTS +CREATE TABLE ctas_ine_tbl AS SELECT 1; +GO +~~ROW COUNT: 1~~ + +CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0; -- error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: relation "ctas_ine_tbl" already exists + Server SQLState: 42P07)~~ + +CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0; -- ok +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: relation "ctas_ine_tbl" already exists + Server SQLState: 42P07)~~ + +CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- ok +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0; -- error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: relation "ctas_ine_tbl" already exists + Server SQLState: 42P07)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0; -- ok +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +~~START~~ +text +~~END~~ + +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: relation "ctas_ine_tbl" already exists + Server SQLState: 42P07)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- ok +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +~~START~~ +text +~~END~~ + +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +PREPARE ctas_ine_query AS SELECT 1 / 0; +GO +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE ctas_ine_tbl AS EXECUTE ctas_ine_query; -- error +GO +~~ERROR (Code: 0)~~ + +~~ERROR (Message: ERROR: relation "ctas_ine_tbl" already exists + Server SQLState: 42P07)~~ + +EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) + CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS EXECUTE ctas_ine_query; -- ok +GO +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +~~START~~ +text +~~END~~ + +~~WARNING (Code: 0)~~ + +~~WARNING (Message: relation "ctas_ine_tbl" already exists, skipping Server SQLState: 42P07)~~ + +DROP TABLE ctas_ine_tbl; +GO