qp_orca_fallback.out 7.3 KB
Newer Older
V
Venkatesh Raghavan 已提交
1
-- Test the optimizer_enable_dml_constraints GUC, which forces GPORCA to fall back when there
2 3 4 5 6
-- are NULL or CHECK constraints on a table.
set optimizer_trace_fallback = on;
DROP TABLE IF EXISTS constr_tab;
NOTICE:  table "constr_tab" does not exist, skipping
CREATE TABLE constr_tab ( a int check (a>0) , b int, c int, d int, CHECK (a+b>5)) DISTRIBUTED BY (a);
V
Venkatesh Raghavan 已提交
7
set optimizer_enable_dml_constraints = off;
8 9 10
explain insert into constr_tab values (1,2,3);
                   QUERY PLAN                   
------------------------------------------------
A
Asim R P 已提交
11
 Insert on constr_tab  (cost=0.00..0.01 rows=1 width=0)
12
   ->  Result  (cost=0.00..0.01 rows=1 width=0)
13
 Optimizer status: Postgres query optimizer
14 15
(3 rows)

V
Venkatesh Raghavan 已提交
16
set optimizer_enable_dml_constraints=on;
17 18 19
explain insert into constr_tab values (1,2,3);
                   QUERY PLAN                   
------------------------------------------------
A
Asim R P 已提交
20
 Insert on constr_tab  (cost=0.00..0.01 rows=1 width=0)
21
   ->  Result  (cost=0.00..0.01 rows=1 width=0)
22
 Optimizer status: Postgres query optimizer
23 24 25 26
(3 rows)

-- The remaining tests require a row in the table.
INSERT INTO constr_tab VALUES(1,5,3,4);
V
Venkatesh Raghavan 已提交
27
set optimizer_enable_dml_constraints=off;
28
explain update constr_tab set a = 10;
29 30 31 32 33 34 35
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
   ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=22)
         Hash Key: a
         ->  Split  (cost=0.00..1.01 rows=1 width=22)
               ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
36
 Optimizer: Postgres query optimizer
37 38
(6 rows)

39 40 41
explain update constr_tab set b = 10;
                           QUERY PLAN                            
-----------------------------------------------------------------
A
Asim R P 已提交
42
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
43
   ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
44
 Optimizer status: Postgres query optimizer
45 46
(3 rows)

V
Venkatesh Raghavan 已提交
47
set optimizer_enable_dml_constraints=on;
48 49 50
explain update constr_tab set b = 10;
                           QUERY PLAN                            
-----------------------------------------------------------------
A
Asim R P 已提交
51
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
52
   ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
53
 Optimizer status: Postgres query optimizer
54 55 56 57 58 59
(3 rows)

-- Same, with NOT NULL constraint.
DROP TABLE IF EXISTS constr_tab;
CREATE TABLE constr_tab ( a int NOT NULL, b int, c int, d int, CHECK (a+b>5)) DISTRIBUTED BY (a);
INSERT INTO constr_tab VALUES(1,5,3,4);
V
Venkatesh Raghavan 已提交
60
set optimizer_enable_dml_constraints=off;
61
explain update constr_tab set a = 10;
62 63 64 65 66 67 68
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
   ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=22)
         Hash Key: a
         ->  Split  (cost=0.00..1.01 rows=1 width=22)
               ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
69
 Optimizer: Postgres query optimizer
70 71
(6 rows)

72 73 74 75
DROP TABLE IF EXISTS constr_tab;
CREATE TABLE constr_tab ( a int NOT NULL, b int NOT NULL, c int NOT NULL, d int NOT NULL) DISTRIBUTED BY (a,b);
INSERT INTO constr_tab VALUES(1,5,3,4);
INSERT INTO constr_tab VALUES(1,5,3,4);
V
Venkatesh Raghavan 已提交
76
set optimizer_enable_dml_constraints=off;
77
explain update constr_tab set b = 10;
78 79 80 81 82 83 84
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
   ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=22)
         Hash Key: a, b
         ->  Split  (cost=0.00..1.01 rows=1 width=22)
               ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
85
 Optimizer: Postgres query optimizer
86 87
(6 rows)

88 89 90 91
DROP TABLE IF EXISTS constr_tab;
CREATE TABLE constr_tab ( a int, b int, c int, d int) DISTRIBUTED BY (a);
INSERT INTO constr_tab VALUES(1,5,3,4);
INSERT INTO constr_tab VALUES(1,5,3,4);
V
Venkatesh Raghavan 已提交
92
set optimizer_enable_dml_constraints=off;
93
explain update constr_tab set a = 10;
94 95 96 97 98 99 100
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Update on constr_tab  (cost=0.00..1.01 rows=1 width=22)
   ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=22)
         Hash Key: a
         ->  Split  (cost=0.00..1.01 rows=1 width=22)
               ->  Seq Scan on constr_tab  (cost=0.00..1.01 rows=1 width=22)
101
 Optimizer: Postgres query optimizer
102 103
(6 rows)

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
-- Test ORCA fallback on "FROM ONLY"
CREATE TABLE homer (a int, b int, c int)
DISTRIBUTED BY (a)
PARTITION BY range(b)
    SUBPARTITION BY range(c)
        SUBPARTITION TEMPLATE (
            START(40) END(46) EVERY(3)
        )
(START(0) END(4) EVERY(2));
INSERT INTO homer VALUES (1,0,40),(2,1,43),(3,2,41),(4,3,44);
SELECT * FROM ONLY homer;
 a | b | c 
---+---+---
(0 rows)

SELECT * FROM ONLY homer_1_prt_1;
 a | b | c 
---+---+---
(0 rows)

UPDATE ONLY homer SET c = c + 1;
SELECT * FROM homer;
 a | b | c  
---+---+----
 1 | 0 | 40
 2 | 1 | 43
 3 | 2 | 41
 4 | 3 | 44
(4 rows)

DELETE FROM ONLY homer WHERE a = 3;
SELECT * FROM homer;
 a | b | c  
---+---+----
 1 | 0 | 40
 2 | 1 | 43
 3 | 2 | 41
 4 | 3 | 44
(4 rows)

144
-- ORCA should not fallback just because external tables are in FROM clause
145 146 147 148 149 150 151 152 153
-- start_ignore
CREATE TABLE heap_t1 (a int, b int) DISTRIBUTED BY (b);
CREATE EXTERNAL TABLE ext_table_no_fallback (a int, b int) LOCATION ('gpfdist://myhost:8080/test.csv') FORMAT 'CSV';
-- end_ignore
EXPLAIN SELECT * FROM ext_table_no_fallback;
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..11000.00 rows=1000000 width=8)
   ->  External Scan on ext_table_no_fallback  (cost=0.00..11000.00 rows=333334 width=8)
154
 Optimizer: Postgres query optimizer
155 156 157 158 159 160 161
(3 rows)

EXPLAIN SELECT * FROM ONLY ext_table_no_fallback;
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..11000.00 rows=1000000 width=8)
   ->  External Scan on ext_table_no_fallback  (cost=0.00..11000.00 rows=333334 width=8)
162
 Optimizer: Postgres query optimizer
163 164 165 166 167 168 169 170 171
(3 rows)

EXPLAIN INSERT INTO heap_t1 SELECT * FROM ONLY ext_table_no_fallback;
                                           QUERY PLAN                                            
-------------------------------------------------------------------------------------------------
 Insert on heap_t1  (cost=0.00..11000.00 rows=333334 width=8)
   ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..11000.00 rows=333334 width=8)
         Hash Key: ext_table_no_fallback.b
         ->  External Scan on ext_table_no_fallback  (cost=0.00..11000.00 rows=333334 width=8)
172
 Optimizer: Postgres query optimizer
173 174
(5 rows)