ao_upgrade_optimizer.source 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
-- set_ao_formatversion forces an AO[CO] format to a specific version (the last
-- argument is set to true for a column-oriented table, and false otherwise).
CREATE OR REPLACE FUNCTION set_ao_formatversion(aosegrel oid, version smallint, isaocs bool) RETURNS bool AS '@abs_builddir@/isolation2_regress@DLSUFFIX@', 'setAOFormatVersion' LANGUAGE C RETURNS NULL ON NULL INPUT;
CREATE

DROP TABLE IF EXISTS ao_upgrade_test;
DROP
DROP TABLE IF EXISTS aocs_upgrade_test;
DROP
10 11
DROP TABLE IF EXISTS aocs_rle_upgrade_test;
DROP
12 13 14 15 16 17 18 19

CREATE TABLE ao_upgrade_test (rowid int, n numeric) WITH (appendonly=true);
CREATE
CREATE TABLE aocs_upgrade_test (rowid int, n numeric) WITH (appendonly=true, orientation=column);
CREATE
CREATE TABLE aocs_rle_upgrade_test (rowid int, n numeric) WITH (appendonly=true, orientation=column, compresstype=RLE_TYPE);
CREATE

20 21 22 23
-- We want to load GPDB4 numerics into the table; to do that, add a direct cast
-- from bytea to numeric so we can hardcode what the GPDB4 data looked like.
CREATE CAST (bytea AS numeric) WITHOUT FUNCTION;
CREATE
24

25
INSERT INTO ao_upgrade_test VALUES (1, '\x000003000c007a0d'::bytea::numeric),	-- 12.345 (2, '\x00000000'::bytea::numeric),			-- 0 (3, '\x000003400c007a0d'::bytea::numeric),	-- -12.345 (4, '\x010000000100'::bytea::numeric),		-- 10000 (5, '\xfeff0500e803'::bytea::numeric),		-- 0.00001 (6, '\xfeff0900e803'::bytea::numeric),		-- 0.000010000 (7, '\x190000000100'::bytea::numeric),		-- 1e100 (8, '\x010000002400400b'::bytea::numeric),	-- 9! (362880) (9, '\x000000c0'::bytea::numeric);			-- NaN INSERT INTO aocs_upgrade_test VALUES (1, '\x000003000c007a0d'::bytea::numeric),	-- 12.345 (2, '\x00000000'::bytea::numeric),			-- 0 (3, '\x000003400c007a0d'::bytea::numeric),	-- -12.345 (4, '\x010000000100'::bytea::numeric),		-- 10000 (5, '\xfeff0500e803'::bytea::numeric),		-- 0.00001 (6, '\xfeff0900e803'::bytea::numeric),		-- 0.000010000 (7, '\x190000000100'::bytea::numeric),		-- 1e100 (8, '\x010000002400400b'::bytea::numeric),	-- 9! (362880) (9, '\x000000c0'::bytea::numeric);			-- NaN 
26 27
-- For the RLE test case, insert a bunch of identical numerics so they will be
-- run-length compressed.
28
INSERT INTO aocs_rle_upgrade_test (SELECT a, '\x010000002400400b'::bytea::numeric FROM generate_series(1, 10) a);
29 30 31 32 33
INSERT 10

-- Downgrade to GPDB4 (AO version 2).
--start_ignore
*U: SELECT set_ao_formatversion( (SELECT segrelid FROM pg_appendonly WHERE relid = 'ao_upgrade_test'::regclass), 2::smallint, false);
34 35 36
 set_ao_formatversion 
----------------------
 t                    
37 38
(1 row)

39 40 41
 set_ao_formatversion 
----------------------
 t                    
42 43
(1 row)

44 45 46
 set_ao_formatversion 
----------------------
 t                    
47 48
(1 row)

49 50 51
 set_ao_formatversion 
----------------------
 t                    
52 53
(1 row)
*U: SELECT set_ao_formatversion( (SELECT segrelid FROM pg_appendonly WHERE relid = 'aocs_upgrade_test'::regclass), 2::smallint, true);
54 55 56
 set_ao_formatversion 
----------------------
 t                    
57 58
(1 row)

59 60 61
 set_ao_formatversion 
----------------------
 t                    
62 63
(1 row)

64 65 66
 set_ao_formatversion 
----------------------
 t                    
67 68
(1 row)

69 70 71
 set_ao_formatversion 
----------------------
 t                    
72 73
(1 row)
*U: SELECT set_ao_formatversion( (SELECT segrelid FROM pg_appendonly WHERE relid = 'aocs_rle_upgrade_test'::regclass), 2::smallint, true);
74 75 76
 set_ao_formatversion 
----------------------
 t                    
77 78
(1 row)

79 80 81
 set_ao_formatversion 
----------------------
 t                    
82 83
(1 row)

84 85 86
 set_ao_formatversion 
----------------------
 t                    
87 88
(1 row)

89 90 91
 set_ao_formatversion 
----------------------
 t                    
92 93 94 95 96
(1 row)
--end_ignore

-- Scan test. The numerics should be fixed again.
SELECT * FROM ao_upgrade_test;
97 98 99 100 101 102 103 104 105 106 107
 rowid | n                                                                                                     
-------+-------------------------------------------------------------------------------------------------------
 2     | 0                                                                                                     
 5     | 0.00001                                                                                               
 6     | 0.000010000                                                                                           
 9     | NaN                                                                                                   
 1     | 12.345                                                                                                
 3     | -12.345                                                                                               
 4     | 10000                                                                                                 
 7     | 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 
 8     | 362880                                                                                                
108
(9 rows)
109
SELECT * FROM aocs_upgrade_test;
110 111 112 113 114 115 116 117 118 119 120
 rowid | n                                                                                                     
-------+-------------------------------------------------------------------------------------------------------
 2     | 0                                                                                                     
 5     | 0.00001                                                                                               
 6     | 0.000010000                                                                                           
 9     | NaN                                                                                                   
 4     | 10000                                                                                                 
 7     | 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 
 8     | 362880                                                                                                
 1     | 12.345                                                                                                
 3     | -12.345                                                                                               
121
(9 rows)
122
SELECT * FROM aocs_rle_upgrade_test;
123 124 125 126 127 128 129 130 131 132 133 134
 rowid | n      
-------+--------
 1     | 362880 
 2     | 362880 
 3     | 362880 
 4     | 362880 
 5     | 362880 
 6     | 362880 
 7     | 362880 
 8     | 362880 
 9     | 362880 
 10    | 362880 
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
(10 rows)

-- Fetch test. To force fetches, we'll add bitmap indexes and disable sequential
-- scan.
CREATE INDEX ao_bitmap_index ON ao_upgrade_test USING bitmap(n);
CREATE
CREATE INDEX aocs_bitmap_index ON aocs_upgrade_test USING bitmap(n);
CREATE
CREATE INDEX aocs_rle_bitmap_index ON aocs_rle_upgrade_test USING bitmap(n);
CREATE

SET enable_seqscan TO off;
SET

-- Ensure we're using a bitmap scan for our tests. Upgrade note to developers:
-- the only thing that this test needs to verify is that a fetch-based scan is
-- in use. Other diffs are fine.
EXPLAIN SELECT n FROM ao_upgrade_test WHERE n = (9 !);
153 154 155 156 157 158 159 160
 QUERY PLAN                                                                                            
-------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=1000.36..1100.37 rows=1 width=9)                      
   ->  Bitmap Heap Scan on ao_upgrade_test  (cost=1000.36..1100.37 rows=1 width=9) 
         Recheck Cond: n = 362880::numeric                                                             
         ->  Bitmap Index Scan on ao_bitmap_index  (cost=0.00..1000.36 rows=1 width=0)                 
               Index Cond: n = 362880::numeric                                                         
 Settings:  enable_seqscan=off                                                                         
161
 Optimizer status: Postgres query optimizer                                                              
162 163
(7 rows)
EXPLAIN SELECT n FROM aocs_upgrade_test WHERE n = (9 !);
164 165 166 167 168 169 170 171
 QUERY PLAN                                                                                                 
------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=1000.36..1100.37 rows=1 width=9)                           
   ->  Bitmap Heap Scan on aocs_upgrade_test  (cost=1000.36..1100.37 rows=1 width=9) 
         Recheck Cond: n = 362880::numeric                                                                  
         ->  Bitmap Index Scan on aocs_bitmap_index  (cost=0.00..1000.36 rows=1 width=0)                    
               Index Cond: n = 362880::numeric                                                              
 Settings:  enable_seqscan=off                                                                              
172
 Optimizer status: Postgres query optimizer                                                                   
173 174
(7 rows)
EXPLAIN SELECT n FROM aocs_rle_upgrade_test WHERE n = (9 !);
175 176 177 178 179 180 181 182
 QUERY PLAN                                                                                                     
----------------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=1000.36..1100.37 rows=1 width=9)                               
   ->  Bitmap Heap Scan on aocs_rle_upgrade_test  (cost=1000.36..1100.37 rows=1 width=9) 
         Recheck Cond: n = 362880::numeric                                                                      
         ->  Bitmap Index Scan on aocs_rle_bitmap_index  (cost=0.00..1000.36 rows=1 width=0)                    
               Index Cond: n = 362880::numeric                                                                  
 Settings:  enable_seqscan=off                                                                                  
183
 Optimizer status: Postgres query optimizer                                                                       
184 185 186
(7 rows)

SELECT n FROM ao_upgrade_test WHERE n = (9 !);
187 188 189
 n      
--------
 362880 
190 191
(1 row)
SELECT n FROM aocs_upgrade_test WHERE n = (9 !);
192 193 194
 n      
--------
 362880 
195 196
(1 row)
SELECT n FROM aocs_rle_upgrade_test WHERE n = (9 !);
197 198 199 200 201 202 203 204 205 206 207 208
 n      
--------
 362880 
 362880 
 362880 
 362880 
 362880 
 362880 
 362880 
 362880 
 362880 
 362880 
209 210 211 212 213
(10 rows)

RESET enable_seqscan;
RESET

214
DROP CAST (bytea AS numeric);
215 216 217
DROP
DROP FUNCTION set_ao_formatversion(oid, smallint, bool);
DROP