From bca672e0a40cefa83d3afe8542e70a1254e2773a Mon Sep 17 00:00:00 2001 From: Burak Yucesoy Date: Tue, 12 Jul 2016 17:27:19 +0300 Subject: [PATCH] Fix master_apply_delete_command with schema Fixes #73 --- .../master/master_delete_protocol.c | 7 +++++ .../regress/expected/multi_schema_support.out | 25 +++++++++++++++ src/test/regress/sql/multi_schema_support.sql | 31 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/backend/distributed/master/master_delete_protocol.c b/src/backend/distributed/master/master_delete_protocol.c index 09c50d5b5..5b46fa763 100644 --- a/src/backend/distributed/master/master_delete_protocol.c +++ b/src/backend/distributed/master/master_delete_protocol.c @@ -113,6 +113,13 @@ master_apply_delete_command(PG_FUNCTION_ARGS) relationName = deleteStatement->relation->relname; relationId = RangeVarGetRelid(deleteStatement->relation, NoLock, failOK); + /* schema-prefix if it is not specified already */ + if (schemaName == NULL) + { + Oid schemaId = get_rel_namespace(relationId); + schemaName = get_namespace_name(schemaId); + } + CheckDistributedTable(relationId); EnsureTablePermissions(relationId, ACL_DELETE); diff --git a/src/test/regress/expected/multi_schema_support.out b/src/test/regress/expected/multi_schema_support.out index d62461037..fa2cd9e38 100644 --- a/src/test/regress/expected/multi_schema_support.out +++ b/src/test/regress/expected/multi_schema_support.out @@ -801,3 +801,28 @@ SELECT * FROM pg_dist_shard_placement WHERE shardid = 1190000; 1190000 | 1 | 0 | localhost | 57637 (2 rows) +-- test master_apply_delete_command with schemas +SET search_path TO public; +SELECT master_apply_delete_command('DELETE FROM test_schema_support.nation_append') ; + master_apply_delete_command +----------------------------- + 1 +(1 row) + +-- verify shard is dropped +\c - - - :worker_1_port +\d test_schema_support.nation_append_119* +\c - - - :master_port +-- test with search_path is set +SET search_path TO test_schema_support; +\COPY nation_append FROM STDIN with delimiter '|'; +SELECT master_apply_delete_command('DELETE FROM nation_append') ; + master_apply_delete_command +----------------------------- + 1 +(1 row) + +-- verify shard is dropped +\c - - - :worker_1_port +\d test_schema_support.nation_append_119* +\c - - - :master_port diff --git a/src/test/regress/sql/multi_schema_support.sql b/src/test/regress/sql/multi_schema_support.sql index f1ec78d5f..40770eb23 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -516,3 +516,34 @@ SELECT master_copy_shard_placement(1190000, 'localhost', :worker_2_port, 'localh -- verify shardstate SELECT * FROM pg_dist_shard_placement WHERE shardid = 1190000; + + +-- test master_apply_delete_command with schemas +SET search_path TO public; +SELECT master_apply_delete_command('DELETE FROM test_schema_support.nation_append') ; + +-- verify shard is dropped +\c - - - :worker_1_port +\d test_schema_support.nation_append_119* + +\c - - - :master_port + +-- test with search_path is set +SET search_path TO test_schema_support; + +\COPY nation_append FROM STDIN with delimiter '|'; +0|ALGERIA|0| haggle. carefully final deposits detect slyly agai +1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold +4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d +5|ETHIOPIA|0|ven packages wake quickly. regu +\. + +SELECT master_apply_delete_command('DELETE FROM nation_append') ; + +-- verify shard is dropped +\c - - - :worker_1_port +\d test_schema_support.nation_append_119* + +\c - - - :master_port