qp_dml_oids.out 11.7 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 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
create schema qp_dml_oids;
set search_path='qp_dml_oids';
DROP TABLE IF EXISTS dml_ao;
NOTICE:  table "dml_ao" does not exist, skipping
CREATE TABLE dml_ao (a int , b int default -1, c text) WITH (appendonly = true, oids = true) DISTRIBUTED BY (a);
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
INSERT INTO dml_ao VALUES(generate_series(1,2),generate_series(1,2),'r');
INSERT INTO dml_ao VALUES(NULL,NULL,NULL);
--
-- DDL on AO/CO tables with OIDS(Negative Test)
--
DROP TABLE IF EXISTS tempoid;
NOTICE:  table "tempoid" does not exist, skipping
CREATE TABLE tempoid as SELECT oid,a FROM dml_ao ORDER BY 1;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
UPDATE dml_ao SET a = 100;
ERROR:  Cannot parallelize an UPDATE statement that updates the distribution columns
SELECT * FROM ( (SELECT COUNT(*) FROM dml_ao) UNION (SELECT COUNT(*) FROM tempoid, dml_ao WHERE tempoid.oid = dml_ao.oid AND tempoid.gp_segment_id = dml_ao.gp_segment_id))foo;
 count 
-------
     3
(1 row)

DROP TABLE IF EXISTS dml_heap_check_r;
NOTICE:  table "dml_heap_check_r" does not exist, skipping
CREATE TABLE dml_heap_check_r (
	a int default 100 CHECK( a between 1 and 105), 
	b float8 CONSTRAINT rcheck_b CHECK( b <> 0.00 and b IS NOT NULL),
	c text, 
	d numeric NOT NULL) 
WITH OIDS DISTRIBUTED BY (a);
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
--
-- DML on table with constraints and OIDS(Negative Test)
--
INSERT INTO dml_heap_check_r SELECT i, i ,'r', i FROM generate_series(1,2)i;
SELECT SUM(a),SUM(b) FROM dml_heap_check_r;
 sum | sum 
-----+-----
   3 |   3
(1 row)

SELECT COUNT(*) FROM dml_heap_check_r;
 count 
-------
     2
(1 row)

INSERT INTO dml_heap_check_r VALUES(DEFAULT,DEFAULT,'rn',0);
ERROR:  new row for relation "dml_heap_check_r" violates check constraint "rcheck_b"  (seg2 127.0.0.1:40002 pid=24286)
SELECT SUM(a),SUM(b) FROM dml_heap_check_r;
 sum | sum 
-----+-----
   3 |   3
(1 row)

SELECT COUNT(*) FROM dml_heap_check_r;
 count 
-------
     2
(1 row)

INSERT INTO dml_heap_check_r VALUES(110,NULL,'rn',0);
ERROR:  new row for relation "dml_heap_check_r" violates check constraint "rcheck_b"  (seg1 127.0.0.1:40001 pid=24284)
SELECT SUM(a),SUM(b) FROM dml_heap_check_r;
 sum | sum 
-----+-----
   3 |   3
(1 row)

SELECT COUNT(*) FROM dml_heap_check_r;
 count 
-------
     2
(1 row)

SELECT SUM(a) FROM dml_heap_check_r;
 sum 
-----
   3
(1 row)

DROP TABLE IF EXISTS tempoid;
CREATE TABLE tempoid as SELECT oid,a FROM dml_heap_check_r DISTRIBUTED BY (a);
UPDATE dml_heap_check_r set a = 110;
ERROR:  Cannot parallelize an UPDATE statement that updates the distribution columns
SELECT SUM(a) FROM dml_heap_check_r;
 sum 
-----
   3
(1 row)

-- THIS SQL CONFIRMS THAT POST UPDATE THE OID OF THE TUPLE REMAINS THE SAME
SELECT * FROM ( (SELECT COUNT(*) FROM dml_heap_check_r) UNION (SELECT COUNT(*) FROM tempoid, dml_heap_check_r WHERE tempoid.oid = dml_heap_check_r.oid AND tempoid.gp_segment_id = dml_heap_check_r.gp_segment_id))foo;
 count 
-------
     2
(1 row)

DROP TABLE IF EXISTS dml_heap_r;
NOTICE:  table "dml_heap_r" does not exist, skipping
CREATE TABLE dml_heap_r (a int , b int default -1, c text) WITH OIDS DISTRIBUTED BY (a);
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
INSERT INTO dml_heap_r VALUES(generate_series(1,2),generate_series(1,2),'r');
INSERT INTO dml_heap_r VALUES(NULL,NULL,NULL);
SELECT COUNT(*) FROM dml_heap_r;
 count 
-------
     3
(1 row)

--
-- DELETE on table with OIDS
--
SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

DROP TABLE IF EXISTS tempoid;
CREATE TABLE tempoid as SELECT oid,a FROM dml_heap_r DISTRIBUTED BY (a);
DELETE FROM dml_heap_r WHERE a is NULL;
SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

SELECT * FROM ( (SELECT COUNT(*) FROM dml_heap_r) UNION (SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.gp_segment_id = dml_heap_r.gp_segment_id AND tempoid.a is NOT NULL))foo;
 count 
-------
     2
(1 row)

DROP TABLE IF EXISTS dml_heap_r;
CREATE TABLE dml_heap_r (col1 serial, a int , b int default -1, c text) WITH OIDS DISTRIBUTED BY (a);
NOTICE:  CREATE TABLE will create implicit sequence "dml_heap_r_col1_seq" for serial column "dml_heap_r.col1"
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
INSERT INTO dml_heap_r(a,b,c) VALUES(generate_series(1,2),generate_series(1,2),'r');
INSERT INTO dml_heap_r(a,b,c) VALUES(NULL,NULL,NULL);
SELECT COUNT(*) FROM dml_heap_r;
 count 
-------
     3
(1 row)

--
-- UPDATE to constant value on table with OIDS
--
SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

DROP TABLE IF EXISTS tempoid;
CREATE TABLE tempoid as SELECT oid,col1,a FROM dml_heap_r ORDER BY 1;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
UPDATE dml_heap_r SET a = 1;
ERROR:  Cannot parallelize an UPDATE statement that updates the distribution columns
SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

-- The query checks that the tuple oids remain the remain pre and post update .
-- SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.col1 = dml_heap_r.col1 is a join on the tuple oids before update and after update. If the oids remain the same the below query should return 1 row which is equivalent to the number of rows in the table
SELECT * FROM ( (SELECT COUNT(*) FROM dml_heap_r) UNION (SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.col1 = dml_heap_r.col1))foo;
 count 
-------
     3
(1 row)

DROP TABLE IF EXISTS dml_heap_r;
DROP TABLE IF EXISTS dml_heap_p;
NOTICE:  table "dml_heap_p" does not exist, skipping
CREATE TABLE dml_heap_r (a int , b int default -1, c text) WITH OIDS DISTRIBUTED BY (a);
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
CREATE TABLE dml_heap_p (col1 serial, a numeric, b decimal) WITH OIDS DISTRIBUTED BY (a,b);
NOTICE:  CREATE TABLE will create implicit sequence "dml_heap_p_col1_seq" for serial column "dml_heap_p.col1"
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
INSERT INTO dml_heap_p(a,b) SELECT id as a, id as b FROM (SELECT * FROM generate_series(1,2) as id) AS x;
INSERT INTO dml_heap_p(a,b) VALUES(NULL,NULL);
INSERT INTO dml_heap_r VALUES(generate_series(1,2),generate_series(1,2),'r');
INSERT INTO dml_heap_r VALUES(NULL,NULL,NULL);
SELECT COUNT(*) FROM dml_heap_r;
 count 
-------
     3
(1 row)

SELECT COUNT(*) FROM dml_heap_p;
 count 
-------
     3
(1 row)

--
-- UPDATE with SELECT on table with OIDS
--
SELECT SUM(a), SUM(b) FROM dml_heap_p;
 sum | sum 
-----+-----
   3 |   3
(1 row)

DROP TABLE IF EXISTS tempoid;
CREATE TABLE tempoid as SELECT oid,col1,a,b FROM dml_heap_p ORDER BY 1;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a, 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.
UPDATE dml_heap_p SET a = (SELECT a FROM dml_heap_r ORDER BY 1 LIMIT 1), b = ((SELECT b FROM dml_heap_r ORDER BY 1 LIMIT 1));
ERROR:  Cannot parallelize an UPDATE statement that updates the distribution columns
-- The query checks that the tuple oids remain the remain pre and post update .
-- SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.col1 = dml_heap_r.col1 is a join on the tuple oids before update and after update. If the oids remain the same the below query should return 1 row which is equivalent to the number of rows in the table
SELECT * FROM ( (SELECT COUNT(*) FROM dml_heap_p) UNION (SELECT COUNT(*) FROM tempoid, dml_heap_p WHERE tempoid.oid = dml_heap_p.oid AND tempoid.col1 = dml_heap_p.col1))foo;
 count 
-------
     3
(1 row)

SELECT SUM(a), SUM(b) FROM dml_heap_p;
 sum | sum 
-----+-----
   3 |   3
(1 row)

DROP TABLE IF EXISTS dml_heap_r;
DROP TABLE IF EXISTS dml_heap_p;
CREATE TABLE dml_heap_r (col1 serial,a int , b int default -1, c text) WITH OIDS DISTRIBUTED BY (a);
NOTICE:  CREATE TABLE will create implicit sequence "dml_heap_r_col1_seq" for serial column "dml_heap_r.col1"
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
CREATE TABLE dml_heap_p (col1 serial, a numeric, b decimal) WITH OIDS DISTRIBUTED BY (a,b);
NOTICE:  CREATE TABLE will create implicit sequence "dml_heap_p_col1_seq" for serial column "dml_heap_p.col1"
NOTICE:  OIDS=TRUE is not recommended for user-created tables. Use OIDS=FALSE to prevent wrap-around of the OID counter
INSERT INTO dml_heap_p(a,b) SELECT id as a, id as b FROM (SELECT * FROM generate_series(1,2) as id) AS x;
INSERT INTO dml_heap_p(a,b) VALUES(NULL,NULL);
INSERT INTO dml_heap_r(a,b,c) VALUES(generate_series(1,2),generate_series(1,2),'r');
INSERT INTO dml_heap_r(a,b,c) VALUES(NULL,NULL,NULL);
SELECT COUNT(*) FROM dml_heap_r;
 count 
-------
     3
(1 row)

SELECT COUNT(*) FROM dml_heap_p;
 count 
-------
     3
(1 row)

--
-- UPDATE with joins on table with OIDS
--
SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

DROP TABLE IF EXISTS tempoid;
CREATE TABLE tempoid as SELECT oid,col1,a FROM dml_heap_r ORDER BY 1;
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
SELECT SUM(dml_heap_r.a) FROM dml_heap_p, dml_heap_r WHERE dml_heap_r.b = dml_heap_p.a;
 sum 
-----
   3
(1 row)

274
UPDATE dml_heap_r SET a = dml_heap_r.a FROM dml_heap_p WHERE dml_heap_r.b = dml_heap_p.a;
275 276 277 278 279 280 281 282 283 284 285 286 287 288
-- The query checks that the tuple oids remain the remain pre and post update .
-- SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.col1 = dml_heap_r.col1 is a join on the tuple oids before update and after update. If the oids remain the same the below query should return 1 row which is equivalent to the number of rows in the table
SELECT * FROM ( (SELECT COUNT(*) FROM dml_heap_r) UNION (SELECT COUNT(*) FROM tempoid, dml_heap_r WHERE tempoid.oid = dml_heap_r.oid AND tempoid.col1 = dml_heap_r.col1))foo;
 count 
-------
     3
(1 row)

SELECT SUM(a) FROM dml_heap_r;
 sum 
-----
   3
(1 row)

289 290 291 292 293 294 295 296 297 298 299 300
--
-- Check that a tuple gets an OID, even if it's toasted (there used to
-- be a bug, where toasting a tuple cleared its just-assigned OID)
--
INSERT INTO dml_ao (a, b, c) VALUES (10, 1, repeat('x', 50000));
INSERT INTO dml_ao (a, b, c) VALUES (10, 2, repeat('x', 50000));
SELECT COUNT(distinct oid) FROM dml_ao where a = 10;
 count 
-------
     2
(1 row)

301 302 303 304 305 306 307 308 309 310 311 312 313
--
-- Check that new OIDs are generated even if the tuple being inserted came from
-- the same relation and segment.
--
INSERT INTO dml_ao VALUES (11, 1, 'foo');
INSERT INTO dml_ao VALUES (11, 2, 'bar');
INSERT INTO dml_ao SELECT * FROM dml_ao WHERE a = 11 LIMIT 1;
SELECT COUNT(DISTINCT oid) FROM dml_ao WHERE a = 11; -- all three rows should have different OID
 count 
-------
     3
(1 row)