mirror of https://github.com/citusdata/citus.git
Disallow adding local table with identity column to metadata (#4633)
pg_get_tableschemadef_string doesn't know how to deparse identity columns so we cannot reflect those columns when creating shell relation. For this reason, we don't allow adding local tables -having identity cols- to metadata.pull/4635/head
parent
5efb742f8a
commit
3a403090fd
|
@ -49,6 +49,7 @@ static void citus_add_local_table_to_metadata_internal(Oid relationId,
|
||||||
bool cascadeViaForeignKeys);
|
bool cascadeViaForeignKeys);
|
||||||
static void ErrorIfUnsupportedCreateCitusLocalTable(Relation relation);
|
static void ErrorIfUnsupportedCreateCitusLocalTable(Relation relation);
|
||||||
static void ErrorIfUnsupportedCitusLocalTableKind(Oid relationId);
|
static void ErrorIfUnsupportedCitusLocalTableKind(Oid relationId);
|
||||||
|
static void ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation);
|
||||||
static List * GetShellTableDDLEventsForCitusLocalTable(Oid relationId);
|
static List * GetShellTableDDLEventsForCitusLocalTable(Oid relationId);
|
||||||
static uint64 ConvertLocalTableToShard(Oid relationId);
|
static uint64 ConvertLocalTableToShard(Oid relationId);
|
||||||
static void RenameRelationToShardRelation(Oid shellRelationId, uint64 shardId);
|
static void RenameRelationToShardRelation(Oid shellRelationId, uint64 shardId);
|
||||||
|
@ -338,6 +339,7 @@ ErrorIfUnsupportedCreateCitusLocalTable(Relation relation)
|
||||||
ErrorIfCoordinatorNotAddedAsWorkerNode();
|
ErrorIfCoordinatorNotAddedAsWorkerNode();
|
||||||
ErrorIfUnsupportedCitusLocalTableKind(relationId);
|
ErrorIfUnsupportedCitusLocalTableKind(relationId);
|
||||||
EnsureTableNotDistributed(relationId);
|
EnsureTableNotDistributed(relationId);
|
||||||
|
ErrorIfUnsupportedCitusLocalColumnDefinition(relation);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When creating other citus table types, we don't need to check that case as
|
* When creating other citus table types, we don't need to check that case as
|
||||||
|
@ -405,6 +407,30 @@ ErrorIfUnsupportedCitusLocalTableKind(Oid relationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ErrorIfUnsupportedCitusLocalColumnDefinition errors out if given relation
|
||||||
|
* has unsupported column definition for citus local table creation.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
ErrorIfUnsupportedCitusLocalColumnDefinition(Relation relation)
|
||||||
|
{
|
||||||
|
TupleDesc relationDesc = RelationGetDescr(relation);
|
||||||
|
if (RelationUsesIdentityColumns(relationDesc))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* pg_get_tableschemadef_string doesn't know how to deparse identity
|
||||||
|
* columns so we cannot reflect those columns when creating shell
|
||||||
|
* relation. For this reason, error out here.
|
||||||
|
*/
|
||||||
|
Oid relationId = relation->rd_id;
|
||||||
|
ereport(ERROR, (errmsg("cannot add %s to citus metadata since table "
|
||||||
|
"has identity column",
|
||||||
|
generate_qualified_relation_name(relationId)),
|
||||||
|
errhint("Drop the identity columns and re-try the command")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetShellTableDDLEventsForCitusLocalTable returns a list of DDL commands
|
* GetShellTableDDLEventsForCitusLocalTable returns a list of DDL commands
|
||||||
* to create the shell table from scratch.
|
* to create the shell table from scratch.
|
||||||
|
|
|
@ -122,7 +122,6 @@ static void DropFKeysRelationInvolvedWithTableType(Oid relationId, int tableType
|
||||||
static bool LocalTableEmpty(Oid tableId);
|
static bool LocalTableEmpty(Oid tableId);
|
||||||
static void CopyLocalDataIntoShards(Oid relationId);
|
static void CopyLocalDataIntoShards(Oid relationId);
|
||||||
static List * TupleDescColumnNameList(TupleDesc tupleDescriptor);
|
static List * TupleDescColumnNameList(TupleDesc tupleDescriptor);
|
||||||
static bool RelationUsesIdentityColumns(TupleDesc relationDesc);
|
|
||||||
static bool DistributionColumnUsesGeneratedStoredColumn(TupleDesc relationDesc,
|
static bool DistributionColumnUsesGeneratedStoredColumn(TupleDesc relationDesc,
|
||||||
Var *distributionColumn);
|
Var *distributionColumn);
|
||||||
static bool CanUseExclusiveConnections(Oid relationId, bool localTableEmpty);
|
static bool CanUseExclusiveConnections(Oid relationId, bool localTableEmpty);
|
||||||
|
@ -1636,7 +1635,7 @@ TupleDescColumnNameList(TupleDesc tupleDescriptor)
|
||||||
* RelationUsesIdentityColumns returns whether a given relation uses
|
* RelationUsesIdentityColumns returns whether a given relation uses
|
||||||
* GENERATED ... AS IDENTITY
|
* GENERATED ... AS IDENTITY
|
||||||
*/
|
*/
|
||||||
static bool
|
bool
|
||||||
RelationUsesIdentityColumns(TupleDesc relationDesc)
|
RelationUsesIdentityColumns(TupleDesc relationDesc)
|
||||||
{
|
{
|
||||||
for (int attributeIndex = 0; attributeIndex < relationDesc->natts; attributeIndex++)
|
for (int attributeIndex = 0; attributeIndex < relationDesc->natts; attributeIndex++)
|
||||||
|
|
|
@ -249,6 +249,7 @@ extern void EnsureTableNotDistributed(Oid relationId);
|
||||||
extern void EnsureReplicationSettings(Oid relationId, char replicationModel);
|
extern void EnsureReplicationSettings(Oid relationId, char replicationModel);
|
||||||
extern void EnsureRelationExists(Oid relationId);
|
extern void EnsureRelationExists(Oid relationId);
|
||||||
extern bool RegularTable(Oid relationId);
|
extern bool RegularTable(Oid relationId);
|
||||||
|
extern bool RelationUsesIdentityColumns(TupleDesc relationDesc);
|
||||||
extern char * ConstructQualifiedShardName(ShardInterval *shardInterval);
|
extern char * ConstructQualifiedShardName(ShardInterval *shardInterval);
|
||||||
extern uint64 GetFirstShardId(Oid relationId);
|
extern uint64 GetFirstShardId(Oid relationId);
|
||||||
extern Datum StringToDatum(char *inputString, Oid dataType);
|
extern Datum StringToDatum(char *inputString, Oid dataType);
|
||||||
|
|
|
@ -56,6 +56,18 @@ BEGIN;
|
||||||
SELECT citus_add_local_table_to_metadata('temp_table');
|
SELECT citus_add_local_table_to_metadata('temp_table');
|
||||||
ERROR: constraints on temporary tables may reference only temporary tables
|
ERROR: constraints on temporary tables may reference only temporary tables
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
-- below two errors out since we don't support adding local tables
|
||||||
|
-- having any identity columns to metadata
|
||||||
|
BEGIN;
|
||||||
|
CREATE TABLE identity_cols_test (a int generated by default as identity (start with 42));
|
||||||
|
SELECT citus_add_local_table_to_metadata('identity_cols_test');
|
||||||
|
ERROR: cannot add citus_local_tables_test_schema.identity_cols_test to citus metadata since table has identity column
|
||||||
|
ROLLBACK;
|
||||||
|
BEGIN;
|
||||||
|
CREATE TABLE identity_cols_test (a int generated always as identity (increment by 42));
|
||||||
|
SELECT citus_add_local_table_to_metadata('identity_cols_test');
|
||||||
|
ERROR: cannot add citus_local_tables_test_schema.identity_cols_test to citus metadata since table has identity column
|
||||||
|
ROLLBACK;
|
||||||
-- creating citus local table having no data initially would work
|
-- creating citus local table having no data initially would work
|
||||||
SELECT citus_add_local_table_to_metadata('citus_local_table_1');
|
SELECT citus_add_local_table_to_metadata('citus_local_table_1');
|
||||||
citus_add_local_table_to_metadata
|
citus_add_local_table_to_metadata
|
||||||
|
|
|
@ -46,6 +46,18 @@ BEGIN;
|
||||||
SELECT citus_add_local_table_to_metadata('temp_table');
|
SELECT citus_add_local_table_to_metadata('temp_table');
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
|
||||||
|
-- below two errors out since we don't support adding local tables
|
||||||
|
-- having any identity columns to metadata
|
||||||
|
BEGIN;
|
||||||
|
CREATE TABLE identity_cols_test (a int generated by default as identity (start with 42));
|
||||||
|
SELECT citus_add_local_table_to_metadata('identity_cols_test');
|
||||||
|
ROLLBACK;
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
CREATE TABLE identity_cols_test (a int generated always as identity (increment by 42));
|
||||||
|
SELECT citus_add_local_table_to_metadata('identity_cols_test');
|
||||||
|
ROLLBACK;
|
||||||
|
|
||||||
-- creating citus local table having no data initially would work
|
-- creating citus local table having no data initially would work
|
||||||
SELECT citus_add_local_table_to_metadata('citus_local_table_1');
|
SELECT citus_add_local_table_to_metadata('citus_local_table_1');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue