Skip to content

Commit

Permalink
block partitioning a table that is the target of a constraint
Browse files Browse the repository at this point in the history
Signed-off-by: Dorin Hogea <[email protected]>
  • Loading branch information
dorinhogea committed Oct 3, 2024
1 parent 358802d commit cb7af84
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sqlite/src/comdb2build.c
Original file line number Diff line number Diff line change
Expand Up @@ -4862,8 +4862,18 @@ void comdb2AlterTableEnd(Parse *pParse)
sc->force = 1;
}

if (ctx->partition)
if (ctx->partition) {
sc->partition = *ctx->partition;
if (sc->partition.type == PARTITION_ADD_TIMED) {
struct dbtable * tbl = get_dbtable_by_name(sc->tablename);
if (tbl && tbl->n_rev_constraints > 0) {

setError(pParse, SQLITE_MISUSE,
"Cannot partition a constraint target table");
goto cleanup;
}
}
}

/* prepare_csc2 can free the ctx, do not touch it afterwards ! */
sc->newcsc2 = prepare_csc2(pParse, ctx);
Expand Down
2 changes: 2 additions & 0 deletions tests/timepart_trunc.test/run.log.alpha
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,5 @@ TEST 18
Test block alter
TEST 19
Test check for partition new over old shards
TEST 20
Test block alter of a constraint target table
21 changes: 21 additions & 0 deletions tests/timepart_trunc.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,27 @@ if (( $? == 0 )) ; then
exit 1
fi

header 20 "Test block alter of a constraint target table"
$cmd "create table t21 {`cat t21.csc2`}"
if (( $? != 0 )) ; then
echo "FAILURE to create table tv21"
exit 1
fi


$cmd "create table t22 {`cat t22.csc2`}"
if (( $? != 0 )) ; then
echo "FAILURE to create table tv22"
exit 1
fi

$cmd "alter table t21 partitioned by time period 'daily' retention 2 start '2024-01-01T'"
if (( $? == 0 )) ; then
echo "FAILURE to block partitioning a constraint target table"
exit 1
fi



# we need to scrub dbname from alpha
sed "s/dorintdb/$dbname/g; s#\${CDB2_OPTIONS}#${CDB2_OPTIONS}#g" $OUT.alpha > $OUT.alpha.actual
Expand Down
8 changes: 8 additions & 0 deletions tests/timepart_trunc.test/t21.csc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
schema
{
int a
}
keys
{
"a" = a
}
12 changes: 12 additions & 0 deletions tests/timepart_trunc.test/t22.csc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
schema
{
int a
}
keys
{
"a" = a
}
constraints
{
"a" -> <"t21":"a">
}

0 comments on commit cb7af84

Please sign in to comment.