gpdist_legacy_opclasses_optimizer.out 9.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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
--
-- Tests for legacy cdbhash opclasses
--
-- Basic sanity check of all the legacy hash opclasses. Create a table that
-- uses all of them in the distribution key, and insert a value.
set gp_use_legacy_hashops=on;
create table all_legacy_types(
  int2_col int2,
  int4_col int4,
  int8_col int8,
  float4_col float4,
  float8_col float8,
  numeric_col numeric,
  char_col "char",
  bpchar_col char(20),
  text_col text,
  varchar_col varchar(20),
  bytea_col bytea,
  name_col name,
  oid_col oid,
  tid_col tid,
  timestamp_col timestamp,
  timestamptz_col timestamptz,
  date_col date,
  time_col time,
  timetz_col timetz,
  interval_col interval,
  abstime_col abstime,
  tinterval_col tinterval,
  inet_col inet,
  cidr_col cidr,
  macaddr_col macaddr,
  bit_col bit(11),
  varbit_col varbit(20),
  bool_col bool,
  oidvector_col oidvector,
  money_col money,
  --uuid_col uuid,
  complex_col complex
) distributed by (
  int2_col,
  int4_col,
  int8_col,
  float4_col,
  float8_col,
  numeric_col,
  char_col,
  bpchar_col,
  text_col,
  varchar_col,
  bytea_col,
  name_col,
  oid_col,
  tid_col,
  timestamp_col,
  timestamptz_col,
  date_col,
  time_col,
  timetz_col,
  interval_col,
  abstime_col,
  tinterval_col,
  inet_col,
  cidr_col,
  macaddr_col,
  bit_col,
  varbit_col,
  bool_col,
  oidvector_col,
  money_col,
  --uuid_col,
  complex_col
);
-- Verify that all columns are using the legacy hashops
select distkey, distclass from gp_distribution_policy where localoid='all_legacy_types'::regclass;
                                       distkey                                       |                                                                                         distclass                                                                                         
-------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 10165 10166 10167 10168 10169 10170 10171 10174 10172 10172 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10187 10188 10188 10189 10190 10190 10192 10194 10195 10196
(1 row)

insert into all_legacy_types values (
  '12345',          -- int2
  '12345678',       -- int4
  '1234567890123',  -- int8
  '1.2345',         -- float4
  '1.23456789',     -- float8
  '1.23456789',     -- numeric
  'x',              -- "char"
  'bpchar foobar',  -- bpchar
  'text foobar',     -- text
  'varchar foobar', -- varchar
  '\xdeadbeef',     -- bytea
  'name foobar',    -- name
  '12345',          -- oid
  '(1,1)',          -- tid
  '2018-11-25 01:23:45+02',   -- timestamp
  '2018-11-25 01:23:45+02',   -- timestamptz
  '2018-11-25',     -- date,
  '01:23:45',       -- time,
  '01:23:45+02',    -- timetz,
  '6 years',        -- interval,
  'Mon May  1 00:30:30 1995', -- abstime,
  '["Feb 15 1990 12:15:03" "2001-09-23 11:12:13"]', -- tinterval,
  '192.168.1.255/25',   -- inet,
  '10.1.2',         -- cidr,
  '08:00:2b:01:02:03',         -- macaddr,
  B'11011000000',   -- bit,
  B'01010101010',   -- varbit,
  'true',        -- bool,
  '1 2 3 4',        -- oidvector,
  '123.45',        -- money,
  --uuid_col         -- uuid,
  '5 + 3i'         -- complex
);
set gp_use_legacy_hashops=off;
--
-- Test joins between tables using a mix of default and legacy opclasses.
--
create table legacy_int (id int4) distributed by (id cdbhash_int4_ops);
insert into legacy_int values (1), (2), (3);
create table modern_int (id int4) distributed by (id);
insert into modern_int values (2), (3), (4);
create table modern_text (t text) distributed by (t);
insert into modern_text values ('foo'), ('1');
-- Only legacy opclasses used. ORCA can deal with this
explain (costs off) select * from legacy_int a inner join legacy_int b on a.id = b.id;
                      QUERY PLAN                       
-------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: (legacy_int.id = legacy_int_1.id)
         ->  Seq Scan on legacy_int
         ->  Hash
               ->  Seq Scan on legacy_int legacy_int_1
 Optimizer: PQO version 3.9.0
(7 rows)

select * from legacy_int a inner join legacy_int b on a.id = b.id;
 id | id 
----+----
  1 |  1
  2 |  2
  3 |  3
(3 rows)

-- A mixture of legacy and modern opclasses. Needs a Redistribute motion. ORCA
-- can't handle this, and falls back.
explain (costs off) select * from legacy_int a inner join modern_int b on a.id = b.id;
                            QUERY PLAN                            
------------------------------------------------------------------
 Gather Motion 3:1  (slice2; segments: 3)
   ->  Hash Join
         Hash Cond: (a.id = b.id)
         ->  Seq Scan on legacy_int a
         ->  Hash
               ->  Redistribute Motion 3:3  (slice1; segments: 3)
                     Hash Key: b.id
                     ->  Seq Scan on modern_int b
159
 Optimizer: Postgres query optimizer
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
(9 rows)

select * from legacy_int a inner join modern_int b on a.id = b.id;
 id | id 
----+----
  2 |  2
  3 |  3
(2 rows)

-- for the sake of completeness, modern opclasses only. No problem for ORCA.
explain (costs off) select * from modern_int a inner join modern_int b on a.id = b.id;
                      QUERY PLAN                       
-------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: (modern_int.id = modern_int_1.id)
         ->  Seq Scan on modern_int
         ->  Hash
               ->  Seq Scan on modern_int modern_int_1
 Optimizer: PQO version 3.9.0
(7 rows)

select * from modern_int a inner join modern_int b on a.id = b.id;
 id | id 
----+----
  2 |  2
  3 |  3
  4 |  4
(3 rows)

-- In principle, ORCA would create a correct plan for this, because even though it
-- mixes the legacy and other opclasses, they're not used in join conditions. But
-- the ORCA translator code is conservative, and falls back if there are any mixed
-- use, even if it would be safe.
explain (costs off) select * from legacy_int a inner join modern_text b on a.id::text = b.t;
                         QUERY PLAN                         
------------------------------------------------------------
 Gather Motion 3:1  (slice2; segments: 3)
   ->  Hash Join
         Hash Cond: ((a.id)::text = b.t)
         ->  Redistribute Motion 3:3  (slice1; segments: 3)
               Hash Key: (a.id)::text
               ->  Seq Scan on legacy_int a
         ->  Hash
               ->  Seq Scan on modern_text b
205
 Optimizer: Postgres query optimizer
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
(9 rows)

select * from legacy_int a inner join modern_text b on a.id::text = b.t;
 id | t 
----+---
  1 | 1
(1 row)

-- Also test with a domain over a base type, and enums.
create domain intdom as integer;
create table legacy_domain_over_int(id intdom) distributed by(id cdbhash_int4_ops);
insert into legacy_domain_over_int values (1), (2), (3);
explain (costs off) select * from legacy_domain_over_int a inner join legacy_domain_over_int b on a.id = b.id;
                                             QUERY PLAN                                             
----------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: ((legacy_domain_over_int.id)::integer = (legacy_domain_over_int_1.id)::integer)
         ->  Seq Scan on legacy_domain_over_int
         ->  Hash
               ->  Seq Scan on legacy_domain_over_int legacy_domain_over_int_1
 Optimizer: PQO version 3.9.0
(7 rows)

explain (costs off) select * from legacy_int a inner join legacy_domain_over_int b on a.id = b.id;
                                QUERY PLAN                                 
---------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: (legacy_int.id = (legacy_domain_over_int.id)::integer)
         ->  Seq Scan on legacy_int
         ->  Hash
               ->  Seq Scan on legacy_domain_over_int
 Optimizer: PQO version 3.9.0
(7 rows)

explain (costs off) select * from modern_int a inner join legacy_domain_over_int b on a.id = b.id;
                            QUERY PLAN                            
------------------------------------------------------------------
 Gather Motion 3:1  (slice2; segments: 3)
   ->  Hash Join
         Hash Cond: ((b.id)::integer = a.id)
         ->  Seq Scan on legacy_domain_over_int b
         ->  Hash
               ->  Redistribute Motion 3:3  (slice1; segments: 3)
                     Hash Key: a.id
                     ->  Seq Scan on modern_int a
253
 Optimizer: Postgres query optimizer
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
(9 rows)

create type colors as enum ('red', 'green', 'blue');
create table legacy_enum(color colors) distributed by(color cdbhash_enum_ops);
insert into legacy_enum values ('red'), ('green'), ('blue');
explain (costs off) select * from legacy_enum a inner join legacy_enum b on a.color = b.color;
                          QUERY PLAN                          
--------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Join
         Hash Cond: (legacy_enum.color = legacy_enum_1.color)
         ->  Seq Scan on legacy_enum
         ->  Hash
               ->  Seq Scan on legacy_enum legacy_enum_1
 Optimizer: PQO version 3.9.0
(7 rows)

select * from legacy_enum a inner join legacy_enum b on a.color = b.color;
 color | color 
-------+-------
 blue  | blue
 red   | red
 green | green
(3 rows)