Migration COPY to new framework.

This implies several behaviour changes:
- COPY is now transactional
- failure to compute stats for append partitioned tables is an error
pull/775/head
Andres Freund 2016-09-18 19:45:25 -07:00
parent 360307f6d5
commit a8f9e983a0
5 changed files with 431 additions and 484 deletions

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,7 @@
#define CREATE_SCHEMA_COMMAND "CREATE SCHEMA IF NOT EXISTS %s" #define CREATE_SCHEMA_COMMAND "CREATE SCHEMA IF NOT EXISTS %s"
#define CREATE_EMPTY_SHARD_QUERY "SELECT master_create_empty_shard('%s')" #define CREATE_EMPTY_SHARD_QUERY "SELECT master_create_empty_shard('%s')"
#define FINALIZED_SHARD_PLACEMENTS_QUERY \ #define FINALIZED_SHARD_PLACEMENTS_QUERY \
"SELECT nodename, nodeport FROM pg_dist_shard_placement WHERE shardstate = 1 AND shardid = %ld" "SELECT placementid, nodename, nodeport FROM pg_dist_shard_placement WHERE shardstate = 1 AND shardid = %ld"
#define UPDATE_SHARD_STATISTICS_QUERY \ #define UPDATE_SHARD_STATISTICS_QUERY \
"SELECT master_update_shard_statistics(%ld)" "SELECT master_update_shard_statistics(%ld)"
#define PARTITION_METHOD_QUERY "SELECT part_method FROM master_get_table_metadata('%s');" #define PARTITION_METHOD_QUERY "SELECT part_method FROM master_get_table_metadata('%s');"

View File

@ -160,31 +160,27 @@ INSERT INTO labs VALUES (6, 'Bell Labs');
SELECT count(*) FROM researchers WHERE lab_id = 6; SELECT count(*) FROM researchers WHERE lab_id = 6;
ERROR: cannot open new connections after the first modification command within a transaction ERROR: cannot open new connections after the first modification command within a transaction
ABORT; ABORT;
-- COPY can't happen second, -- Check COPY can happen after INSERT
BEGIN; BEGIN;
INSERT INTO labs VALUES (6, 'Bell Labs'); INSERT INTO labs VALUES (6, 'Bell Labs');
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
ERROR: distributed copy operations must not appear in transaction blocks containing other distributed modifications
CONTEXT: COPY labs, line 1: "10,Weyland-Yutani"
COMMIT; COMMIT;
-- though it will work if before any modifications -- Check COPY can happen before INSERT
BEGIN; BEGIN;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
SELECT name FROM labs WHERE id = 10; SELECT name FROM labs WHERE id = 10;
name name
---------------- ----------------
Weyland-Yutani Weyland-Yutani
(1 row) Weyland-Yutani
(2 rows)
INSERT INTO labs VALUES (6, 'Bell Labs'); INSERT INTO labs VALUES (6, 'Bell Labs');
ERROR: cannot open new connections after the first modification command within a transaction
COMMIT; COMMIT;
-- but a double-copy isn't allowed (the first will persist) -- Two COPYs are also ok
BEGIN; BEGIN;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
ERROR: distributed copy operations must not appear in transaction blocks containing other distributed modifications
CONTEXT: COPY labs, line 1: "12,fsociety"
COMMIT; COMMIT;
SELECT name FROM labs WHERE id = 11; SELECT name FROM labs WHERE id = 11;
name name
@ -192,13 +188,12 @@ SELECT name FROM labs WHERE id = 11;
Planet Express Planet Express
(1 row) (1 row)
-- finally, ALTER and copy aren't compatible -- finally, check ALTER and copy are compatible
BEGIN; BEGIN;
ALTER TABLE labs ADD COLUMN motto2 text; ALTER TABLE labs ADD COLUMN motto2 text;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
ERROR: distributed copy operations must not appear in transaction blocks containing other distributed modifications
CONTEXT: COPY labs, line 1: "12,fsociety,lol"
COMMIT; COMMIT;
ALTER TABLE labs DROP COLUMN motto2;
-- but the DDL should correctly roll back -- but the DDL should correctly roll back
\d labs \d labs
Table "public.labs" Table "public.labs"
@ -207,30 +202,33 @@ COMMIT;
id | bigint | not null id | bigint | not null
name | text | not null name | text | not null
SELECT * FROM labs WHERE id = 12;
id | name
----+------
(0 rows)
-- and if the copy is before the ALTER...
BEGIN;
\copy labs from stdin delimiter ','
ALTER TABLE labs ADD COLUMN motto3 text;
ERROR: distributed DDL commands must not appear within transaction blocks containing data modifications
COMMIT;
-- the DDL fails, but copy persists
\d labs
Table "public.labs"
Column | Type | Modifiers
--------+--------+-----------
id | bigint | not null
name | text | not null
SELECT * FROM labs WHERE id = 12; SELECT * FROM labs WHERE id = 12;
id | name id | name
----+---------- ----+----------
12 | fsociety 12 | fsociety
(1 row) 12 | fsociety
(2 rows)
-- and if the copy is before the ALTER...
BEGIN;
\copy labs from stdin delimiter ','
ALTER TABLE labs ADD COLUMN motto3 text;
ERROR: distributed DDL commands must not appear within transaction blocks containing data modifications
COMMIT;
-- the DDL fails, and copy does not persist
\d labs
Table "public.labs"
Column | Type | Modifiers
--------+--------+-----------
id | bigint | not null
name | text | not null
SELECT * FROM labs WHERE id = 12;
id | name
----+----------
12 | fsociety
12 | fsociety
(2 rows)
-- now, for some special failures... -- now, for some special failures...
CREATE TABLE objects ( CREATE TABLE objects (

View File

@ -702,8 +702,4 @@ SELECT master_create_distributed_table('composite_partition_column_table', 'comp
WARNING: function min(number_pack) does not exist WARNING: function min(number_pack) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts. HINT: No function matches the given name and argument types. You might need to add explicit type casts.
CONTEXT: while executing command on localhost:57637 CONTEXT: while executing command on localhost:57637
WARNING: function min(number_pack) does not exist ERROR: failure on connection marked as essential: localhost:57637
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
CONTEXT: while executing command on localhost:57638
WARNING: could not get statistics for shard public.composite_partition_column_table_560164
DETAIL: Setting shard statistics to NULL

View File

@ -131,7 +131,7 @@ INSERT INTO labs VALUES (6, 'Bell Labs');
SELECT count(*) FROM researchers WHERE lab_id = 6; SELECT count(*) FROM researchers WHERE lab_id = 6;
ABORT; ABORT;
-- COPY can't happen second, -- Check COPY can happen after INSERT
BEGIN; BEGIN;
INSERT INTO labs VALUES (6, 'Bell Labs'); INSERT INTO labs VALUES (6, 'Bell Labs');
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
@ -139,7 +139,7 @@ INSERT INTO labs VALUES (6, 'Bell Labs');
\. \.
COMMIT; COMMIT;
-- though it will work if before any modifications -- Check COPY can happen before INSERT
BEGIN; BEGIN;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
10,Weyland-Yutani 10,Weyland-Yutani
@ -148,7 +148,7 @@ SELECT name FROM labs WHERE id = 10;
INSERT INTO labs VALUES (6, 'Bell Labs'); INSERT INTO labs VALUES (6, 'Bell Labs');
COMMIT; COMMIT;
-- but a double-copy isn't allowed (the first will persist) -- Two COPYs are also ok
BEGIN; BEGIN;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
11,Planet Express 11,Planet Express
@ -160,13 +160,14 @@ COMMIT;
SELECT name FROM labs WHERE id = 11; SELECT name FROM labs WHERE id = 11;
-- finally, ALTER and copy aren't compatible -- finally, check ALTER and copy are compatible
BEGIN; BEGIN;
ALTER TABLE labs ADD COLUMN motto2 text; ALTER TABLE labs ADD COLUMN motto2 text;
\copy labs from stdin delimiter ',' \copy labs from stdin delimiter ','
12,fsociety,lol 12,fsociety,lol
\. \.
COMMIT; COMMIT;
ALTER TABLE labs DROP COLUMN motto2;
-- but the DDL should correctly roll back -- but the DDL should correctly roll back
\d labs \d labs
@ -180,7 +181,7 @@ BEGIN;
ALTER TABLE labs ADD COLUMN motto3 text; ALTER TABLE labs ADD COLUMN motto3 text;
COMMIT; COMMIT;
-- the DDL fails, but copy persists -- the DDL fails, and copy does not persist
\d labs \d labs
SELECT * FROM labs WHERE id = 12; SELECT * FROM labs WHERE id = 12;