From cb7af849544f146ba713392b75f2dc08c44e0209 Mon Sep 17 00:00:00 2001 From: Dorin Hogea Date: Wed, 2 Oct 2024 15:57:26 -0400 Subject: [PATCH] block partitioning a table that is the target of a constraint Signed-off-by: Dorin Hogea --- sqlite/src/comdb2build.c | 12 +++++++++++- tests/timepart_trunc.test/run.log.alpha | 2 ++ tests/timepart_trunc.test/runit | 21 +++++++++++++++++++++ tests/timepart_trunc.test/t21.csc2 | 8 ++++++++ tests/timepart_trunc.test/t22.csc2 | 12 ++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/timepart_trunc.test/t21.csc2 create mode 100644 tests/timepart_trunc.test/t22.csc2 diff --git a/sqlite/src/comdb2build.c b/sqlite/src/comdb2build.c index 049a0bf3ea..269f3a55f9 100644 --- a/sqlite/src/comdb2build.c +++ b/sqlite/src/comdb2build.c @@ -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); diff --git a/tests/timepart_trunc.test/run.log.alpha b/tests/timepart_trunc.test/run.log.alpha index 1472933e5b..46a7d905ea 100644 --- a/tests/timepart_trunc.test/run.log.alpha +++ b/tests/timepart_trunc.test/run.log.alpha @@ -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 diff --git a/tests/timepart_trunc.test/runit b/tests/timepart_trunc.test/runit index 6c642024ef..6eb213a2ae 100755 --- a/tests/timepart_trunc.test/runit +++ b/tests/timepart_trunc.test/runit @@ -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 diff --git a/tests/timepart_trunc.test/t21.csc2 b/tests/timepart_trunc.test/t21.csc2 new file mode 100644 index 0000000000..5a5edc8e78 --- /dev/null +++ b/tests/timepart_trunc.test/t21.csc2 @@ -0,0 +1,8 @@ +schema +{ + int a +} +keys +{ + "a" = a +} diff --git a/tests/timepart_trunc.test/t22.csc2 b/tests/timepart_trunc.test/t22.csc2 new file mode 100644 index 0000000000..ffa28ede25 --- /dev/null +++ b/tests/timepart_trunc.test/t22.csc2 @@ -0,0 +1,12 @@ +schema +{ + int a +} +keys +{ + "a" = a +} +constraints +{ + "a" -> <"t21":"a"> +}