Merge pull request #1774 from citusdata/fix_partitioning_in_schema

Fix attaching partition to a distributed table in schema
pull/1781/merge
Burak Yücesoy 2017-11-09 12:49:55 +02:00 committed by GitHub
commit cf7a4ae608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 331 additions and 3 deletions

View File

@ -874,7 +874,7 @@ ProcessCreateTableStmtPartitionOf(CreateStmt *createStatement)
missingOk);
Var *parentDistributionColumn = DistPartitionKey(parentRelationId);
char parentDistributionMethod = DISTRIBUTE_BY_HASH;
char *parentRelationName = get_rel_name(parentRelationId);
char *parentRelationName = generate_qualified_relation_name(parentRelationId);
bool viaDeprecatedAPI = false;
CreateDistributedTable(relationId, parentDistributionColumn,
@ -952,11 +952,11 @@ ProcessAlterTableStmtAttachPartition(AlterTableStmt *alterTableStatement)
{
Var *distributionColumn = DistPartitionKey(relationId);
char distributionMethod = DISTRIBUTE_BY_HASH;
char *relationName = get_rel_name(relationId);
char *parentRelationName = generate_qualified_relation_name(relationId);
bool viaDeprecatedAPI = false;
CreateDistributedTable(partitionRelationId, distributionColumn,
distributionMethod, relationName,
distributionMethod, parentRelationName,
viaDeprecatedAPI);
}
}

View File

@ -1255,3 +1255,127 @@ SELECT create_distributed_table('partitioning_test', 'id');
(1 row)
DROP TABLE partitioning_test;
-- make sure we can attach partitions to a distributed table in a schema
CREATE SCHEMA partitioning_schema;
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
create_distributed_table
--------------------------
(1 row)
CREATE TABLE partitioning_schema."schema-test_2009"(id int, time date);
ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITION partitioning_schema."schema-test_2009" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- attached partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
logicalrelid
----------------------------------------
partitioning_schema."schema-test"
partitioning_schema."schema-test_2009"
(2 rows)
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
logicalrelid | count
----------------------------------------+-------
partitioning_schema."schema-test" | 4
partitioning_schema."schema-test_2009" | 4
(2 rows)
DROP TABLE partitioning_schema."schema-test";
-- make sure we can create partition of a distributed table in a schema
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
create_distributed_table
--------------------------
(1 row)
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF partitioning_schema."schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
logicalrelid
----------------------------------------
partitioning_schema."schema-test"
partitioning_schema."schema-test_2009"
(2 rows)
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
logicalrelid | count
----------------------------------------+-------
partitioning_schema."schema-test" | 4
partitioning_schema."schema-test_2009" | 4
(2 rows)
DROP TABLE partitioning_schema."schema-test";
-- make sure creating partitioned tables works while search_path is set
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SET search_path = partitioning_schema;
SELECT create_distributed_table('"schema-test"', 'id');
create_distributed_table
--------------------------
(1 row)
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF "schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
logicalrelid
--------------------
"schema-test"
"schema-test_2009"
(2 rows)
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
logicalrelid | count
--------------------+-------
"schema-test" | 4
"schema-test_2009" | 4
(2 rows)
DROP SCHEMA partitioning_schema CASCADE;
NOTICE: drop cascades to table "schema-test"

View File

@ -1143,3 +1143,123 @@ LINE 1: SELECT create_distributed_table('partitioning_test', 'id');
^
DROP TABLE partitioning_test;
ERROR: table "partitioning_test" does not exist
-- make sure we can attach partitions to a distributed table in a schema
CREATE SCHEMA partitioning_schema;
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
ERROR: syntax error at or near "PARTITION"
LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ...
^
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 1: SELECT create_distributed_table('partitioning_schema."schema...
^
CREATE TABLE partitioning_schema."schema-test_2009"(id int, time date);
ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITION partitioning_schema."schema-test_2009" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
ERROR: syntax error at or near "ATTACH"
LINE 1: ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITI...
^
-- attached partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl...
^
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re...
^
DROP TABLE partitioning_schema."schema-test";
ERROR: table "schema-test" does not exist
-- make sure we can create partition of a distributed table in a schema
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
ERROR: syntax error at or near "PARTITION"
LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ...
^
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 1: SELECT create_distributed_table('partitioning_schema."schema...
^
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF partitioning_schema."schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
ERROR: syntax error at or near "PARTITION"
LINE 1: ...EATE TABLE partitioning_schema."schema-test_2009" PARTITION ...
^
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl...
^
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re...
^
DROP TABLE partitioning_schema."schema-test";
ERROR: table "schema-test" does not exist
-- make sure creating partitioned tables works while search_path is set
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
ERROR: syntax error at or near "PARTITION"
LINE 1: ...titioning_schema."schema-test"(id int, time date) PARTITION ...
^
SET search_path = partitioning_schema;
SELECT create_distributed_table('"schema-test"', 'id');
ERROR: relation "schema-test" does not exist
LINE 1: SELECT create_distributed_table('"schema-test"', 'id');
^
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF "schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
ERROR: syntax error at or near "PARTITION"
LINE 1: ...EATE TABLE partitioning_schema."schema-test_2009" PARTITION ...
^
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::regcl...
^
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
ERROR: relation "partitioning_schema.schema-test" does not exist
LINE 6: logicalrelid IN ('partitioning_schema."schema-test"'::re...
^
DROP SCHEMA partitioning_schema CASCADE;
NOTICE: drop cascades to table "schema-test_2009"

View File

@ -820,3 +820,87 @@ CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time);
CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
SELECT create_distributed_table('partitioning_test', 'id');
DROP TABLE partitioning_test;
-- make sure we can attach partitions to a distributed table in a schema
CREATE SCHEMA partitioning_schema;
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
CREATE TABLE partitioning_schema."schema-test_2009"(id int, time date);
ALTER TABLE partitioning_schema."schema-test" ATTACH PARTITION partitioning_schema."schema-test_2009" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- attached partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
DROP TABLE partitioning_schema."schema-test";
-- make sure we can create partition of a distributed table in a schema
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SELECT create_distributed_table('partitioning_schema."schema-test"', 'id');
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF partitioning_schema."schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
DROP TABLE partitioning_schema."schema-test";
-- make sure creating partitioned tables works while search_path is set
CREATE TABLE partitioning_schema."schema-test"(id int, time date) PARTITION BY RANGE (time);
SET search_path = partitioning_schema;
SELECT create_distributed_table('"schema-test"', 'id');
CREATE TABLE partitioning_schema."schema-test_2009" PARTITION OF "schema-test" FOR VALUES FROM ('2009-01-01') TO ('2010-01-01');
-- newly created partition is distributed as well
SELECT
logicalrelid
FROM
pg_dist_partition
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
ORDER BY 1;
SELECT
logicalrelid, count(*)
FROM
pg_dist_shard
WHERE
logicalrelid IN ('partitioning_schema."schema-test"'::regclass, 'partitioning_schema."schema-test_2009"'::regclass)
GROUP BY
logicalrelid
ORDER BY
1,2;
DROP SCHEMA partitioning_schema CASCADE;