Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Table and Index partitioning in Babelfish #399

Merged
10 changes: 10 additions & 0 deletions src/backend/access/common/reloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ static void initialize_reloptions(void);
static void parse_one_reloption(relopt_value *option, char *text_str,
int text_len, bool validate);

pltsql_is_partitioned_table_reloptions_allowed_hook_type pltsql_is_partitioned_table_reloptions_allowed_hook = NULL;

/*
* Get the length of a string reloption (either default or the user-defined
* value). This is used for allocation purposes when building a set of
Expand Down Expand Up @@ -2001,10 +2003,18 @@ bytea *
partitioned_table_reloptions(Datum reloptions, bool validate)
{
if (validate && reloptions)
{
/*
* For babelfish partitioned table, allow usage of reloptions in TSQL dialect.
*/
if (pltsql_is_partitioned_table_reloptions_allowed_hook && pltsql_is_partitioned_table_reloptions_allowed_hook(reloptions))
return NULL;

ereport(ERROR,
errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot specify storage parameters for a partitioned table"),
errhint("Specify storage parameters for its leaf partitions instead."));
}
return NULL;
}

Expand Down
4 changes: 3 additions & 1 deletion src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -8868,6 +8868,7 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
char constraintType;
ObjectAddress address;
bits16 flags;
const char *bbf_dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false);

Assert(IsA(stmt, IndexStmt));
Assert(OidIsValid(index_oid));
Expand All @@ -8877,7 +8878,8 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel,
* Doing this on partitioned tables is not a simple feature to implement,
* so let's punt for now.
*/
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
(!bbf_dump_restore || strcmp(bbf_dump_restore, "on") != 0)) /* For Babelfish databases, allow the restore of index for partitioned table. */
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables")));
Expand Down
9 changes: 7 additions & 2 deletions src/backend/parser/parse_utilcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,13 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
errmsg("index \"%s\" does not belong to table \"%s\"",
index_name, RelationGetRelationName(heap_rel)),
parser_errposition(cxt->pstate, constraint->location)));

if (!index_form->indisvalid)
/*
* For Babelfish databases, allow the restore of index which is
* marked as not valid for partitioned table.
*/
if (!index_form->indisvalid &&
!(bbf_dump_restore && strcmp(bbf_dump_restore, "on") == 0 &&
RelationGetForm(heap_rel)->relkind == RELKIND_PARTITIONED_TABLE))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("index \"%s\" is not valid", index_name),
Expand Down
2 changes: 2 additions & 0 deletions src/include/access/reloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,7 @@ extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
extern bytea *attribute_reloptions(Datum reloptions, bool validate);
extern bytea *tablespace_reloptions(Datum reloptions, bool validate);
extern LOCKMODE AlterTableGetRelOptionsLockLevel(List *defList);
typedef bool (*pltsql_is_partitioned_table_reloptions_allowed_hook_type)();
extern PGDLLEXPORT pltsql_is_partitioned_table_reloptions_allowed_hook_type pltsql_is_partitioned_table_reloptions_allowed_hook;

#endif /* RELOPTIONS_H */
1 change: 1 addition & 0 deletions src/include/nodes/parsenodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ typedef struct PartitionSpec
PartitionStrategy strategy;
List *partParams; /* List of PartitionElems */
int location; /* token location, or -1 if unknown */
char *tsql_partition_scheme; /* tsql partition scheme name */
} PartitionSpec;

/*
Expand Down
Loading