bfv_subquery.out 19.2 KB
Newer Older
1 2 3 4
-- count number of certain operators in a given plan
-- start_ignore
create language plpythonu;
-- end_ignore
5
create or replace function count_operator(query text, operator text) returns int as
6
$$
7
rv = plpy.execute('EXPLAIN ' + query)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
search_text = operator
result = 0
for i in range(len(rv)):
    cur_line = rv[i]['QUERY PLAN']
    if search_text.lower() in cur_line.lower():
        result = result+1
return result
$$
language plpythonu;
--start_ignore
DROP TABLE IF EXISTS bfv_subquery_p;
NOTICE:  table "bfv_subquery_p" does not exist, skipping
DROP TABLE IF EXISTS bfv_subquery_r;
NOTICE:  table "bfv_subquery_r" does not exist, skipping
--end_ignore
-- subquery over partitioned table
CREATE TABLE bfv_subquery_(a int, b int) partition by range(b) (start(1) end(10));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
NOTICE:  CREATE TABLE will create partition "bfv_subquery__1_prt_1" for table "bfv_subquery_"
CREATE TABLE bfv_subquery_r (a int, b int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO bfv_subquery_ SELECT i,i FROM generate_series(1,9)i;
INSERT INTO bfv_subquery_r SELECT i,i FROM generate_series(1,9)i;
SELECT a FROM bfv_subquery_r WHERE b < ( SELECT 0.5 * sum(a) FROM bfv_subquery_ WHERE b >= 3) ORDER BY 1;
 a 
---
 1
 2
 3
 4
 5
 6
 7
 8
 9
(9 rows)

	
--start_ignore
drop table if exists bfv_subquery_r2;
NOTICE:  table "bfv_subquery_r2" does not exist, skipping
drop table if exists s;
NOTICE:  table "s" does not exist, skipping
--end_ignore
-- subquery with distinct and outer references	
create table bfv_subquery_r2(a int, b int) distributed by (a);
create table bfv_subquery_s2(a int, b int) distributed by (a);
insert into bfv_subquery_r2 values (1,1);
insert into bfv_subquery_r2 values (2,1);
insert into bfv_subquery_r2 values (2,NULL);
insert into bfv_subquery_r2 values (NULL,0);
insert into bfv_subquery_r2 values (NULL,NULL);
insert into bfv_subquery_s2 values (2,2);
insert into bfv_subquery_s2 values (1,0);
insert into bfv_subquery_s2 values (1,1);
select * from bfv_subquery_r2 
where a = (select x.a from (select distinct a from bfv_subquery_s2 where bfv_subquery_s2.b = bfv_subquery_r2	.b) x);
 a | b 
---+---
 1 | 1
(1 row)

H
Haisheng Yuan 已提交
72
-- start_ignore
73 74
DROP FUNCTION IF EXISTS csq_f(a int);
NOTICE:  function csq_f(pg_catalog.int4) does not exist, skipping
H
Haisheng Yuan 已提交
75
-- end_ignore
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
CREATE FUNCTION csq_f(a int) RETURNS int AS $$ select $1 $$ LANGUAGE SQL;
--start_ignore
DROP TABLE IF EXISTS csq_r;
NOTICE:  table "csq_r" does not exist, skipping
--end_ignore
CREATE TABLE csq_r(a int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO csq_r VALUES (1);
SELECT * FROM csq_r WHERE a IN (SELECT * FROM csq_f(csq_r.a));
 a 
---
 1
(1 row)

-- subquery in the select list
--start_ignore
drop table if exists  bfv_subquery_t1;
NOTICE:  table "bfv_subquery_t1" does not exist, skipping
drop table if exists  bfv_subquery_t2;
NOTICE:  table "bfv_subquery_t2" does not exist, skipping
--end_ignore
create table  bfv_subquery_t1(i int, j int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table  bfv_subquery_t2(i int, j int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into  bfv_subquery_t1 select i, i%5 from generate_series(1,10)i;
insert into  bfv_subquery_t2 values (1, 10);
106
select count_operator('select bfv_subquery_t1.i, (select bfv_subquery_t1.i from bfv_subquery_t2) from bfv_subquery_t1;', 'Seq Scan') > 0;
107 108 109 110 111 112
 ?column? 
----------
 t
(1 row)

select bfv_subquery_t1.i, (select bfv_subquery_t1.i from bfv_subquery_t2) from bfv_subquery_t1 order by 1, 2;
R
Richard Guo 已提交
113 114 115 116 117 118 119 120 121 122 123 124
 i  | i  
----+----
  1 |  1
  2 |  2
  3 |  3
  4 |  4
  5 |  5
  6 |  6
  7 |  7
  8 |  8
  9 |  9
 10 | 10
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
(10 rows)

-- start_ignore
drop table if exists bfv_subquery_t3;
NOTICE:  table "bfv_subquery_t3" does not exist, skipping
drop table if exists bfv_subquery_s3;
NOTICE:  table "bfv_subquery_s3" does not exist, skipping
-- end_ignore
create table bfv_subquery_t3(a int, b int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into bfv_subquery_t3 values (1,4),(0,3);
create table bfv_subquery_s3(i int, j int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
-- ALL subquery
select * from bfv_subquery_t3 where a < all (select i from bfv_subquery_s3 limit 1) order by a;
 a | b 
---+---
 0 | 3
 1 | 4
(2 rows)

select * from bfv_subquery_t3 where a < all (select i from bfv_subquery_s3) order by a;
 a | b 
---+---
 0 | 3
 1 | 4
(2 rows)

select * from bfv_subquery_t3 where a < all (select i from bfv_subquery_s3 limit 2) order by a;
 a | b 
---+---
 0 | 3
 1 | 4
(2 rows)

select * from bfv_subquery_t3 where a < all (select i from bfv_subquery_s3) order by a;
 a | b 
---+---
 0 | 3
 1 | 4
(2 rows)

-- Direct Dispatch caused reader gang process hanging  on start_xact_command
DROP TABLE IF EXISTS bfv_subquery_a1;
NOTICE:  table "bfv_subquery_a1" does not exist, skipping
DROP TABLE IF EXISTS bfv_subquery_b1;
NOTICE:  table "bfv_subquery_b1" does not exist, skipping
CREATE TABLE bfv_subquery_a1(i INT, j INT);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO bfv_subquery_a1(SELECT i, i * i FROM generate_series(1, 10) AS i);
CREATE TABLE bfv_subquery_b1(i INT, j INT);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO bfv_subquery_b1(SELECT i, i * i FROM generate_series(1, 10) AS i);
SELECT  bfv_subquery_a1.* FROM bfv_subquery_a1 INNER JOIN bfv_subquery_b1 ON  bfv_subquery_a1.i =  bfv_subquery_b1.i WHERE  bfv_subquery_a1.j NOT IN (SELECT j FROM bfv_subquery_a1 a2 where a2.j =  bfv_subquery_b1.j) and  bfv_subquery_a1.i = 1;
 i | j 
---+---
(0 rows)

DROP TABLE IF EXISTS bfv_subquery_a2;
NOTICE:  table "bfv_subquery_a2" does not exist, skipping
CREATE TABLE bfv_subquery_a2(i INT, j INT);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO bfv_subquery_a2(SELECT i, i * i FROM generate_series(1, 10) AS i);
SELECT bfv_subquery_a2.* FROM bfv_subquery_a2 WHERE bfv_subquery_a2.j NOT IN (SELECT j FROM bfv_subquery_a2 a2 where a2.j = bfv_subquery_a2.j) and bfv_subquery_a2.i = 1;
 i | j 
---+---
(0 rows)

-- prohibit plans with Motions above outer references
--start_ignore
drop table if exists  bfv_subquery_foo1;
NOTICE:  table "bfv_subquery_foo1" does not exist, skipping
--end_ignore
create table  bfv_subquery_foo1(a integer, b integer) distributed by (a);
							 
insert into  bfv_subquery_foo1 values(1,1);
insert into  bfv_subquery_foo1 values(2,2);
select 
(select a from  bfv_subquery_foo1 inner1 where inner1.a=outer1.a  
union 
select b from  bfv_subquery_foo1 inner2 where inner2.b=outer1.b) 
from  bfv_subquery_foo1 outer1;
R
Richard Guo 已提交
212 213 214 215
 a 
---
 1
 2
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
(2 rows)

-- using of subqueries with unnest with IN or NOT IN predicates
select 1 where 22 not in (SELECT unnest(array[1,2]));
 ?column? 
----------
        1
(1 row)

select 1 where 22 in (SELECT unnest(array[1,2]));
 ?column? 
----------
(0 rows)

select 1 where 22  in (SELECT unnest(array[1,2,22]));
 ?column? 
----------
        1
(1 row)

select 1 where 22 not in (SELECT unnest(array[1,2,22]));
 ?column? 
----------
(0 rows)

-- start_ignore
drop table if exists mpp_t1;
NOTICE:  table "mpp_t1" does not exist, skipping
drop table if exists mpp_t2;
NOTICE:  table "mpp_t2" does not exist, skipping
drop table if exists mpp_t3;
NOTICE:  table "mpp_t3" does not exist, skipping
create table mpp_t1(a int,b int) distributed by (a); 
create table mpp_t2(a int,b int) distributed by (b);
create table mpp_t3(like mpp_t1);
251
NOTICE:  table doesn't have 'DISTRIBUTED BY' clause, defaulting to distribution columns from LIKE table
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
-- end_ignore
select * from mpp_t1 where a=1 and a=2 and a > (select mpp_t2.b from mpp_t2);
 a | b 
---+---
(0 rows)

select * from mpp_t1 where a<1 and a>2 and a > (select mpp_t2.b from mpp_t2);
 a | b 
---+---
(0 rows)

select * from mpp_t3 where a in ( select a from mpp_t1 where a<1 and a>2 and a > (select mpp_t2.b from mpp_t2));
 a | b 
---+---
(0 rows)

select * from mpp_t3 where a <1 and a=1 and a in ( select a from mpp_t1 where a > (select mpp_t2.b from mpp_t2));
 a | b 
---+---
(0 rows)

select * from mpp_t1 where a <1 and a=1 and a in ( select a from mpp_t1 where a > (select mpp_t2.b from mpp_t2));
 a | b 
---+---
(0 rows)

select * from mpp_t1 where a = (select a FROM mpp_t2 where mpp_t2.b > (select max(b) from mpp_t3 group by b) and mpp_t2.b=1 and mpp_t2.b=2);
 a | b 
---+---
(0 rows)

-- start_ignore
drop table if exists mpp_t1;
drop table if exists mpp_t2;
drop table if exists mpp_t3;
-- end_ignore
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
--
-- Test case for when there is case clause in join filter
--
-- start_ignore
drop table if exists t_case_subquery1;
NOTICE:  table "t_case_subquery1" does not exist, skipping
-- end_ignore
create table t_case_subquery1 (a int, b int, c text);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into t_case_subquery1 values(1, 5, NULL), (1, 2, NULL);
select t1.* from t_case_subquery1 t1 where t1.b = (
  select max(b) from t_case_subquery1 t2 where t1.a = t2.a and t2.b < 5 and
    case
    when t1.c is not null and t2.c is not null
    then t1.c = t2.c
    end
);
 a | b | c 
---+---+---
(0 rows)

-- start_ignore
drop table if exists t_case_subquery1;
-- end_ignore
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
--
-- Test case for if coalesce is needed for specific cases where a subquery with
-- count aggregate has to return 0 or null. Count returns 0 on empty relations
-- where other queries return NULL.
--
-- start_ignore
drop table if exists t_coalesce_count_subquery;
NOTICE:  table "t_coalesce_count_subquery" does not exist, skipping
drop table if exists t_coalesce_count_subquery_empty;
NOTICE:  table "t_coalesce_count_subquery_empty" does not exist, skipping
drop table if exists t_coalesce_count_subquery_empty2;
NOTICE:  table "t_coalesce_count_subquery_empty2" does not exist, skipping
CREATE TABLE t_coalesce_count_subquery(a, b) AS VALUES (1, 1);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE t_coalesce_count_subquery_empty(c int, d int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE t_coalesce_count_subquery_empty2(e int, f int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'e' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
-- end_ignore
SELECT (SELECT count(*) FROM t_coalesce_count_subquery_empty where c = a) FROM t_coalesce_count_subquery;
R
Richard Guo 已提交
336 337 338
 count 
-------
     0
339 340 341
(1 row)

SELECT (SELECT COUNT(*) FROM t_coalesce_count_subquery_empty GROUP BY c LIMIT 1) FROM t_coalesce_count_subquery;
R
Richard Guo 已提交
342 343 344
 count 
-------
      
345 346 347 348 349 350
(1 row)

SELECT (SELECT a1 FROM (SELECT count(*) FROM t_coalesce_count_subquery_empty2 group by e
        union all
        SELECT count(*) from t_coalesce_count_subquery_empty group by c) x(a1) LIMIT 1)
FROM t_coalesce_count_subquery;
R
Richard Guo 已提交
351 352 353
 a1 
----
   
354 355 356 357 358 359
(1 row)

SELECT (SELECT a1 FROM (SELECT count(*) from t_coalesce_count_subquery_empty group by c
        union all
        SELECT count(*) FROM t_coalesce_count_subquery_empty2 group by e) x(a1) LIMIT 1)
FROM t_coalesce_count_subquery;
R
Richard Guo 已提交
360 361 362
 a1 
----
   
363 364 365 366 367 368
(1 row)

-- start_ignore
drop table if exists t_coalesce_count_subquery;
drop table if exists t_coalesce_count_subquery_empty;
drop table if exists t_coalesce_count_subquery_empty2;
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
-- start_ignore
drop table if exists t_outer;
NOTICE:  table "t_outer" does not exist, skipping
drop table if exists t_inner;
NOTICE:  table "t_inner" does not exist, skipping
create table t_outer (a oid, b tid);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table t_inner (c int);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
-- end_ignore
SET enable_nestloop=off;
SET enable_hashjoin=off;
set enable_mergejoin = on;
select * from t_outer where t_outer.b not in (select ctid from t_inner);
385 386
NOTICE:  SELECT uses system-defined column "t_inner.ctid" without the necessary companion column "t_inner.gp_segment_id"
HINT:  To uniquely identify a row within a distributed table, use the "gp_segment_id" column together with the "ctid" column.
387 388 389 390 391 392 393 394 395 396 397
 a | b 
---+---
(0 rows)

RESET enable_nestloop;
RESET enable_hashjoin;
RESET enable_mergejoin;
-- start_ignore
drop table if exists t_outer;
drop table if exists t_inner;
-- end_ignore
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
--
-- In some cases of a NOT EXISTS subquery, planner mistook one side of the
-- predicate as a (derived or direct) attribute on the inner relation, and
-- incorrectly decorrelated the subquery into a JOIN
-- start_ignore
drop table if exists foo;
NOTICE:  table "foo" does not exist, skipping
drop table if exists bar;
NOTICE:  table "bar" does not exist, skipping
create table foo(a, b) as (values (1, 'a'), (2, 'b'));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table bar(c, d) as (values (1, 'a'), (2, 'b'));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'c' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
-- end_ignore
select * from foo where not exists (select * from bar where foo.a + bar.c = 1);
415
 a | b 
416 417 418 419 420 421
---+---
 1 | a
 2 | b
(2 rows)

select * from foo where not exists (select * from bar where foo.b || bar.d = 'hola');
422
 a | b 
423 424 425 426 427 428
---+---
 1 | a
 2 | b
(2 rows)

select * from foo where not exists (select * from bar where foo.a = foo.a + 1);
429
 a | b 
430 431 432 433 434 435
---+---
 1 | a
 2 | b
(2 rows)

select * from foo where not exists (select * from bar where foo.b = foo.b || 'a');
436
 a | b 
437 438 439 440 441 442
---+---
 1 | a
 2 | b
(2 rows)

select * from foo where foo.a = (select min(bar.c) from bar where foo.b || bar.d = 'bb');
443
 a | b 
444 445 446 447 448
---+---
 2 | b
(1 row)

drop table foo, bar;
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
--
-- Test subquery with rescan of RESULT node
--
create table foo_rescan_result(a, b) as (values (1, 2), (1, 1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'column1' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table bar_rescan_result(a, b) as (values (1, 1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'column1' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
select * from foo_rescan_result t1
where (select count(*) from bar_rescan_result where t1.a=t1.b) > 0;
 a | b 
---+---
 1 | 1
(1 row)

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
--
-- subqueries with unnest in projectlist
--
-- start_ignore
DROP TABLE IF EXISTS A;
NOTICE:  table "a" does not exist, skipping
CREATE TABLE A AS SELECT ARRAY[1,2,3] AS X;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'x' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO A VALUES(NULL::int4[]);
-- end_ignore
SELECT (NOT EXISTS (SELECT UNNEST(X))) AS B FROM A;
 b 
---
 f
 t
(2 rows)

SELECT (EXISTS (SELECT UNNEST(X))) AS B FROM A;
 b 
---
 t
 f
(2 rows)

EXPLAIN SELECT (EXISTS (SELECT UNNEST(X))) AS B FROM A;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1.02 rows=1 width=33)
   ->  Seq Scan on a  (cost=0.00..1.02 rows=1 width=33)
         SubPlan 1
           ->  Result  (cost=0.00..0.01 rows=1 width=0)
 Settings:  optimizer=off
498
 Optimizer status: Postgres query optimizer
499 500 501
(6 rows)

DROP TABLE A;