mirror of https://github.com/citusdata/citus.git
ALTER TABLE .. REPLICA IDENTITY support is implemented
parent
4a17d12d74
commit
61ae33dc7f
|
@ -1897,6 +1897,7 @@ ErrorIfUnsupportedDropIndexStmt(DropStmt *dropIndexStatement)
|
||||||
* ALTER TABLE SET|DROP NOT NULL
|
* ALTER TABLE SET|DROP NOT NULL
|
||||||
* ALTER TABLE SET|DROP DEFAULT
|
* ALTER TABLE SET|DROP DEFAULT
|
||||||
* ALTER TABLE ADD|DROP CONSTRAINT
|
* ALTER TABLE ADD|DROP CONSTRAINT
|
||||||
|
* ALTER TABLE REPLICA IDENTITY
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
|
ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
|
||||||
|
@ -2036,11 +2037,12 @@ ErrorIfUnsupportedAlterTableStmt(AlterTableStmt *alterTableStatement)
|
||||||
case AT_DropConstraint:
|
case AT_DropConstraint:
|
||||||
case AT_EnableTrigAll:
|
case AT_EnableTrigAll:
|
||||||
case AT_DisableTrigAll:
|
case AT_DisableTrigAll:
|
||||||
|
case AT_ReplicaIdentity:
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We will not perform any special check for ALTER TABLE DROP CONSTRAINT
|
* We will not perform any special check for ALTER TABLE DROP CONSTRAINT
|
||||||
* , ALTER TABLE .. ALTER COLUMN .. SET NOT NULL and ALTER TABLE ENABLE/
|
* , ALTER TABLE .. ALTER COLUMN .. SET NOT NULL and ALTER TABLE ENABLE/
|
||||||
* DISABLE TRIGGER ALL
|
* DISABLE TRIGGER ALL, ALTER TABLE .. REPLICA IDENTITY ..
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "access/stratnum.h"
|
#include "access/stratnum.h"
|
||||||
#include "catalog/indexing.h"
|
#include "catalog/indexing.h"
|
||||||
#include "catalog/namespace.h"
|
#include "catalog/namespace.h"
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
#include "catalog/pg_constraint.h"
|
#include "catalog/pg_constraint.h"
|
||||||
#include "distributed/metadata_cache.h"
|
#include "distributed/metadata_cache.h"
|
||||||
#include "distributed/relay_utility.h"
|
#include "distributed/relay_utility.h"
|
||||||
|
@ -109,6 +110,17 @@ RelayEventExtendNames(Node *parseTree, char *schemaName, uint64 shardId)
|
||||||
char **indexName = &(command->name);
|
char **indexName = &(command->name);
|
||||||
AppendShardIdToName(indexName, shardId);
|
AppendShardIdToName(indexName, shardId);
|
||||||
}
|
}
|
||||||
|
else if (command->subtype == AT_ReplicaIdentity)
|
||||||
|
{
|
||||||
|
ReplicaIdentityStmt *replicaIdentity =
|
||||||
|
(ReplicaIdentityStmt *) command->def;
|
||||||
|
|
||||||
|
if (replicaIdentity->identity_type == REPLICA_IDENTITY_INDEX)
|
||||||
|
{
|
||||||
|
char **indexName = &(replicaIdentity->name);
|
||||||
|
AppendShardIdToName(indexName, shardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -240,10 +240,37 @@ COMMIT;
|
||||||
SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'lineitem_alter';
|
SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'lineitem_alter';
|
||||||
|
|
||||||
-- Create single-shard table (to avoid deadlocks in the upcoming test hackery)
|
-- Create single-shard table (to avoid deadlocks in the upcoming test hackery)
|
||||||
CREATE TABLE single_shard_items (id integer, name text);
|
CREATE TABLE single_shard_items (id integer NOT NULL, name text);
|
||||||
SELECT master_create_distributed_table('single_shard_items', 'id', 'hash');
|
SELECT master_create_distributed_table('single_shard_items', 'id', 'hash');
|
||||||
SELECT master_create_worker_shards('single_shard_items', 1, 2);
|
SELECT master_create_worker_shards('single_shard_items', 1, 2);
|
||||||
|
|
||||||
|
-- Verify that ALTER TABLE .. REPLICATION IDENTITY [USING INDEX]* .. works
|
||||||
|
CREATE UNIQUE INDEX replica_idx on single_shard_items(id);
|
||||||
|
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY nothing;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY full;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY USING INDEX replica_idx;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY default, REPLICA IDENTITY USING INDEX replica_idx, REPLICA IDENTITY nothing;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items ADD COLUMN test_col int, REPLICA IDENTITY full;
|
||||||
|
|
||||||
|
DROP INDEX replica_idx;
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY default;
|
||||||
|
|
||||||
-- Drop the column from the worker...
|
-- Drop the column from the worker...
|
||||||
\c - - - :worker_2_port
|
\c - - - :worker_2_port
|
||||||
ALTER TABLE lineitem_alter_220000 DROP COLUMN first;
|
ALTER TABLE lineitem_alter_220000 DROP COLUMN first;
|
||||||
|
|
|
@ -539,7 +539,7 @@ SELECT indexname, tablename FROM pg_indexes WHERE tablename = 'lineitem_alter';
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
-- Create single-shard table (to avoid deadlocks in the upcoming test hackery)
|
-- Create single-shard table (to avoid deadlocks in the upcoming test hackery)
|
||||||
CREATE TABLE single_shard_items (id integer, name text);
|
CREATE TABLE single_shard_items (id integer NOT NULL, name text);
|
||||||
SELECT master_create_distributed_table('single_shard_items', 'id', 'hash');
|
SELECT master_create_distributed_table('single_shard_items', 'id', 'hash');
|
||||||
master_create_distributed_table
|
master_create_distributed_table
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
@ -552,6 +552,80 @@ SELECT master_create_worker_shards('single_shard_items', 1, 2);
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- Verify that ALTER TABLE .. REPLICATION IDENTITY [USING INDEX]* .. works
|
||||||
|
CREATE UNIQUE INDEX replica_idx on single_shard_items(id);
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
relreplident
|
||||||
|
--------------
|
||||||
|
d
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
run_command_on_workers
|
||||||
|
------------------------
|
||||||
|
(localhost,57637,t,d)
|
||||||
|
(localhost,57638,t,d)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY nothing;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
relreplident
|
||||||
|
--------------
|
||||||
|
n
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
run_command_on_workers
|
||||||
|
------------------------
|
||||||
|
(localhost,57637,t,n)
|
||||||
|
(localhost,57638,t,n)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY full;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
relreplident
|
||||||
|
--------------
|
||||||
|
f
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
run_command_on_workers
|
||||||
|
------------------------
|
||||||
|
(localhost,57637,t,f)
|
||||||
|
(localhost,57638,t,f)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY USING INDEX replica_idx;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
relreplident
|
||||||
|
--------------
|
||||||
|
i
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
run_command_on_workers
|
||||||
|
------------------------
|
||||||
|
(localhost,57637,t,i)
|
||||||
|
(localhost,57638,t,i)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY default, REPLICA IDENTITY USING INDEX replica_idx, REPLICA IDENTITY nothing;
|
||||||
|
SELECT relreplident FROM pg_class WHERE relname = 'single_shard_items';
|
||||||
|
relreplident
|
||||||
|
--------------
|
||||||
|
n
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT run_command_on_workers('SELECT relreplident FROM pg_class WHERE relname LIKE ''single_shard_items_%'' LIMIT 1;');
|
||||||
|
run_command_on_workers
|
||||||
|
------------------------
|
||||||
|
(localhost,57637,t,n)
|
||||||
|
(localhost,57638,t,n)
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
ALTER TABLE single_shard_items ADD COLUMN test_col int, REPLICA IDENTITY full;
|
||||||
|
DROP INDEX replica_idx;
|
||||||
|
ALTER TABLE single_shard_items REPLICA IDENTITY default;
|
||||||
-- Drop the column from the worker...
|
-- Drop the column from the worker...
|
||||||
\c - - - :worker_2_port
|
\c - - - :worker_2_port
|
||||||
ALTER TABLE lineitem_alter_220000 DROP COLUMN first;
|
ALTER TABLE lineitem_alter_220000 DROP COLUMN first;
|
||||||
|
|
Loading…
Reference in New Issue