bfv_partition.out 80.1 KB
Newer Older
1 2
create schema bfv_partition;
set search_path=bfv_partition;
3 4 5
--
-- Initial setup for all the partitioning test for this suite
--
6 7 8 9
-- start_ignore
create language plpythonu;
ERROR:  language "plpythonu" already exists
-- end_ignore
10
create or replace function count_operator(query text, operator text) returns int as
11
$$
12
rv = plpy.execute('EXPLAIN ' + query)
13 14 15 16 17 18 19 20 21 22 23
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;
create or replace function find_operator(query text, operator_name text) returns text as
$$
24
rv = plpy.execute('EXPLAIN' + query)
25 26 27 28 29 30 31 32 33 34
search_text = operator_name
result = ['false']
for i in range(len(rv)):
    cur_line = rv[i]['QUERY PLAN']
    if search_text.lower() in cur_line.lower():
        result = ['true']
        break
return result
$$
language plpythonu;
35 36 37
--
-- Tests if it produces SIGSEGV from "select from partition_table group by rollup or cube function"
--
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
-- SETUP
-- start_ignore
drop table if exists mpp7980;
NOTICE:  table "mpp7980" does not exist, skipping
-- end_ignore
create table mpp7980
(
 month_id date,
 bill_stmt_id  character varying(30),
 cust_type     character varying(10),
 subscription_status      character varying(30),
 voice_call_min           numeric(15,2),
 minute_per_call          numeric(15,2),
 subscription_id          character varying(15)
)
distributed by (subscription_id, bill_stmt_id)
  PARTITION BY RANGE(month_id)
    (
    start ('2009-02-01'::date) end ('2009-08-01'::date)  exclusive EVERY (INTERVAL '1 month')
    );
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_1" for table "mpp7980"
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_2" for table "mpp7980"
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_3" for table "mpp7980"
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_4" for table "mpp7980"
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_5" for table "mpp7980"
NOTICE:  CREATE TABLE will create partition "mpp7980_1_prt_6" for table "mpp7980"
    
-- TEST
66
select count_operator('select cust_type, subscription_status,count(distinct subscription_id),sum(voice_call_min),sum(minute_per_call) from mpp7980 where month_id =E''2009-04-01'' group by rollup(1,2);','SIGSEGV');
67 68 69 70 71
 count_operator 
----------------
              0
(1 row)

72 73 74 75 76 77 78 79 80 81 82 83
insert into mpp7980 values('2009-04-01','xyz','zyz','1',1,1,'1');
insert into mpp7980 values('2009-04-01','zxyz','zyz','2',2,1,'1');
insert into mpp7980 values('2009-03-03','xyz','zyz','4',1,3,'1');
select cust_type, subscription_status,count(distinct subscription_id),sum(voice_call_min),sum(minute_per_call) from mpp7980 where month_id ='2009-04-01' group by rollup(1,2);
 cust_type | subscription_status | count | sum  | sum  
-----------+---------------------+-------+------+------
           |                     |     1 | 3.00 | 2.00
 zyz       |                     |     1 | 3.00 | 2.00
 zyz       | 1                   |     1 | 1.00 | 1.00
 zyz       | 2                   |     1 | 2.00 | 1.00
(4 rows)

84 85 86 87
-- CLEANUP
-- start_ignore
drop table mpp7980;
-- end_ignore
88 89 90
--
-- Tests if it is using casting comparator for partition selector with compatible types
--
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 212 213 214 215 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 251 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 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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
-- SETUP
CREATE TABLE TIMESTAMP_MONTH_rangep_STARTINCL (i1 int, f2 timestamp)
partition by range (f2)
(
  start ('2000-01-01'::timestamp) INCLUSIVE
  end (date '2001-01-01'::timestamp) EXCLUSIVE
  every ('1 month'::interval)
);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i1' 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 "timestamp_month_rangep_startincl_1_prt_1" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_2" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_3" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_4" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_5" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_6" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_7" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_8" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_9" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_10" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_11" for table "timestamp_month_rangep_startincl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startincl_1_prt_12" for table "timestamp_month_rangep_startincl"
CREATE TABLE TIMESTAMP_MONTH_rangep_STARTEXCL (i1 int, f2 timestamp)
partition by range (f2)
(
  start ('2000-01-01'::timestamp) EXCLUSIVE
  end (date '2001-01-01'::timestamp) INCLUSIVE
  every ('1 month'::interval)
);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i1' 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 "timestamp_month_rangep_startexcl_1_prt_1" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_2" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_3" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_4" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_5" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_6" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_7" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_8" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_9" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_10" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_11" for table "timestamp_month_rangep_startexcl"
NOTICE:  CREATE TABLE will create partition "timestamp_month_rangep_startexcl_1_prt_12" for table "timestamp_month_rangep_startexcl"
CREATE TABLE TIMESTAMP_MONTH_listp (i1 int, f2 timestamp)
partition by list (f2)
(
  partition jan1 values ('2000-01-01'::timestamp),
  partition jan2 values ('2000-01-02'::timestamp),
  partition jan3 values ('2000-01-03'::timestamp),
  partition jan4 values ('2000-01-04'::timestamp),
  partition jan5 values ('2000-01-05'::timestamp)
);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i1' 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 "timestamp_month_listp_1_prt_jan1" for table "timestamp_month_listp"
NOTICE:  CREATE TABLE will create partition "timestamp_month_listp_1_prt_jan2" for table "timestamp_month_listp"
NOTICE:  CREATE TABLE will create partition "timestamp_month_listp_1_prt_jan3" for table "timestamp_month_listp"
NOTICE:  CREATE TABLE will create partition "timestamp_month_listp_1_prt_jan4" for table "timestamp_month_listp"
NOTICE:  CREATE TABLE will create partition "timestamp_month_listp_1_prt_jan5" for table "timestamp_month_listp"
-- TEST
-- Middle of a middle range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTINCL values (1, '2000-07-16');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = '2000-07-16';
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_TIMESTAMP('2000-07-16', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_DATE('2000-07-16', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

-- Beginning of the first range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTINCL values (2, '2000-01-01');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = '2000-01-01';
 i1 |            f2            
----+--------------------------
  2 | Sat Jan 01 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_TIMESTAMP('2000-01-01', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  2 | Sat Jan 01 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_DATE('2000-01-01', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  2 | Sat Jan 01 00:00:00 2000
(1 row)

INSERT INTO TIMESTAMP_MONTH_rangep_STARTINCL values (3, '2000-01-02');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = '2000-01-02';
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_TIMESTAMP('2000-01-02', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_DATE('2000-01-02', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

-- End of the last range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTINCL values (4, '2000-12-31');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = '2000-12-31';
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_TIMESTAMP('2000-12-31', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_DATE('2000-12-31', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

INSERT INTO TIMESTAMP_MONTH_rangep_STARTINCL values (5, '2001-01-01'); -- should fail, no such partition
ERROR:  no partition for partitioning key  (seg1 office-4-160.pa.pivotal.io:25433 pid=9457)
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = '2001-01-01';
 i1 | f2 
----+----
(0 rows)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_TIMESTAMP('2001-01-01', 'YYYY-MM-DD');
 i1 | f2 
----+----
(0 rows)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTINCL WHERE f2 = TO_DATE('2001-01-01', 'YYYY-MM-DD');
 i1 | f2 
----+----
(0 rows)

-- Range partitioning: START EXCLUSIVE, END INCLUSIVE
-- Middle of a middle range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTEXCL values (1, '2000-07-16');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = '2000-07-16';
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_TIMESTAMP('2000-07-16', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_DATE('2000-07-16', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Sun Jul 16 00:00:00 2000
(1 row)

-- Beginning of the first range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTEXCL values (2, '2000-01-01'); -- should fail, no such partition
ERROR:  no partition for partitioning key  (seg0 office-4-160.pa.pivotal.io:25432 pid=9456)
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = '2000-01-01';
 i1 | f2 
----+----
(0 rows)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_TIMESTAMP('2000-01-01', 'YYYY-MM-DD');
 i1 | f2 
----+----
(0 rows)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_DATE('2000-01-01', 'YYYY-MM-DD');
 i1 | f2 
----+----
(0 rows)

INSERT INTO TIMESTAMP_MONTH_rangep_STARTEXCL values (3, '2000-01-02');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = '2000-01-02';
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_TIMESTAMP('2000-01-02', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_DATE('2000-01-02', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  3 | Sun Jan 02 00:00:00 2000
(1 row)

-- End of the last range
INSERT INTO TIMESTAMP_MONTH_rangep_STARTEXCL values (4, '2000-12-31');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = '2000-12-31';
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_TIMESTAMP('2000-12-31', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_DATE('2000-12-31', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  4 | Sun Dec 31 00:00:00 2000
(1 row)

INSERT INTO TIMESTAMP_MONTH_rangep_STARTEXCL values (5, '2001-01-01');
SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = '2001-01-01';
 i1 |            f2            
----+--------------------------
  5 | Mon Jan 01 00:00:00 2001
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_TIMESTAMP('2001-01-01', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  5 | Mon Jan 01 00:00:00 2001
(1 row)

SELECT * FROM TIMESTAMP_MONTH_rangep_STARTEXCL WHERE f2 = TO_DATE('2001-01-01', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  5 | Mon Jan 01 00:00:00 2001
(1 row)

-- List partitioning
INSERT INTO TIMESTAMP_MONTH_listp values (1, '2000-01-03');
SELECT * FROM TIMESTAMP_MONTH_listp WHERE f2 = '2000-01-03';
 i1 |            f2            
----+--------------------------
  1 | Mon Jan 03 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_listp WHERE f2 = TO_TIMESTAMP('2000-01-03', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Mon Jan 03 00:00:00 2000
(1 row)

SELECT * FROM TIMESTAMP_MONTH_listp WHERE f2 = TO_DATE('2000-01-03', 'YYYY-MM-DD');
 i1 |            f2            
----+--------------------------
  1 | Mon Jan 03 00:00:00 2000
(1 row)

-- CLEANUP
-- start_ignore
DROP TABLE TIMESTAMP_MONTH_listp;
DROP TABLE TIMESTAMP_MONTH_rangep_STARTEXCL;
DROP TABLE TIMESTAMP_MONTH_rangep_STARTINCL;
-- end_ignore
370 371 372
--
-- Data Engineer can see partition key in psql
--
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
-- SETUP
-- start_ignore
DROP TABLE IF EXISTS T26002_T1;
NOTICE:  table "t26002_t1" does not exist, skipping
DROP TABLE IF EXISTS T26002_T2;
NOTICE:  table "t26002_t2" does not exist, skipping
-- end_ignore
CREATE TABLE T26002_T1 (empid int, departmentid int, year int, region varchar(20))
DISTRIBUTED BY (empid)
  PARTITION BY RANGE (year)
  SUBPARTITION BY LIST (region, departmentid)
    SUBPARTITION TEMPLATE (
       SUBPARTITION usa VALUES (('usa', 1)),
       SUBPARTITION europe VALUES (('europe', 2)),
       SUBPARTITION asia VALUES (('asia', 3)),
       DEFAULT SUBPARTITION other_regions)
( START (2012) END (2015) EVERY (3),
  DEFAULT PARTITION outlying_years);
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_outlying_years" for table "t26002_t1"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_2" for table "t26002_t1"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_outlying_years_2_prt_usa" for table "t26002_t1_1_prt_outlying_years"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_outlying_years_2_prt_europe" for table "t26002_t1_1_prt_outlying_years"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_outlying_years_2_prt_asia" for table "t26002_t1_1_prt_outlying_years"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_outlying_years_2_prt_other_regions" for table "t26002_t1_1_prt_outlying_years"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_2_2_prt_usa" for table "t26002_t1_1_prt_2"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_2_2_prt_europe" for table "t26002_t1_1_prt_2"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_2_2_prt_asia" for table "t26002_t1_1_prt_2"
NOTICE:  CREATE TABLE will create partition "t26002_t1_1_prt_2_2_prt_other_regions" for table "t26002_t1_1_prt_2"
  
-- TEST
-- expected to see the partition key
\d T26002_T1;
         Table "bfv_partition.t26002_t1"
    Column    |         Type          | Modifiers 
--------------+-----------------------+-----------
 empid        | integer               | 
 departmentid | integer               | 
 year         | integer               | 
 region       | character varying(20) | 
Number of child tables: 2 (Use \d+ to list them.)
Distributed by: (empid)
Partition by: (year)

\d t26002_t1_1_prt_2;
     Table "bfv_partition.t26002_t1_1_prt_2"
    Column    |         Type          | Modifiers 
--------------+-----------------------+-----------
 empid        | integer               | 
 departmentid | integer               | 
 year         | integer               | 
 region       | character varying(20) | 
Check constraints:
    "t26002_t1_1_prt_2_check" CHECK (year >= 2012 AND year < 2015)
Inherits: t26002_t1
Number of child tables: 4 (Use \d+ to list them.)
Distributed by: (empid)
Partition by: (region, departmentid)

\d t26002_t1_1_prt_2_2_prt_asia;
Table "bfv_partition.t26002_t1_1_prt_2_2_prt_asia"
    Column    |         Type          | Modifiers 
--------------+-----------------------+-----------
 empid        | integer               | 
 departmentid | integer               | 
 year         | integer               | 
 region       | character varying(20) | 
Check constraints:
    "t26002_t1_1_prt_2_2_prt_asia_check" CHECK (region::text = 'asia'::text AND departmentid = 3)
    "t26002_t1_1_prt_2_check" CHECK (year >= 2012 AND year < 2015)
Inherits: t26002_t1_1_prt_2
Distributed by: (empid)

\d+ T26002_T1;
                      Table "bfv_partition.t26002_t1"
    Column    |         Type          | Modifiers | Storage  | Description 
--------------+-----------------------+-----------+----------+-------------
 empid        | integer               |           | plain    | 
 departmentid | integer               |           | plain    | 
 year         | integer               |           | plain    | 
 region       | character varying(20) |           | extended | 
Child tables: t26002_t1_1_prt_2,
              t26002_t1_1_prt_outlying_years
Has OIDs: no
Distributed by: (empid)
Partition by: (year)

\d+ t26002_t1_1_prt_2;
                  Table "bfv_partition.t26002_t1_1_prt_2"
    Column    |         Type          | Modifiers | Storage  | Description 
--------------+-----------------------+-----------+----------+-------------
 empid        | integer               |           | plain    | 
 departmentid | integer               |           | plain    | 
 year         | integer               |           | plain    | 
 region       | character varying(20) |           | extended | 
Check constraints:
    "t26002_t1_1_prt_2_check" CHECK (year >= 2012 AND year < 2015)
Inherits: t26002_t1
Child tables: t26002_t1_1_prt_2_2_prt_asia,
              t26002_t1_1_prt_2_2_prt_europe,
              t26002_t1_1_prt_2_2_prt_other_regions,
              t26002_t1_1_prt_2_2_prt_usa
Has OIDs: no
Distributed by: (empid)
Partition by: (region, departmentid)

\d+ t26002_t1_1_prt_2_2_prt_asia;
            Table "bfv_partition.t26002_t1_1_prt_2_2_prt_asia"
    Column    |         Type          | Modifiers | Storage  | Description 
--------------+-----------------------+-----------+----------+-------------
 empid        | integer               |           | plain    | 
 departmentid | integer               |           | plain    | 
 year         | integer               |           | plain    | 
 region       | character varying(20) |           | extended | 
Check constraints:
    "t26002_t1_1_prt_2_2_prt_asia_check" CHECK (region::text = 'asia'::text AND departmentid = 3)
    "t26002_t1_1_prt_2_check" CHECK (year >= 2012 AND year < 2015)
Inherits: t26002_t1_1_prt_2
Has OIDs: no
Distributed by: (empid)

/*
-- test 2: Data Engineer won't see partition key for non-partitioned table
GIVEN I am a Data Engineer
WHEN I run \d on a non-partitioned table
THEN I should NOT see the partition key in the output
*/
CREATE TABLE T26002_T2 (empid int, departmentid int, year int, region varchar(20))
DISTRIBUTED BY (empid);
\d T26002_T2;
         Table "bfv_partition.t26002_t2"
    Column    |         Type          | Modifiers 
--------------+-----------------------+-----------
 empid        | integer               | 
 departmentid | integer               | 
 year         | integer               | 
 region       | character varying(20) | 
Distributed by: (empid)

\d+ T26002_T2;
                      Table "bfv_partition.t26002_t2"
    Column    |         Type          | Modifiers | Storage  | Description 
--------------+-----------------------+-----------+----------+-------------
 empid        | integer               |           | plain    | 
 departmentid | integer               |           | plain    | 
 year         | integer               |           | plain    | 
 region       | character varying(20) |           | extended | 
Has OIDs: no
Distributed by: (empid)

-- CLEANUP
-- start_ignore
DROP TABLE IF EXISTS T26002_T1;
DROP TABLE IF EXISTS T26002_T2;
-- end_ignore
-- ************ORCA ENABLED**********
--
-- MPP-23195
--
-- SETUP
-- start_ignore
set optimizer_enable_bitmapscan=on;
set optimizer_enable_indexjoin=on;
drop table if exists mpp23195_t1;
NOTICE:  table "mpp23195_t1" does not exist, skipping
drop table if exists mpp23195_t2;
NOTICE:  table "mpp23195_t2" does not exist, skipping
-- end_ignore
create table mpp23195_t1 (i int) partition by range(i) (partition pt1 start(1) end(10), partition pt2 start(10) end(20));
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.
NOTICE:  CREATE TABLE will create partition "mpp23195_t1_1_prt_pt1" for table "mpp23195_t1"
NOTICE:  CREATE TABLE will create partition "mpp23195_t1_1_prt_pt2" for table "mpp23195_t1"
create index index_mpp23195_t1_i on mpp23195_t1(i);
NOTICE:  building index for child partition "mpp23195_t1_1_prt_pt1"
NOTICE:  building index for child partition "mpp23195_t1_1_prt_pt2"
create table mpp23195_t2(i 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 mpp23195_t1 values (generate_series(1,19));
insert into mpp23195_t2 values (1);
-- TEST
554
select find_operator('select * from mpp23195_t1,mpp23195_t2 where mpp23195_t1.i < mpp23195_t2.i;', 'Dynamic Index Scan');
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
 find_operator 
---------------
 ['false']
(1 row)

select * from mpp23195_t1,mpp23195_t2 where mpp23195_t1.i < mpp23195_t2.i;
 i | i 
---+---
(0 rows)

-- CLEANUP
-- start_ignore
drop table if exists mpp23195_t1;
drop table if exists mpp23195_t2;
set optimizer_enable_bitmapscan=off;
set optimizer_enable_indexjoin=off;
-- end_ignore
572 573 574
--
-- Check we have Dynamic Index Scan operator and check we have Nest loop operator
--
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
-- SETUP
-- start_ignore
drop table if exists mpp21834_t1;
NOTICE:  table "mpp21834_t1" does not exist, skipping
drop table if exists mpp21834_t2;
NOTICE:  table "mpp21834_t2" does not exist, skipping
-- end_ignore
create table mpp21834_t1 (i int, j int) partition by range(i) (partition pp1 start(1) end(10), partition pp2 start(10) end(20));
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.
NOTICE:  CREATE TABLE will create partition "mpp21834_t1_1_prt_pp1" for table "mpp21834_t1"
NOTICE:  CREATE TABLE will create partition "mpp21834_t1_1_prt_pp2" for table "mpp21834_t1"
create index index_1 on mpp21834_t1(i);
NOTICE:  building index for child partition "mpp21834_t1_1_prt_pp1"
NOTICE:  building index for child partition "mpp21834_t1_1_prt_pp2"
create index index_2 on mpp21834_t1(j);
NOTICE:  building index for child partition "mpp21834_t1_1_prt_pp1"
NOTICE:  building index for child partition "mpp21834_t1_1_prt_pp2"
create table mpp21834_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.
-- TEST
-- start_ignore
select disable_xform('CXformInnerJoin2HashJoin');
            disable_xform             
--------------------------------------
 CXformInnerJoin2HashJoin is disabled
(1 row)

-- end_ignore
605
select find_operator('analyze select * from mpp21834_t2,mpp21834_t1 where mpp21834_t2.i < mpp21834_t1.i;','Dynamic Index Scan');
606 607 608 609 610
 find_operator 
---------------
 ['false']
(1 row)

611
select find_operator('analyze select * from mpp21834_t2,mpp21834_t1 where mpp21834_t2.i < mpp21834_t1.i;','Nested Loop');
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
 find_operator 
---------------
 ['true']
(1 row)

-- CLEANUP
-- start_ignore
drop index index_2;
WARNING:  Only dropped the index "index_2"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop index index_1;
WARNING:  Only dropped the index "index_1"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop table if exists mpp21834_t2;
drop table if exists mpp21834_t1;
select enable_xform('CXformInnerJoin2HashJoin');
            enable_xform             
-------------------------------------
 CXformInnerJoin2HashJoin is enabled
(1 row)

-- end_ignore
634 635 636
--
-- A rescanning of DTS with its own partition selector (under sequence node)
--
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
-- SETUP
-- start_ignore
set optimizer_enable_broadcast_nestloop_outer_child=on;
drop table if exists mpp23288;
NOTICE:  table "mpp23288" does not exist, skipping
-- end_ignore
create table mpp23288(a int, b int) 
  partition by range (a)
  (
      PARTITION pfirst  END(5) INCLUSIVE,
      PARTITION pinter  START(5) EXCLUSIVE END (10) INCLUSIVE,
      PARTITION plast   START (10) EXCLUSIVE
  );
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 "mpp23288_1_prt_pfirst" for table "mpp23288"
NOTICE:  CREATE TABLE will create partition "mpp23288_1_prt_pinter" for table "mpp23288"
NOTICE:  CREATE TABLE will create partition "mpp23288_1_prt_plast" for table "mpp23288"
insert into mpp23288(a) select generate_series(1,20);
analyze mpp23288;
-- TEST
658
select count_operator('select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on (t1.a < t2.a and t2.a =10) order by t2.a, t1.a;','Dynamic Table Scan');
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
 count_operator 
----------------
              0
(1 row)

select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on (t1.a < t2.a and t2.a =10) order by t2.a, t1.a;
 a  | a 
----+---
 10 | 1
 10 | 2
 10 | 3
 10 | 4
 10 | 5
 10 | 6
 10 | 7
 10 | 8
 10 | 9
(9 rows)

678
select count_operator('select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on (t1.a < t2.a and (t2.a = 10 or t2.a = 5 or t2.a = 12)) order by t2.a, t1.a;','Dynamic Table Scan');
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
 count_operator 
----------------
              0
(1 row)

select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on (t1.a < t2.a and (t2.a = 10 or t2.a = 5 or t2.a = 12)) order by t2.a, t1.a;
 a  | a  
----+----
  5 |  1
  5 |  2
  5 |  3
  5 |  4
 10 |  1
 10 |  2
 10 |  3
 10 |  4
 10 |  5
 10 |  6
 10 |  7
 10 |  8
 10 |  9
 12 |  1
 12 |  2
 12 |  3
 12 |  4
 12 |  5
 12 |  6
 12 |  7
 12 |  8
 12 |  9
 12 | 10
 12 | 11
(24 rows)

713
select count_operator('select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on t1.a < t2.a and t2.a = 1 or t2.a < 10 order by t2.a, t1.a;','Dynamic Table Scan');
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
 count_operator 
----------------
              0
(1 row)

select t2.a, t1.a from mpp23288 as t1 join mpp23288 as t2 on t1.a < t2.a and t2.a = 1 or t2.a < 10 order by t2.a, t1.a;
 a | a  
---+----
 1 |  1
 1 |  2
 1 |  3
 1 |  4
 1 |  5
 1 |  6
 1 |  7
 1 |  8
 1 |  9
 1 | 10
 1 | 11
 1 | 12
 1 | 13
 1 | 14
 1 | 15
 1 | 16
 1 | 17
 1 | 18
 1 | 19
 1 | 20
 2 |  1
 2 |  2
 2 |  3
 2 |  4
 2 |  5
 2 |  6
 2 |  7
 2 |  8
 2 |  9
 2 | 10
 2 | 11
 2 | 12
 2 | 13
 2 | 14
 2 | 15
 2 | 16
 2 | 17
 2 | 18
 2 | 19
 2 | 20
 3 |  1
 3 |  2
 3 |  3
 3 |  4
 3 |  5
 3 |  6
 3 |  7
 3 |  8
 3 |  9
 3 | 10
 3 | 11
 3 | 12
 3 | 13
 3 | 14
 3 | 15
 3 | 16
 3 | 17
 3 | 18
 3 | 19
 3 | 20
 4 |  1
 4 |  2
 4 |  3
 4 |  4
 4 |  5
 4 |  6
 4 |  7
 4 |  8
 4 |  9
 4 | 10
 4 | 11
 4 | 12
 4 | 13
 4 | 14
 4 | 15
 4 | 16
 4 | 17
 4 | 18
 4 | 19
 4 | 20
 5 |  1
 5 |  2
 5 |  3
 5 |  4
 5 |  5
 5 |  6
 5 |  7
 5 |  8
 5 |  9
 5 | 10
 5 | 11
 5 | 12
 5 | 13
 5 | 14
 5 | 15
 5 | 16
 5 | 17
 5 | 18
 5 | 19
 5 | 20
 6 |  1
 6 |  2
 6 |  3
 6 |  4
 6 |  5
 6 |  6
 6 |  7
 6 |  8
 6 |  9
 6 | 10
 6 | 11
 6 | 12
 6 | 13
 6 | 14
 6 | 15
 6 | 16
 6 | 17
 6 | 18
 6 | 19
 6 | 20
 7 |  1
 7 |  2
 7 |  3
 7 |  4
 7 |  5
 7 |  6
 7 |  7
 7 |  8
 7 |  9
 7 | 10
 7 | 11
 7 | 12
 7 | 13
 7 | 14
 7 | 15
 7 | 16
 7 | 17
 7 | 18
 7 | 19
 7 | 20
 8 |  1
 8 |  2
 8 |  3
 8 |  4
 8 |  5
 8 |  6
 8 |  7
 8 |  8
 8 |  9
 8 | 10
 8 | 11
 8 | 12
 8 | 13
 8 | 14
 8 | 15
 8 | 16
 8 | 17
 8 | 18
 8 | 19
 8 | 20
 9 |  1
 9 |  2
 9 |  3
 9 |  4
 9 |  5
 9 |  6
 9 |  7
 9 |  8
 9 |  9
 9 | 10
 9 | 11
 9 | 12
 9 | 13
 9 | 14
 9 | 15
 9 | 16
 9 | 17
 9 | 18
 9 | 19
 9 | 20
(180 rows)

-- CLEANUP
-- start_ignore
drop table if exists mpp23288;
set optimizer_enable_broadcast_nestloop_outer_child=off;
-- end_ignore
909 910 911
--
-- Testing whether test gives wrong results with partition tables when sub-partitions are distributed differently than the parent partition.
--
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
-- SETUP
-- start_ignore
drop table if exists pt;
NOTICE:  table "pt" does not exist, skipping
drop table if exists t;
NOTICE:  table "t" does not exist, skipping
-- end_ignore
create table pt(a int, b int, c int) distributed by (a) partition by range(b) (start(0) end(10) every (2));
NOTICE:  CREATE TABLE will create partition "pt_1_prt_1" for table "pt"
NOTICE:  CREATE TABLE will create partition "pt_1_prt_2" for table "pt"
NOTICE:  CREATE TABLE will create partition "pt_1_prt_3" for table "pt"
NOTICE:  CREATE TABLE will create partition "pt_1_prt_4" for table "pt"
NOTICE:  CREATE TABLE will create partition "pt_1_prt_5" for table "pt"
alter table pt_1_prt_1 set distributed randomly;
create table t(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 pt select g%10, g%2 + 1, g*2 from generate_series(1,20) g;
insert into pt values(1,1,3);
insert into t select g%10, g%2 + 1 from generate_series(1,20) g;
create index pt_c on pt(c);
NOTICE:  building index for child partition "pt_1_prt_1"
NOTICE:  building index for child partition "pt_1_prt_2"
NOTICE:  building index for child partition "pt_1_prt_3"
NOTICE:  building index for child partition "pt_1_prt_4"
NOTICE:  building index for child partition "pt_1_prt_5"
analyze t;
analyze pt;
-- TEST
SELECT COUNT(*) FROM pt, t WHERE pt.a = t.a;
 count 
-------
    42
(1 row)

SELECT COUNT(*) FROM pt, t WHERE pt.a = t.a and pt.c=4;
 count 
-------
     2
(1 row)

select a, count(*) from pt group by a; 
 a | count 
---+-------
 9 |     2
 8 |     2
 2 |     2
 1 |     3
 0 |     2
 3 |     2
 6 |     2
 7 |     2
 5 |     2
 4 |     2
(10 rows)

select b, count(*) from pt group by b;
 b | count 
---+-------
 2 |    10
 1 |    11
(2 rows)

select a, count(*) from pt where a<2 group by a;
 a | count 
---+-------
 1 |     3
 0 |     2
(2 rows)

-- CLEANUP
-- start_ignore
drop index pt_c;
WARNING:  Only dropped the index "pt_c"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop table if exists pt;
drop table if exists t;
-- end_ignore
990 991 992
--
-- Tests if DynamicIndexScan sets tuple descriptor of the planstate->ps_ResultTupleSlot
--
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
-- SETUP
-- start_ignore
drop table if exists mpp24151_t;
NOTICE:  table "mpp24151_t" does not exist, skipping
drop table if exists mpp24151_pt;
NOTICE:  table "mpp24151_pt" does not exist, skipping
-- end_ignore
create table mpp24151_t(dist int, tid int, t1 text, t2 text);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'dist' 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 mpp24151_pt(dist int, pt1 text, pt2 text, pt3 text, ptid int) 
DISTRIBUTED BY (dist)
PARTITION BY RANGE(ptid) 
          (
          START (0) END (5) EVERY (1),
          DEFAULT PARTITION junk_data
          )
;
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_junk_data" for table "mpp24151_pt"
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_2" for table "mpp24151_pt"
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_3" for table "mpp24151_pt"
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_4" for table "mpp24151_pt"
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_5" for table "mpp24151_pt"
NOTICE:  CREATE TABLE will create partition "mpp24151_pt_1_prt_6" for table "mpp24151_pt"
create index pt1_idx on mpp24151_pt using btree (pt1);
NOTICE:  building index for child partition "mpp24151_pt_1_prt_junk_data"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_2"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_3"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_4"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_5"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_6"
create index ptid_idx on mpp24151_pt using btree (ptid);
NOTICE:  building index for child partition "mpp24151_pt_1_prt_junk_data"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_2"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_3"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_4"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_5"
NOTICE:  building index for child partition "mpp24151_pt_1_prt_6"
insert into mpp24151_pt select i, 'hello' || 0, 'world', 'drop this', i % 6 from generate_series(0,100)i;
insert into mpp24151_pt select i, 'hello' || i, 'world', 'drop this', i % 6 from generate_series(0,200000)i;
insert into mpp24151_t select i, i % 6, 'hello' || i, 'bar' from generate_series(0,10)i;
analyze mpp24151_pt;
analyze mpp24151_t;
-- TEST
-- start_ignore
select disable_xform('CXformDynamicGet2DynamicTableScan');
                 disable_xform                 
-----------------------------------------------
 CXformDynamicGet2DynamicTableScan is disabled
(1 row)

-- end_ignore
1045
select count_operator('select * from mpp24151_t, mpp24151_pt where tid = ptid and pt1 = E''hello0'';','Result');
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
 count_operator 
----------------
              6
(1 row)

select * from mpp24151_t, mpp24151_pt where tid = ptid and pt1 = 'hello0';
 dist | tid |   t1    | t2  | dist |  pt1   |  pt2  |    pt3    | ptid 
------+-----+---------+-----+------+--------+-------+-----------+------
    5 |   5 | hello5  | bar |    5 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   41 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   53 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   77 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   89 | hello0 | world | drop this |    5
    6 |   0 | hello6  | bar |   96 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   96 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   90 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   90 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   54 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   54 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   42 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   42 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   18 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   18 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |    6 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |    6 | hello0 | world | drop this |    0
    7 |   1 | hello7  | bar |    7 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |    7 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   19 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   19 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   55 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   55 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   73 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   73 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   91 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   91 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   97 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   97 | hello0 | world | drop this |    1
    2 |   2 | hello2  | bar |   20 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   20 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   38 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   38 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   56 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   56 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   74 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   74 | hello0 | world | drop this |    2
    3 |   3 | hello3  | bar |    3 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |    3 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   21 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   21 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   39 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   39 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   57 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   57 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   75 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   75 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   87 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   87 | hello0 | world | drop this |    3
    4 |   4 | hello4  | bar |    4 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |    4 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   22 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   22 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   40 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   40 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   76 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   76 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   88 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   88 | hello0 | world | drop this |    4
    5 |   5 | hello5  | bar |   17 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   29 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   35 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   71 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   83 | hello0 | world | drop this |    5
    6 |   0 | hello6  | bar |    0 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |    0 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   84 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   84 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   72 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   72 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   48 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   48 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   36 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   36 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   30 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   30 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |    0 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |    0 | hello0 | world | drop this |    0
    7 |   1 | hello7  | bar |    1 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |    1 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   13 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   13 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   31 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   31 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   37 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   37 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   49 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   49 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   85 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   85 | hello0 | world | drop this |    1
    2 |   2 | hello2  | bar |    2 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |    2 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   14 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   14 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   50 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   50 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   68 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   68 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   86 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   86 | hello0 | world | drop this |    2
    3 |   3 | hello3  | bar |   15 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   15 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   33 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   33 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   51 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   51 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   63 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   63 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   69 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   69 | hello0 | world | drop this |    3
    4 |   4 | hello4  | bar |   16 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   16 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   28 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   28 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   34 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   34 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   52 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   52 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   70 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   70 | hello0 | world | drop this |    4
    5 |   5 | hello5  | bar |   11 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   23 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   47 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   59 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   65 | hello0 | world | drop this |    5
    5 |   5 | hello5  | bar |   95 | hello0 | world | drop this |    5
    6 |   0 | hello6  | bar |   78 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   78 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   66 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   66 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   60 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   60 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   24 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   24 | hello0 | world | drop this |    0
    6 |   0 | hello6  | bar |   12 | hello0 | world | drop this |    0
    0 |   0 | hello0  | bar |   12 | hello0 | world | drop this |    0
    7 |   1 | hello7  | bar |   25 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   25 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   43 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   43 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   61 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   61 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   67 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   67 | hello0 | world | drop this |    1
    7 |   1 | hello7  | bar |   79 | hello0 | world | drop this |    1
    1 |   1 | hello1  | bar |   79 | hello0 | world | drop this |    1
    2 |   2 | hello2  | bar |    8 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |    8 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   26 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   26 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   32 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   32 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   44 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   44 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   62 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   62 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   80 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   80 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   92 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   92 | hello0 | world | drop this |    2
    2 |   2 | hello2  | bar |   98 | hello0 | world | drop this |    2
    8 |   2 | hello8  | bar |   98 | hello0 | world | drop this |    2
    3 |   3 | hello3  | bar |    9 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |    9 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   27 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   27 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   45 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   45 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   81 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   81 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   93 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   93 | hello0 | world | drop this |    3
    3 |   3 | hello3  | bar |   99 | hello0 | world | drop this |    3
    9 |   3 | hello9  | bar |   99 | hello0 | world | drop this |    3
    4 |   4 | hello4  | bar |   10 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   10 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   46 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   46 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   58 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   58 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   64 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   64 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   82 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   82 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |   94 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |   94 | hello0 | world | drop this |    4
    4 |   4 | hello4  | bar |  100 | hello0 | world | drop this |    4
   10 |   4 | hello10 | bar |  100 | hello0 | world | drop this |    4
(188 rows)

-- CLEANUP
-- start_ignore
drop index ptid_idx;
WARNING:  Only dropped the index "ptid_idx"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop index pt1_idx;
WARNING:  Only dropped the index "pt1_idx"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop table if exists mpp24151_t;
drop table if exists mpp24151_pt;
select enable_xform('CXformDynamicGet2DynamicTableScan');
                 enable_xform                 
----------------------------------------------
 CXformDynamicGet2DynamicTableScan is enabled
(1 row)

-- end_ignore
1261 1262 1263
--
-- No DPE (Dynamic Partition Elimination) on second child of a union under a join
--
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
-- SETUP
-- start_ignore
drop table if exists t;
NOTICE:  table "t" does not exist, skipping
drop table if exists p1;
NOTICE:  table "p1" does not exist, skipping
drop table if exists p2;
NOTICE:  table "p2" does not exist, skipping
drop table if exists p3;
NOTICE:  table "p3" does not exist, skipping
drop table if exists p;
NOTICE:  table "p" does not exist, skipping
-- end_ignore
create table p1 (a int, b int) partition by range(b) (start (1) end(100) every (20));
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 "p1_1_prt_1" for table "p1"
NOTICE:  CREATE TABLE will create partition "p1_1_prt_2" for table "p1"
NOTICE:  CREATE TABLE will create partition "p1_1_prt_3" for table "p1"
NOTICE:  CREATE TABLE will create partition "p1_1_prt_4" for table "p1"
NOTICE:  CREATE TABLE will create partition "p1_1_prt_5" for table "p1"
create table p2 (a int, b int) partition by range(b) (start (1) end(100) every (20));
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 "p2_1_prt_1" for table "p2"
NOTICE:  CREATE TABLE will create partition "p2_1_prt_2" for table "p2"
NOTICE:  CREATE TABLE will create partition "p2_1_prt_3" for table "p2"
NOTICE:  CREATE TABLE will create partition "p2_1_prt_4" for table "p2"
NOTICE:  CREATE TABLE will create partition "p2_1_prt_5" for table "p2"
create table p3 (a int, b int) partition by range(b) (start (1) end(100) every (20));
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 "p3_1_prt_1" for table "p3"
NOTICE:  CREATE TABLE will create partition "p3_1_prt_2" for table "p3"
NOTICE:  CREATE TABLE will create partition "p3_1_prt_3" for table "p3"
NOTICE:  CREATE TABLE will create partition "p3_1_prt_4" for table "p3"
NOTICE:  CREATE TABLE will create partition "p3_1_prt_5" for table "p3"
create table p (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.
create table t(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 t select g, g*10 from generate_series(1,100) g;
insert into p1 select g, g%99 +1 from generate_series(1,10000) g;
insert into p2 select g, g%99 +1 from generate_series(1,10000) g;
insert into p3 select g, g%99 +1 from generate_series(1,10000) g;
insert into p select g, g%99 +1 from generate_series(1,10000) g;
analyze t;
analyze p1;
analyze p2;
analyze p3;
analyze p;
-- TEST
1318
select count_operator('select * from (select * from p1 union all select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1319 1320 1321 1322 1323
 count_operator 
----------------
              0
(1 row)

1324
select count_operator('select * from (select * from p1 union select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1325 1326 1327 1328 1329
 count_operator 
----------------
              0
(1 row)

1330
select count_operator('select * from (select * from p1 except all select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1331 1332 1333 1334 1335
 count_operator 
----------------
              0
(1 row)

1336
select count_operator('select * from (select * from p1 except select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1337 1338 1339 1340 1341
 count_operator 
----------------
              0
(1 row)

1342
select count_operator('select * from (select * from p1 intersect all select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1343 1344 1345 1346 1347
 count_operator 
----------------
              0
(1 row)

1348
select count_operator('select * from (select * from p1 union select * from p2 union all select * from p3) as p_all, t where p_all.b=t.b;','Partition Selector');
1349 1350 1351 1352 1353
 count_operator 
----------------
              0
(1 row)

1354
select count_operator('select * from (select * from p1 union select * from p2 union all select * from p) as p_all, t where p_all.b=t.b;','Partition Selector');
1355 1356 1357 1358 1359
 count_operator 
----------------
              0
(1 row)

1360
select count_operator('select * from (select * from p1 union select * from p union all select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1361 1362 1363 1364 1365
 count_operator 
----------------
              0
(1 row)

1366
select count_operator('select * from (select * from p1 union select * from p2 intersect all select * from p3) as p_all, t where p_all.b=t.b;','Partition Selector');
1367 1368 1369 1370 1371
 count_operator 
----------------
              0
(1 row)

1372
select count_operator('select * from (select * from p1 union select * from p intersect all select * from p2) as p_all, t where p_all.b=t.b;','Partition Selector');
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
 count_operator 
----------------
              0
(1 row)

-- CLEANUP
-- start_ignore
drop table t;
drop table p1;
drop table p2;
drop table p3;
drop table p;
-- end_ignore
1386 1387 1388
--
-- Gracefully handle NULL partition set from BitmapTableScan, DynamicTableScan and DynamicIndexScan
--
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
-- SETUP
-- start_ignore
drop table if exists dts;
NOTICE:  table "dts" does not exist, skipping
drop table if exists dis;
NOTICE:  table "dis" does not exist, skipping
drop table if exists dbs;
NOTICE:  table "dbs" does not exist, skipping
-- end_ignore
create table dts(c1 int, c2 int) partition by range(c2) (start(1) end(11) every(1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' 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 "dts_1_prt_1" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_2" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_3" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_4" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_5" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_6" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_7" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_8" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_9" for table "dts"
NOTICE:  CREATE TABLE will create partition "dts_1_prt_10" for table "dts"
create table dis(c1 int, c2 int, c3 int) partition by range(c2) (start(1) end(11) every(1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' 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 "dis_1_prt_1" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_2" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_3" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_4" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_5" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_6" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_7" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_8" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_9" for table "dis"
NOTICE:  CREATE TABLE will create partition "dis_1_prt_10" for table "dis"
create index dis_index on dis(c3);
NOTICE:  building index for child partition "dis_1_prt_1"
NOTICE:  building index for child partition "dis_1_prt_2"
NOTICE:  building index for child partition "dis_1_prt_3"
NOTICE:  building index for child partition "dis_1_prt_4"
NOTICE:  building index for child partition "dis_1_prt_5"
NOTICE:  building index for child partition "dis_1_prt_6"
NOTICE:  building index for child partition "dis_1_prt_7"
NOTICE:  building index for child partition "dis_1_prt_8"
NOTICE:  building index for child partition "dis_1_prt_9"
NOTICE:  building index for child partition "dis_1_prt_10"
CREATE TABLE dbs(c1 int, c2 int, c3 int) partition by range(c2) (start(1) end(11) every(1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' 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 "dbs_1_prt_1" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_2" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_3" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_4" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_5" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_6" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_7" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_8" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_9" for table "dbs"
NOTICE:  CREATE TABLE will create partition "dbs_1_prt_10" for table "dbs"
create index dbs_index on dbs using bitmap(c3);
NOTICE:  building index for child partition "dbs_1_prt_1"
NOTICE:  building index for child partition "dbs_1_prt_2"
NOTICE:  building index for child partition "dbs_1_prt_3"
NOTICE:  building index for child partition "dbs_1_prt_4"
NOTICE:  building index for child partition "dbs_1_prt_5"
NOTICE:  building index for child partition "dbs_1_prt_6"
NOTICE:  building index for child partition "dbs_1_prt_7"
NOTICE:  building index for child partition "dbs_1_prt_8"
NOTICE:  building index for child partition "dbs_1_prt_9"
NOTICE:  building index for child partition "dbs_1_prt_10"
-- TEST
1460
select find_operator('(select * from dts where c2 = 1) union (select * from dts where c2 = 2) union (select * from dts where c2 = 3) union (select * from dts where c2 = 4) union (select * from dts where c2 = 5) union (select * from dts where c2 = 6) union (select * from dts where c2 = 7) union (select * from dts where c2 = 8) union (select * from dts where c2 = 9) union (select * from dts where c2 = 10);', 'Dynamic Table Scan');
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
 find_operator 
---------------
 ['false']
(1 row)

(select * from dts where c2 = 1) union
(select * from dts where c2 = 2) union
(select * from dts where c2 = 3) union
(select * from dts where c2 = 4) union
(select * from dts where c2 = 5) union
(select * from dts where c2 = 6) union
(select * from dts where c2 = 7) union
(select * from dts where c2 = 8) union
(select * from dts where c2 = 9) union
(select * from dts where c2 = 10);
 c1 | c2 
----+----
(0 rows)

-- start_ignore
select disable_xform('CXformDynamicGet2DynamicTableScan');
                 disable_xform                 
-----------------------------------------------
 CXformDynamicGet2DynamicTableScan is disabled
(1 row)

-- end_ignore
1488
select find_operator('(select * from dis where c3 = 1) union (select * from dis where c3 = 2) union (select * from dis where c3 = 3) union (select * from dis where c3 = 4) union (select * from dis where c3 = 5) union (select * from dis where c3 = 6) union (select * from dis where c3 = 7) union (select * from dis where c3 = 8) union (select * from dis where c3 = 9) union (select * from dis where c3 = 10);', 'Dynamic Index Scan');
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
 find_operator 
---------------
 ['false']
(1 row)

(select * from dis where c3 = 1) union
(select * from dis where c3 = 2) union
(select * from dis where c3 = 3) union
(select * from dis where c3 = 4) union
(select * from dis where c3 = 5) union
(select * from dis where c3 = 6) union
(select * from dis where c3 = 7) union
(select * from dis where c3 = 8) union
(select * from dis where c3 = 9) union
(select * from dis where c3 = 10);
 c1 | c2 | c3 
----+----+----
(0 rows)

1508
select find_operator('select * from dbs where c2= 15 and c3 = 5;', 'Bitmap Table Scan');
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
 find_operator 
---------------
 ['false']
(1 row)

select * from dbs where c2= 15 and c3 = 5;
 c1 | c2 | c3 
----+----+----
(0 rows)

-- CLEANUP
-- start_ignore
drop index dbs_index;
WARNING:  Only dropped the index "dbs_index"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop table if exists dbs;
drop index dis_index;
WARNING:  Only dropped the index "dis_index"
HINT:  To drop other indexes on child partitions, drop each one explicitly.
drop table if exists dis;
drop table if exists dts;
select enable_xform('CXformDynamicGet2DynamicTableScan');
                 enable_xform                 
----------------------------------------------
 CXformDynamicGet2DynamicTableScan is enabled
(1 row)

-- end_ignore
1537 1538 1539
--
-- Partition elimination for heterogenous DynamicIndexScans
--
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
-- SETUP
-- start_ignore
drop table if exists pp;
NOTICE:  table "pp" does not exist, skipping
drop index if exists pp_1_prt_1_idx;
NOTICE:  index "pp_1_prt_1_idx" does not exist, skipping
drop index if exists pp_rest_1_idx;
NOTICE:  index "pp_rest_1_idx" does not exist, skipping
drop index if exists pp_rest_2_idx;
NOTICE:  index "pp_rest_2_idx" does not exist, skipping
set optimizer_segments=2;
set optimizer_partition_selection_log=on;
-- end_ignore
create table pp(a int, b int, c int) partition by range(b) (start(1) end(15) every(5));
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 "pp_1_prt_1" for table "pp"
NOTICE:  CREATE TABLE will create partition "pp_1_prt_2" for table "pp"
NOTICE:  CREATE TABLE will create partition "pp_1_prt_3" for table "pp"
insert into pp values (1,1,2),(2,6,2), (3,11,2);
-- Heterogeneous Index on the partition table
create index pp_1_prt_1_idx on pp_1_prt_1(c);
-- Create other indexes so that we can automate the repro for MPP-21069 by disabling tablescan
create index pp_rest_1_idx on pp_1_prt_2(c,a);
create index pp_rest_2_idx on pp_1_prt_3(c,a);
-- TEST
-- start_ignore
select disable_xform('CXformDynamicGet2DynamicTableScan') ;
                 disable_xform                 
-----------------------------------------------
 CXformDynamicGet2DynamicTableScan is disabled
(1 row)

-- end_ignore
select * from pp where b=2 and c=2;
 a | b | c 
---+---+---
(0 rows)

1579
select count_operator('select * from pp where b=2 and c=2;','Partition Selector');
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
 count_operator 
----------------
              0
(1 row)

-- CLEANUP
-- start_ignore
drop index if exists pp_rest_2_idx;
drop index if exists pp_rest_1_idx;
drop index if exists pp_1_prt_1_idx;
drop table if exists pp;
select enable_xform('CXformDynamicGet2DynamicTableScan') ;
                 enable_xform                 
----------------------------------------------
 CXformDynamicGet2DynamicTableScan is enabled
(1 row)

reset optimizer_segments;
set optimizer_partition_selection_log=off;
select enable_xform('CXformDynamicGet2DynamicTableScan') ;
                 enable_xform                 
----------------------------------------------
 CXformDynamicGet2DynamicTableScan is enabled
(1 row)

-- end_ignore
1606 1607 1608
--
-- Partition elimination with implicit CAST on the partitioning key
--
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
-- SETUP
-- start_ignore
set optimizer_segments=2;
set optimizer_partition_selection_log=on;
DROP TABLE IF EXISTS ds_4;
NOTICE:  table "ds_4" does not exist, skipping
-- end_ignore
CREATE TABLE ds_4
(
  month_id character varying(6),
  cust_group_acc numeric(10),
  mobile_no character varying(10)
)
DISTRIBUTED BY (cust_group_acc, mobile_no)
PARTITION BY LIST(month_id)
          (
          PARTITION p200800 VALUES('200800'),
          PARTITION p200801 VALUES('200801'),
          PARTITION p200802 VALUES('200802'),
          PARTITION p200803 VALUES('200803')
);
NOTICE:  CREATE TABLE will create partition "ds_4_1_prt_p200800" for table "ds_4"
NOTICE:  CREATE TABLE will create partition "ds_4_1_prt_p200801" for table "ds_4"
NOTICE:  CREATE TABLE will create partition "ds_4_1_prt_p200802" for table "ds_4"
NOTICE:  CREATE TABLE will create partition "ds_4_1_prt_p200803" for table "ds_4"
-- TEST
select * from ds_4 where month_id = '200800';
 month_id | cust_group_acc | mobile_no 
----------+----------------+-----------
(0 rows)

1640
select count_operator('select * from ds_4 where month_id = E''200800'';','Partition Selector');
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
 count_operator 
----------------
              0
(1 row)

select * from ds_4 where month_id > '200800';
 month_id | cust_group_acc | mobile_no 
----------+----------------+-----------
(0 rows)

1651
select count_operator('select * from ds_4 where month_id > E''200800'';','Partition Selector');
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661
 count_operator 
----------------
              0
(1 row)

select * from ds_4 where month_id <= '200800';
 month_id | cust_group_acc | mobile_no 
----------+----------------+-----------
(0 rows)

1662
select count_operator('select * from ds_4 where month_id <= E''200800'';','Partition Selector');
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
 count_operator 
----------------
              0
(1 row)

select * from ds_4 a1,ds_4 a2 where a1.month_id = a2.month_id and a1.month_id > '200800';
 month_id | cust_group_acc | mobile_no | month_id | cust_group_acc | mobile_no 
----------+----------------+-----------+----------+----------------+-----------
(0 rows)

1673
select count_operator('select * from ds_4 a1,ds_4 a2 where a1.month_id = a2.month_id and a1.month_id > E''200800'';','Partition Selector');
1674 1675
 count_operator 
----------------
1676
              1
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
(1 row)

-- CLEANUP
-- start_ignore
DROP TABLE IF EXISTS ds_4;
set optimizer_partition_selection_log=off;
reset optimizer_segments;
drop function if exists find_operator(query text, operator_name text);
drop function if exists count_operator(query text, operator_name text);
-- end_ignore
1687 1688 1689
--
-- Partition table with appendonly leaf, full join
--
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
-- SETUP
-- 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 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.
CREATE TABLE bar (b int, c int)
PARTITION BY RANGE (b)
  SUBPARTITION BY RANGE (c) SUBPARTITION TEMPLATE 
  (
    START (1) END (10) WITH (appendonly=true),
    START (10) END (20)
  ) 
( 
  START (1) END (10) ,
  START (10) END (20)
); 
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'b' 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 "bar_1_prt_1" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_1" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_2" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_1" for table "bar_1_prt_2"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_2" for table "bar_1_prt_2"
1718
-- end_ignore
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
INSERT INTO foo VALUES (1);
INSERT INTO bar VALUES (2,3);
SELECT * FROM foo FULL JOIN bar ON foo.a = bar.b;
 a | b | c 
---+---+---
 1 |   |  
   | 2 | 3
(2 rows)

-- CLEANUP
-- start_ignore
DROP TABLE IF EXISTS foo;
DROP TABLE IF EXISTS bar;
-- end_ignore
1733 1734 1735
--
-- Partition table with appendonly set at middlevel partition, full join
--
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
-- SETUP
-- 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 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.
CREATE TABLE bar (b int, c int)
PARTITION BY RANGE (b)
  SUBPARTITION BY RANGE (c) SUBPARTITION TEMPLATE 
  (
    START (1) END (10),
    START (10) END (20)
  ) 
( 
  START (1) END (10) WITH (appendonly=true),
  START (10) END (20)
); 
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'b' 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 "bar_1_prt_1" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_1" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_2" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_1" for table "bar_1_prt_2"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_2" for table "bar_1_prt_2"
1764
-- end_ignore
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
INSERT INTO foo VALUES (1);
INSERT INTO bar VALUES (2,3);
SELECT * FROM foo FULL JOIN bar ON foo.a = bar.b;
 a | b | c 
---+---+---
 1 |   |  
   | 2 | 3
(2 rows)

-- CLEANUP
-- start_ignore
DROP TABLE IF EXISTS foo;
DROP TABLE IF EXISTS bar;
-- end_ignore
1779 1780 1781
--
-- Partition table with appendonly set at root partition, full join
--
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809
-- SETUP
-- 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 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.
CREATE TABLE bar (b int, c int) WITH (appendonly=true)
PARTITION BY RANGE (b)
  SUBPARTITION BY RANGE (c) SUBPARTITION TEMPLATE 
  (
    START (1) END (10),
    START (10) END (20)
  ) 
( 
  START (1) END (10),
  START (10) END (20)
); 
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'b' 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 "bar_1_prt_1" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_1" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_1_2_prt_2" for table "bar_1_prt_1"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_1" for table "bar_1_prt_2"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2_2_prt_2" for table "bar_1_prt_2"
1810
-- end_ignore
1811 1812 1813 1814 1815 1816 1817 1818 1819
INSERT INTO foo VALUES (1);
INSERT INTO bar VALUES (2,3);
SELECT * FROM foo FULL JOIN bar ON foo.a = bar.b;
 a | b | c 
---+---+---
 1 |   |  
   | 2 | 3
(2 rows)

1820 1821 1822
--
-- Test a hash agg that has a Sequence + Partition Selector below it.
--
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
-- SETUP
-- start_ignore
DROP TABLE IF EXISTS bar;
-- end_ignore
CREATE TABLE bar (b int, c int)
PARTITION BY RANGE (b)
(
  START (0) END (10),
  START (10) END (20)
);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'b' 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 "bar_1_prt_1" for table "bar"
NOTICE:  CREATE TABLE will create partition "bar_1_prt_2" for table "bar"
INSERT INTO bar SELECT g % 20, g % 20 from generate_series(1, 1000) g;
ANALYZE bar;
SELECT b FROM bar GROUP BY b;
 b  
----
  7
  4
 19
  3
  5
 18
  6
 11
  9
  8
 12
 10
 17
  1
  0
  2
 16
 15
 14
 13
(20 rows)

EXPLAIN SELECT b FROM bar GROUP BY b;
                                    QUERY PLAN                                     
-----------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=18.50..18.60 rows=10 width=4)
   ->  HashAggregate  (cost=18.50..18.60 rows=4 width=4)
         Group By: bfv_partition.bar.b
         ->  Append  (cost=0.00..16.00 rows=334 width=4)
               ->  Seq Scan on bar_1_prt_1 bar  (cost=0.00..8.00 rows=167 width=4)
               ->  Seq Scan on bar_1_prt_2 bar  (cost=0.00..8.00 rows=167 width=4)
 Optimizer status: legacy query optimizer
(7 rows)

1876 1877 1878
-- CLEANUP
DROP TABLE IF EXISTS foo;
DROP TABLE IF EXISTS bar;
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
-- Test EXPLAIN ANALYZE on a partitioned table. There used to be a bug, where
-- you got an internal error with this, because the EXPLAIN ANALYZE sends the
-- stats from QEs to the QD at the end of query, but because the subnodes are
-- terminated earlier, their stats were already gone.
create table mpp8031 (oid integer,
odate timestamp without time zone,
cid integer)
PARTITION BY RANGE(odate)
(
PARTITION foo START ('2005-05-01 00:00:00'::timestamp
without time zone) END ('2005-07-01 00:00:00'::timestamp
without time zone) EVERY ('2 mons'::interval),
START ('2005-07-01 00:00:00'::timestamp without time zone)
END ('2006-01-01 00:00:00'::timestamp without time zone)
EVERY ('2 mons'::interval)
);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'oid' 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 "mpp8031_1_prt_foo" for table "mpp8031"
NOTICE:  CREATE TABLE will create partition "mpp8031_1_prt_2" for table "mpp8031"
NOTICE:  CREATE TABLE will create partition "mpp8031_1_prt_3" for table "mpp8031"
NOTICE:  CREATE TABLE will create partition "mpp8031_1_prt_4" for table "mpp8031"
explain analyze select a.* from mpp8031 a, mpp8031 b where a.oid = b.oid;
                                           QUERY PLAN                                            
-------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=6799.00..1021796.00 rows=80883360 width=16)
   Rows out:  0 rows at destination with 1.011 ms to end, start offset by 0.365 ms.
   ->  Hash Join  (cost=6799.00..1021796.00 rows=26961120 width=16)
         Hash Cond: a.oid = b.oid
         Rows out:  0 rows (seg0) with 0.051 ms to end, start offset by 1.246 ms.
         ->  Append  (cost=0.00..3244.00 rows=94800 width=16)
               Rows out:  0 rows (seg0) with 0.051 ms to end, start offset by 1.246 ms.
               ->  Seq Scan on mpp8031_1_prt_foo a  (cost=0.00..811.00 rows=23700 width=16)
                     Rows out:  0 rows (seg0) with 0.022 ms to end, start offset by 1.247 ms.
               ->  Seq Scan on mpp8031_1_prt_2 a  (cost=0.00..811.00 rows=23700 width=16)
                     Rows out:  0 rows (seg0) with 0.009 ms to end, start offset by 1.270 ms.
               ->  Seq Scan on mpp8031_1_prt_3 a  (cost=0.00..811.00 rows=23700 width=16)
                     Rows out:  0 rows (seg0) with 0.009 ms to end, start offset by 1.279 ms.
               ->  Seq Scan on mpp8031_1_prt_4 a  (cost=0.00..811.00 rows=23700 width=16)
                     Rows out:  0 rows (seg0) with 0.008 ms to end, start offset by 1.288 ms.
         ->  Hash  (cost=3244.00..3244.00 rows=94800 width=4)
               Rows in:  (No row requested) 0 rows (seg0) with 0 ms to end.
               ->  Append  (cost=0.00..3244.00 rows=94800 width=4)
                     Rows out:  (No row requested) 0 rows (seg0) with 0 ms to end.
                     ->  Seq Scan on mpp8031_1_prt_foo b  (cost=0.00..811.00 rows=23700 width=4)
                           Rows out:  (No row requested) 0 rows (seg0) with 0 ms to end.
                     ->  Seq Scan on mpp8031_1_prt_2 b  (cost=0.00..811.00 rows=23700 width=4)
                           Rows out:  (No row requested) 0 rows (seg0) with 0 ms to end.
                     ->  Seq Scan on mpp8031_1_prt_3 b  (cost=0.00..811.00 rows=23700 width=4)
                           Rows out:  (No row requested) 0 rows (seg0) with 0 ms to end.
                     ->  Seq Scan on mpp8031_1_prt_4 b  (cost=0.00..811.00 rows=23700 width=4)
                           Rows out:  (No row requested) 0 rows (seg0) with 0 ms to end.
 Slice statistics:
   (slice0)    Executor memory: 382K bytes.
   (slice1)    Executor memory: 146K bytes avg x 3 workers, 146K bytes max (seg0).
 Statement statistics:
   Memory used: 128000K bytes
 Optimizer status: legacy query optimizer
 Total runtime: 2.045 ms
(34 rows)

drop table mpp8031;
-- CLEANUP
-- start_ignore
1943 1944
drop schema if exists bfv_partition;
-- end_ignore