subselect.slt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. # Copyright 1994, Regents of the University of California.
  2. # Copyright 1996-2019 PostgreSQL Global Development Group.
  3. # Copyright Materialize, Inc. and contributors. All rights reserved.
  4. #
  5. # Use of this software is governed by the Business Source License
  6. # included in the LICENSE file at the root of this repository.
  7. #
  8. # As of the Change Date specified in that file, in accordance with
  9. # the Business Source License, use of this software will be governed
  10. # by the Apache License, Version 2.0.
  11. #
  12. # This file is derived from the regression test suite in PostgreSQL.
  13. # The original file was retrieved on July 25, 2020 from:
  14. #
  15. # https://github.com/postgres/postgres/blob/15e441972276e95639f8c3d9f5f66c2318fe9348/src/test/regress/expected/subselect.out
  16. #
  17. # The original source code is subject to the terms of the PostgreSQL
  18. # license, a copy of which can be found in the LICENSE file at the
  19. # root of this repository.
  20. mode cockroach
  21. simple conn=mz_system,user=mz_system
  22. ALTER SYSTEM SET unsafe_enable_table_keys = true
  23. ----
  24. COMPLETE 0
  25. statement ok
  26. CREATE TABLE onek (
  27. unique1 int4,
  28. unique2 int4,
  29. two int4,
  30. four int4,
  31. ten int4,
  32. twenty int4,
  33. hundred int4,
  34. thousand int4,
  35. twothousand int4,
  36. fivethous int4,
  37. tenthous int4,
  38. odd int4,
  39. even int4,
  40. stringu1 text,
  41. stringu2 text,
  42. string4 text
  43. )
  44. copy onek test/sqllogictest/postgres/testdata/onek.data
  45. statement ok
  46. CREATE TABLE tenk1 (
  47. unique1 int4,
  48. unique2 int4,
  49. two int4,
  50. four int4,
  51. ten int4,
  52. twenty int4,
  53. hundred int4,
  54. thousand int4,
  55. twothousand int4,
  56. fivethous int4,
  57. tenthous int4,
  58. odd int4,
  59. even int4,
  60. stringu1 text,
  61. stringu2 text,
  62. string4 text
  63. )
  64. copy tenk1 test/sqllogictest/postgres/testdata/tenk.data
  65. statement ok
  66. CREATE TABLE int4_tbl (f1 int)
  67. statement ok
  68. INSERT INTO int4_tbl (f1) VALUES (0), (123456), (-123456), (2147483647), (-2147483647)
  69. statement ok
  70. CREATE TABLE int8_tbl (q1 bigint, q2 bigint)
  71. statement ok
  72. INSERT INTO int8_tbl VALUES
  73. (123, 456),
  74. (123, 4567890123456789),
  75. (4567890123456789, 123),
  76. (4567890123456789, 4567890123456789),
  77. (4567890123456789, -4567890123456789)
  78. query I colnames
  79. SELECT 1 AS one WHERE 1 IN (SELECT 1)
  80. ----
  81. one
  82. 1
  83. query I colnames
  84. SELECT 1 AS zero WHERE 1 NOT IN (SELECT 1)
  85. ----
  86. zero
  87. query I colnames
  88. SELECT 1 AS zero WHERE 1 IN (SELECT 2)
  89. ----
  90. zero
  91. # Check grammar's handling of extra parens in assorted contexts
  92. query I colnames
  93. SELECT * FROM (SELECT 1 AS x) ss
  94. ----
  95. x
  96. 1
  97. query I colnames
  98. SELECT * FROM ((SELECT 1 AS x)) ss
  99. ----
  100. x
  101. 1
  102. query I colnames
  103. (SELECT 2) UNION SELECT 2
  104. ----
  105. ?column?
  106. 2
  107. query I colnames
  108. ((SELECT 2)) UNION SELECT 2
  109. ----
  110. ?column?
  111. 2
  112. query I colnames
  113. SELECT ((SELECT 2) UNION SELECT 2)
  114. ----
  115. ?column?
  116. 2
  117. query I colnames
  118. SELECT (((SELECT 2)) UNION SELECT 2);
  119. ----
  120. ?column?
  121. 2
  122. query I
  123. SELECT (SELECT ARRAY[1,2,3])[1];
  124. ----
  125. 1
  126. query I
  127. SELECT ((SELECT ARRAY[1,2,3]))[2];
  128. ----
  129. 2
  130. query I
  131. SELECT (((SELECT ARRAY[1,2,3])))[3];
  132. ----
  133. 3
  134. # Set up some simple test tables
  135. statement ok
  136. CREATE TABLE SUBSELECT_TBL (
  137. f1 integer,
  138. f2 integer,
  139. f3 float
  140. )
  141. statement ok
  142. INSERT INTO SUBSELECT_TBL VALUES
  143. (1, 2, 3), (2, 3, 4), (3, 4, 5), (1, 1, 1),
  144. (2, 2, 2), (3, 3, 3), (6, 7, 8), (8, 9, NULL)
  145. query III colnames,rowsort
  146. SELECT * FROM SUBSELECT_TBL
  147. ----
  148. f1 f2 f3
  149. 1 2 3
  150. 2 3 4
  151. 3 4 5
  152. 1 1 1
  153. 2 2 2
  154. 3 3 3
  155. 6 7 8
  156. 8 9 NULL
  157. # Uncorrelated subselects
  158. query I colnames
  159. SELECT f1 AS "Constant Select" FROM SUBSELECT_TBL
  160. WHERE f1 IN (SELECT 1)
  161. ----
  162. Constant␠Select
  163. 1
  164. 1
  165. query I colnames,rowsort
  166. SELECT f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
  167. WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL)
  168. ----
  169. Uncorrelated␠Field
  170. 1
  171. 2
  172. 3
  173. 1
  174. 2
  175. 3
  176. query I colnames,rowsort
  177. SELECT f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
  178. WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE
  179. f2 IN (SELECT f1 FROM SUBSELECT_TBL))
  180. ----
  181. Uncorrelated␠Field
  182. 1
  183. 2
  184. 3
  185. 1
  186. 2
  187. 3
  188. query II colnames,rowsort
  189. SELECT f1, f2
  190. FROM SUBSELECT_TBL
  191. WHERE (f1, f2) NOT IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
  192. WHERE f3 IS NOT NULL)
  193. ----
  194. f1 f2
  195. 1 2
  196. 6 7
  197. 8 9
  198. # Correlated subselects
  199. query II colnames,rowsort
  200. SELECT f1 AS "Correlated Field", f2 AS "Second Field"
  201. FROM SUBSELECT_TBL upper
  202. WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1)
  203. ----
  204. Correlated␠Field Second␠Field
  205. 1 2
  206. 2 3
  207. 3 4
  208. 1 1
  209. 2 2
  210. 3 3
  211. query II colnames,rowsort
  212. SELECT f1 AS "Correlated Field", f3 AS "Second Field"
  213. FROM SUBSELECT_TBL upper
  214. WHERE f1 IN
  215. (SELECT f2 FROM SUBSELECT_TBL WHERE CAST(upper.f2 AS float) = f3)
  216. ----
  217. Correlated␠Field Second␠Field
  218. 2 4
  219. 3 5
  220. 1 1
  221. 2 2
  222. 3 3
  223. query II colnames,rowsort
  224. SELECT f1 AS "Correlated Field", f3 AS "Second Field"
  225. FROM SUBSELECT_TBL upper
  226. WHERE f3 IN (SELECT upper.f1 + f2 FROM SUBSELECT_TBL
  227. WHERE f2 = CAST(f3 AS integer))
  228. ----
  229. Correlated␠Field Second␠Field
  230. 1 3
  231. 2 4
  232. 3 5
  233. 6 8
  234. query I colnames,rowsort
  235. SELECT f1 AS "Correlated Field"
  236. FROM SUBSELECT_TBL
  237. WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
  238. WHERE f3 IS NOT NULL)
  239. ----
  240. Correlated␠Field
  241. 2
  242. 3
  243. 1
  244. 2
  245. 3
  246. # Use some existing tables in the regression test
  247. # Commented out as PostgreSQL is relying on undefined order of evaluation here.
  248. # query II colnames,rowsort
  249. # SELECT ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
  250. # FROM SUBSELECT_TBL ss
  251. # WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL
  252. # WHERE f1 != ss.f1 AND f1 < 2147483647)
  253. # ----
  254. # Correlated␠Field Second␠Field
  255. # 2 4
  256. # 3 5
  257. # 2 2
  258. # 3 3
  259. # 6 8
  260. # 8 NULL
  261. query IR colnames,rowsort
  262. select q1, count(*)::float8 / (select count(*) from int8_tbl)
  263. from int8_tbl group by q1 order by q1
  264. ----
  265. q1 ?column?
  266. 123 0.4
  267. 4567890123456789 0.6
  268. # Unspecified-type literals in output columns should resolve as text
  269. query TT colnames
  270. SELECT *, pg_typeof(f1) FROM
  271. (SELECT 'foo' AS f1 FROM generate_series(1,3)) ss ORDER BY 1
  272. ----
  273. f1 pg_typeof
  274. foo text
  275. foo text
  276. foo text
  277. query T colnames
  278. select 1 = all (select (select 1))
  279. ----
  280. ?column?
  281. true
  282. # Test cases to catch unpleasant interactions between IN-join processing
  283. # and subquery pullup.
  284. query I
  285. select count(*) from
  286. (select 1 from tenk1 a
  287. where unique1 IN (select hundred from tenk1 b)) ss
  288. ----
  289. 100
  290. query I
  291. select count(distinct ss.ten) from
  292. (select ten from tenk1 a
  293. where unique1 IN (select hundred from tenk1 b)) ss;
  294. ----
  295. 10
  296. query I
  297. select count(*) from
  298. (select 1 from tenk1 a
  299. where unique1 IN (select distinct hundred from tenk1 b)) ss;
  300. ----
  301. 100
  302. query I
  303. select count(distinct ss.ten) from
  304. (select ten from tenk1 a
  305. where unique1 IN (select distinct hundred from tenk1 b)) ss;
  306. ----
  307. 10
  308. # Test cases to check for overenthusiastic optimization of
  309. # "IN (SELECT DISTINCT ...)" and related cases. Per example from
  310. # Luca Pireddu and Michael Fuhr.
  311. statement ok
  312. CREATE TABLE foo (id integer)
  313. statement ok
  314. CREATE TABLE bar (id1 integer, id2 integer);
  315. statement ok
  316. INSERT INTO foo VALUES (1);
  317. statement ok
  318. INSERT INTO bar VALUES (1, 1), (2, 2), (3, 1)
  319. # These cases require an extra level of distinct-ing above subquery s
  320. query I colnames
  321. SELECT * FROM foo WHERE id IN
  322. (SELECT id2 FROM (SELECT DISTINCT id1, id2 FROM bar) AS s)
  323. ----
  324. id
  325. 1
  326. query I colnames
  327. SELECT * FROM foo WHERE id IN
  328. (SELECT id2 FROM (SELECT id1,id2 FROM bar GROUP BY id1,id2) AS s)
  329. ----
  330. id
  331. 1
  332. query I colnames
  333. SELECT * FROM foo WHERE id IN
  334. (SELECT id2 FROM (SELECT id1, id2 FROM bar UNION
  335. SELECT id1, id2 FROM bar) AS s)
  336. ----
  337. id
  338. 1
  339. # These cases do not
  340. query I colnames
  341. SELECT * FROM foo WHERE id IN
  342. (SELECT id2 FROM (SELECT DISTINCT ON (id2) id1, id2 FROM bar) AS s)
  343. ----
  344. id
  345. 1
  346. query I colnames
  347. SELECT * FROM foo WHERE id IN
  348. (SELECT id2 FROM (SELECT id2 FROM bar GROUP BY id2) AS s)
  349. ----
  350. id
  351. 1
  352. query I colnames
  353. SELECT * FROM foo WHERE id IN
  354. (SELECT id2 FROM (SELECT id2 FROM bar UNION
  355. SELECT id2 FROM bar) AS s)
  356. ----
  357. id
  358. 1
  359. # Test case to catch problems with multiply nested sub-SELECTs not getting
  360. # recalculated properly. Per bug report from Didier Moens.
  361. statement ok
  362. CREATE TABLE orderstest (
  363. approver_ref integer,
  364. po_ref integer,
  365. ordercanceled boolean
  366. )
  367. statement ok
  368. INSERT INTO orderstest VALUES
  369. (1, 1, false), (66, 5, false), (66, 6, false),
  370. (66, 7, false), (66, 1, true), (66, 8, false),
  371. (66, 1, false), (77, 1, false), (1, 1, false),
  372. (66, 1, false), (1, 1, false)
  373. statement ok
  374. CREATE VIEW orders_view AS
  375. SELECT *,
  376. (SELECT CASE
  377. WHEN ord.approver_ref=1 THEN '---' ELSE 'Approved'
  378. END) AS "Approved",
  379. (SELECT CASE
  380. WHEN ord.ordercanceled
  381. THEN 'Canceled'
  382. ELSE
  383. (SELECT CASE
  384. WHEN ord.po_ref=1
  385. THEN
  386. (SELECT CASE
  387. WHEN ord.approver_ref=1
  388. THEN '---'
  389. ELSE 'Approved'
  390. END)
  391. ELSE 'PO'
  392. END)
  393. END) AS "Status",
  394. (CASE
  395. WHEN ord.ordercanceled
  396. THEN 'Canceled'
  397. ELSE
  398. (CASE
  399. WHEN ord.po_ref=1
  400. THEN
  401. (CASE
  402. WHEN ord.approver_ref=1
  403. THEN '---'
  404. ELSE 'Approved'
  405. END)
  406. ELSE 'PO'
  407. END)
  408. END) AS "Status_OK"
  409. FROM orderstest ord
  410. query IITTTT colnames,rowsort
  411. SELECT * FROM orders_view
  412. ----
  413. approver_ref po_ref ordercanceled Approved Status Status_OK
  414. 1 1 false --- --- ---
  415. 66 5 false Approved PO PO
  416. 66 6 false Approved PO PO
  417. 66 7 false Approved PO PO
  418. 66 1 true Approved Canceled Canceled
  419. 66 8 false Approved PO PO
  420. 66 1 false Approved Approved Approved
  421. 77 1 false Approved Approved Approved
  422. 1 1 false --- --- ---
  423. 66 1 false Approved Approved Approved
  424. 1 1 false --- --- ---
  425. statement ok
  426. DROP TABLE orderstest CASCADE
  427. query II colnames,rowsort
  428. select f1, ss1 as relabel from
  429. (select *, (select sum(f1) from int4_tbl b where f1 >= a.f1) as ss1
  430. from int4_tbl a) ss
  431. ----
  432. f1 relabel
  433. 0 2147607103
  434. 123456 2147607103
  435. -123456 2147483647
  436. 2147483647 2147483647
  437. -2147483647 0
  438. # Test cases involving PARAM_EXEC parameters and min/max index optimizations.
  439. # Per bug report from David Sanchez i Gregori.
  440. query I colnames
  441. select * from (
  442. select max(unique1) from tenk1 as a
  443. where exists (select 1 from tenk1 as b where b.thousand = a.unique2)
  444. ) ss
  445. ----
  446. max
  447. 9997
  448. query I colnames
  449. select * from (
  450. select min(unique1) from tenk1 as a
  451. where not exists (select 1 from tenk1 as b where b.unique2 = 10000)
  452. ) ss
  453. ----
  454. min
  455. 0
  456. # --
  457. # -- Test case for bug database-issues#1339: bogus calculation of subplan param sets
  458. # --
  459. # create temp table ta (id int primary key, val int);
  460. # insert into ta values(1,1);
  461. # insert into ta values(2,2);
  462. # create temp table tb (id int primary key, aval int);
  463. # insert into tb values(1,1);
  464. # insert into tb values(2,1);
  465. # insert into tb values(3,2);
  466. # insert into tb values(4,2);
  467. # create temp table tc (id int primary key, aid int);
  468. # insert into tc values(1,1);
  469. # insert into tc values(2,2);
  470. # select
  471. # ( select min(tb.id) from tb
  472. # where tb.aval = (select ta.val from ta where ta.id = tc.aid) ) as min_tb_id
  473. # from tc;
  474. # min_tb_id
  475. # -----------
  476. # 1
  477. # 3
  478. # (2 rows)
  479. # Test case for 8.3 "failed to locate grouping columns" bug
  480. statement ok
  481. create table t1 (f1 numeric(14,0), f2 varchar(30))
  482. query III colnames
  483. select * from
  484. (select distinct f1, f2, (select f2 from t1 x where x.f1 = up.f1) as fs
  485. from t1 up) ss
  486. group by f1,f2,fs
  487. ----
  488. f1 f2 fs
  489. # Test case for bug materialize#5514 (mishandling of whole-row Vars in subselects)
  490. statement ok
  491. create table table_a (id integer)
  492. statement ok
  493. insert into table_a values (42)
  494. statement ok
  495. create view view_a as select * from table_a
  496. query T colnames
  497. select view_a from view_a
  498. ----
  499. view_a
  500. (42)
  501. query T colnames
  502. select (select view_a) from view_a
  503. ----
  504. view_a
  505. (42)
  506. query T colnames
  507. select (select (select view_a)) from view_a
  508. ----
  509. view_a
  510. (42)
  511. query T
  512. select (select (a.*)::text) from view_a a
  513. ----
  514. (42)
  515. # Check that whole-row Vars reading the result of a subselect don't include
  516. # any junk columns therein
  517. query T colnames,rowsort
  518. select q from (select max(f1) from int4_tbl group by f1 order by f1) q
  519. ----
  520. q
  521. (-2147483647)
  522. (-123456)
  523. (0)
  524. (123456)
  525. (2147483647)
  526. query T rowsort
  527. with q as (select max(f1) from int4_tbl group by f1 order by f1)
  528. select q from q;
  529. ----
  530. (-2147483647)
  531. (-123456)
  532. (0)
  533. (123456)
  534. (2147483647)
  535. # Test case for sublinks pushed down into subselects via join alias expansion
  536. query I colnames
  537. select
  538. (select sq1) as qq1
  539. from
  540. (select exists(select 1 from int4_tbl where f1 = q2) as sq1, 42 as dummy
  541. from int8_tbl) sq0
  542. join
  543. int4_tbl i4 on dummy = i4.f1
  544. ----
  545. qq1
  546. # Test case for cross-type partial matching in hashed subplan (bug materialize#7597)
  547. statement ok
  548. create table outer_7597 (f1 int4, f2 int4)
  549. statement ok
  550. insert into outer_7597 values (0, 0), (1, 0), (0, null), (1, null)
  551. statement ok
  552. create table inner_7597(c1 int8, c2 int8)
  553. statement ok
  554. insert into inner_7597 values(0, null)
  555. query II colnames,rowsort
  556. select * from outer_7597 where (f1, f2) not in (select * from inner_7597)
  557. ----
  558. f1 f2
  559. 1 0
  560. 1 NULL
  561. # Test case for planner bug with nested EXISTS handling
  562. query I colnames
  563. select a.thousand from tenk1 a, tenk1 b
  564. where a.thousand = b.thousand
  565. and exists ( select 1 from tenk1 c where b.hundred = c.hundred
  566. and not exists ( select 1 from tenk1 d
  567. where a.thousand = d.thousand ) )
  568. ----
  569. thousand
  570. # TODO: random
  571. #
  572. # query I colnames
  573. # select sum(ss.tst::int) from
  574. # onek o cross join lateral (
  575. # select i.ten in (select f1 from int4_tbl where f1 <= o.hundred) as tst,
  576. # random() as r
  577. # from onek i where i.unique1 = o.unique1 ) ss
  578. # where o.ten = 0
  579. # ----
  580. # sum
  581. # 100
  582. # Test rescan of a SetOp node
  583. query I colnames
  584. select count(*) from
  585. onek o cross join lateral (
  586. select * from onek i1 where i1.unique1 = o.unique1
  587. except
  588. select * from onek i2 where i2.unique1 = o.unique2
  589. ) ss
  590. where o.ten = 1
  591. ----
  592. count
  593. 100
  594. # TODO(benesch): WITH RECURSIVE.
  595. #
  596. # # Test rescan of a RecursiveUnion node
  597. # select sum(o.four), sum(ss.a) from
  598. # onek o cross join lateral (
  599. # with recursive x(a) as
  600. # (select o.four as a
  601. # union
  602. # select a + 1 from x
  603. # where a < 10)
  604. # select * from x
  605. # ) ss
  606. # where o.ten = 1;
  607. # sum | sum
  608. # ------+------
  609. # 1700 | 5350
  610. # (1 row)
  611. # Check we don't misoptimize a NOT IN where the subquery returns no rows.
  612. statement ok
  613. create table notinouter (a int)
  614. statement ok
  615. create table notininner (b int not null)
  616. statement ok
  617. insert into notinouter values (null), (1)
  618. query I colnames,rowsort
  619. select * from notinouter where a not in (select b from notininner)
  620. ----
  621. a
  622. NULL
  623. 1
  624. # Check we behave sanely in corner case of empty SELECT list (bug materialize#8648)
  625. statement ok
  626. create table nocolumns()
  627. query T colnames
  628. select exists(select * from nocolumns)
  629. ----
  630. exists
  631. false
  632. # Check behavior with a SubPlan in VALUES (bug database-issues#4272)
  633. query I rowsort
  634. select val.x
  635. from generate_series(1,10) as s(i),
  636. lateral (
  637. values ((select s.i + 1)), (s.i + 101)
  638. ) as val(x)
  639. where s.i < 10 and (select val.x) < 110
  640. ----
  641. 2
  642. 102
  643. 3
  644. 103
  645. 4
  646. 104
  647. 5
  648. 105
  649. 6
  650. 106
  651. 7
  652. 107
  653. 8
  654. 108
  655. 9
  656. 109
  657. 10
  658. # another variant of that (bug materialize#16213)
  659. query T colnames,rowsort
  660. select * from
  661. (values
  662. (3 not in (select * from (values (1), (2)) ss1)),
  663. (false)
  664. ) ss;
  665. ----
  666. column1
  667. true
  668. false
  669. # Check sane behavior with nested IN SubLinks
  670. query I colnames
  671. select * from int4_tbl where
  672. (case when f1 in (select unique1 from tenk1 a) then f1 else null end) in
  673. (select ten from tenk1 b)
  674. ----
  675. f1
  676. 0
  677. # TODO(benesch): SRF in scalar position.
  678. #
  679. # # Check for incorrect optimization when IN subquery contains a SRF
  680. # query I colnames
  681. # select * from int4_tbl o where (f1, f1) in
  682. # (select f1, generate_series(1,50) / 10 g from int4_tbl i group by f1);
  683. # ----
  684. # f1
  685. # 0
  686. # check for over-optimization of whole-row Var referencing an Append plan
  687. query T colnames,rowsort
  688. select (select q from
  689. (select 1,2,3.0 where f1 > 0
  690. union all
  691. select 4,5,6.0 where f1 <= 0
  692. ) q )
  693. from int4_tbl
  694. ----
  695. q
  696. (1,2,3)
  697. (1,2,3)
  698. (4,5,6)
  699. (4,5,6)
  700. (4,5,6)
  701. # TODO: random.
  702. #
  703. # Check for sane handling of a lateral reference in a subquery's quals
  704. # (most of the complication here is to prevent the test case from being
  705. # flattened too much)
  706. # query III colnames
  707. # select * from
  708. # int4_tbl i4,
  709. # lateral (
  710. # select i4.f1 > 1 as b, 1 as id
  711. # from (select random() order by 1) as t1
  712. # union all
  713. # select true as b, 2 as id
  714. # ) as t2
  715. # where b and f1 >= 0
  716. # ----
  717. # f1 b id
  718. # 0 t 2
  719. # 123456 t 1
  720. # 123456 t 2
  721. # 2147483647 t 1
  722. # 2147483647 t 2