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_EMPTY_SHARD_QUERY "SELECT master_create_empty_shard('%s')"
#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 \
"SELECT master_update_shard_statistics(%ld)"
#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;
ERROR: cannot open new connections after the first modification command within a transaction
ABORT;
-- COPY can't happen second,
-- Check COPY can happen after INSERT
BEGIN;
INSERT INTO labs VALUES (6, 'Bell Labs');
\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;
-- though it will work if before any modifications
-- Check COPY can happen before INSERT
BEGIN;
\copy labs from stdin delimiter ','
SELECT name FROM labs WHERE id = 10;
name
----------------
Weyland-Yutani
(1 row)
Weyland-Yutani
(2 rows)
INSERT INTO labs VALUES (6, 'Bell Labs');
ERROR: cannot open new connections after the first modification command within a transaction
COMMIT;
-- but a double-copy isn't allowed (the first will persist)
-- Two COPYs are also ok
BEGIN;
\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;
SELECT name FROM labs WHERE id = 11;
name
@ -192,13 +188,12 @@ SELECT name FROM labs WHERE id = 11;
Planet Express
(1 row)
-- finally, ALTER and copy aren't compatible
-- finally, check ALTER and copy are compatible
BEGIN;
ALTER TABLE labs ADD COLUMN motto2 text;
\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;
ALTER TABLE labs DROP COLUMN motto2;
-- but the DDL should correctly roll back
\d labs
Table "public.labs"
@ -207,30 +202,33 @@ COMMIT;
id | bigint | 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;
id | name
----+----------
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...
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
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
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.
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
ERROR: failure on connection marked as essential: localhost:57637

View File

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