diff --git a/src/backend/distributed/sql/citus--10.1-1--10.2-1.sql b/src/backend/distributed/sql/citus--10.1-1--10.2-1.sql index 1a6400c47..e4c60081f 100644 --- a/src/backend/distributed/sql/citus--10.1-1--10.2-1.sql +++ b/src/backend/distributed/sql/citus--10.1-1--10.2-1.sql @@ -31,7 +31,7 @@ CREATE FUNCTION pg_catalog.citus_drop_all_shards(logicalrelid regclass, AS 'MODULE_PATHNAME', $$citus_drop_all_shards$$; COMMENT ON FUNCTION pg_catalog.citus_drop_all_shards(regclass, text, text, boolean) IS 'drop all shards in a relation and update metadata'; -ALTER TABLE pg_dist_partition ADD COLUMN autoconverted boolean; + #include "udfs/citus_drop_trigger/10.2-1.sql"; #include "udfs/citus_prepare_pg_upgrade/10.2-1.sql" #include "udfs/citus_finish_pg_upgrade/10.2-1.sql" diff --git a/src/backend/distributed/sql/citus--10.2-3--11.0-1.sql b/src/backend/distributed/sql/citus--10.2-3--11.0-1.sql index b202061db..14662dce6 100644 --- a/src/backend/distributed/sql/citus--10.2-3--11.0-1.sql +++ b/src/backend/distributed/sql/citus--10.2-3--11.0-1.sql @@ -6,5 +6,6 @@ #include "udfs/fix_all_partition_shard_index_names/11.0-1.sql" #include "udfs/worker_fix_partition_shard_index_names/11.0-1.sql" +ALTER TABLE pg_catalog.pg_dist_partition ADD COLUMN autoconverted boolean; DROP FUNCTION IF EXISTS pg_catalog.master_apply_delete_command(text); DROP FUNCTION pg_catalog.master_get_table_metadata(text); diff --git a/src/backend/distributed/sql/downgrades/citus--10.2-1--10.1-1.sql b/src/backend/distributed/sql/downgrades/citus--10.2-1--10.1-1.sql index fad472442..1e47b42c4 100644 --- a/src/backend/distributed/sql/downgrades/citus--10.2-1--10.1-1.sql +++ b/src/backend/distributed/sql/downgrades/citus--10.2-1--10.1-1.sql @@ -25,7 +25,6 @@ DROP PROCEDURE pg_catalog.drop_old_time_partitions(regclass, timestamptz); REVOKE ALL ON FUNCTION pg_catalog.worker_record_sequence_dependency(regclass,regclass,name) FROM PUBLIC; ALTER TABLE pg_catalog.pg_dist_placement DROP CONSTRAINT placement_shardid_groupid_unique_index; -ALTER TABLE pg_catalog.pg_dist_partition DROP COLUMN autoconverted; DROP FUNCTION pg_catalog.citus_drop_all_shards(regclass, text, text, boolean); CREATE FUNCTION pg_catalog.citus_drop_all_shards(logicalrelid regclass, diff --git a/src/backend/distributed/sql/downgrades/citus--11.0-1--10.2-3.sql b/src/backend/distributed/sql/downgrades/citus--11.0-1--10.2-3.sql index 491e42633..60a431121 100644 --- a/src/backend/distributed/sql/downgrades/citus--11.0-1--10.2-3.sql +++ b/src/backend/distributed/sql/downgrades/citus--11.0-1--10.2-3.sql @@ -4,6 +4,8 @@ DROP FUNCTION pg_catalog.fix_all_partition_shard_index_names(); DROP FUNCTION pg_catalog.fix_partition_shard_index_names(regclass); DROP FUNCTION pg_catalog.worker_fix_partition_shard_index_names(regclass, text, text); +ALTER TABLE pg_catalog.pg_dist_partition DROP COLUMN autoconverted; + CREATE FUNCTION pg_catalog.master_apply_delete_command(text) RETURNS integer LANGUAGE C STRICT diff --git a/src/test/regress/expected/multi_master_delete_protocol.out b/src/test/regress/expected/multi_master_delete_protocol.out new file mode 100644 index 000000000..365201f36 --- /dev/null +++ b/src/test/regress/expected/multi_master_delete_protocol.out @@ -0,0 +1,105 @@ +-- +-- MULTI_MASTER_DELETE_PROTOCOL +-- +SET citus.next_shard_id TO 320000; +-- Create a new range partitioned customer_delete_protocol table and load data into it. +CREATE TABLE customer_delete_protocol ( + c_custkey integer not null, + c_name varchar(25) not null, + c_address varchar(40) not null, + c_nationkey integer not null, + c_phone char(15) not null, + c_acctbal decimal(15,2) not null, + c_mktsegment char(10) not null, + c_comment varchar(117) not null); +SELECT master_create_distributed_table('customer_delete_protocol', 'c_custkey', 'append'); + master_create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.1.data' with delimiter '|' +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.2.data' with delimiter '|' +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.3.data' with delimiter '|' +-- Testing master_apply_delete_command +-- Check that we don't support conditions on columns other than partition key. +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_acctbal > 0.0'); +ERROR: cannot delete from distributed table +DETAIL: Where clause includes a column other than partition column +-- Check that we delete a shard if and only if all rows in the shard satisfy the condition. +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 6500'); + master_apply_delete_command +--------------------------------------------------------------------- + 0 +(1 row) + +SELECT count(*) from customer_delete_protocol; + count +--------------------------------------------------------------------- + 3000 +(1 row) + +-- Delete one shard that satisfies the given conditions. +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 1000 AND c_custkey < 3000'); + master_apply_delete_command +--------------------------------------------------------------------- + 1 +(1 row) + +SELECT count(*) from customer_delete_protocol; + count +--------------------------------------------------------------------- + 2000 +(1 row) + +-- Delete all shards if no condition is provided. +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); + master_apply_delete_command +--------------------------------------------------------------------- + 2 +(1 row) + +SELECT count(*) FROM customer_delete_protocol; + count +--------------------------------------------------------------------- + 0 +(1 row) + +-- Verify that empty shards are deleted if no condition is provided +SELECT 1 AS one FROM master_create_empty_shard('customer_delete_protocol'); + one +--------------------------------------------------------------------- + 1 +(1 row) + +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 1000'); + master_apply_delete_command +--------------------------------------------------------------------- + 0 +(1 row) + +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); + master_apply_delete_command +--------------------------------------------------------------------- + 1 +(1 row) + +-- Verify that master_apply_delete_command can be called in a transaction block +SELECT 1 AS one FROM master_create_empty_shard('customer_delete_protocol'); + one +--------------------------------------------------------------------- + 1 +(1 row) + +BEGIN; +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); + master_apply_delete_command +--------------------------------------------------------------------- + 1 +(1 row) + +COMMIT; diff --git a/src/test/regress/sql/multi_master_delete_protocol.sql b/src/test/regress/sql/multi_master_delete_protocol.sql new file mode 100644 index 000000000..2cabf82db --- /dev/null +++ b/src/test/regress/sql/multi_master_delete_protocol.sql @@ -0,0 +1,56 @@ +-- +-- MULTI_MASTER_DELETE_PROTOCOL +-- + + +SET citus.next_shard_id TO 320000; + + +-- Create a new range partitioned customer_delete_protocol table and load data into it. +CREATE TABLE customer_delete_protocol ( + c_custkey integer not null, + c_name varchar(25) not null, + c_address varchar(40) not null, + c_nationkey integer not null, + c_phone char(15) not null, + c_acctbal decimal(15,2) not null, + c_mktsegment char(10) not null, + c_comment varchar(117) not null); +SELECT master_create_distributed_table('customer_delete_protocol', 'c_custkey', 'append'); + +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.1.data' with delimiter '|' +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.2.data' with delimiter '|' +\copy customer_delete_protocol FROM '/home/ahmet/citus/src/test/regress/data/customer.3.data' with delimiter '|' + +-- Testing master_apply_delete_command +-- Check that we don't support conditions on columns other than partition key. + +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_acctbal > 0.0'); +-- Check that we delete a shard if and only if all rows in the shard satisfy the condition. +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 6500'); +SELECT count(*) from customer_delete_protocol; + +-- Delete one shard that satisfies the given conditions. + +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 1000 AND c_custkey < 3000'); +SELECT count(*) from customer_delete_protocol; + +-- Delete all shards if no condition is provided. + +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); +SELECT count(*) FROM customer_delete_protocol; + +-- Verify that empty shards are deleted if no condition is provided +SELECT 1 AS one FROM master_create_empty_shard('customer_delete_protocol'); +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol + WHERE c_custkey > 1000'); +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); + +-- Verify that master_apply_delete_command can be called in a transaction block +SELECT 1 AS one FROM master_create_empty_shard('customer_delete_protocol'); +BEGIN; +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol'); +COMMIT;