From ff1bb00d5fb80f8f4059adf7e12118641b82c98f Mon Sep 17 00:00:00 2001 From: Vidit Bhat Date: Mon, 23 Sep 2024 15:25:25 +0000 Subject: [PATCH] sql: internal error with BUCKET_COUNT = NULL Previously, the `EvalShardBucketCount` function did not properly handle the case where `BUCKET_COUNT` was set to `NULL`, causing evaluation errors. This change adds explicit handling for `NULL` values, ensuring that `BUCKET_COUNT` cannot be set to `NULL` and returns an appropriate error message. Also added a check for NULL before sanitizing and evaluating shardBuckets to avoid invalid operations on NULL values. returns the error `BUCKET_COUNT cannot be NULL`. Epic: none Fixes: #130353 Release note: None --- pkg/sql/catalog/tabledesc/table.go | 4 ++++ pkg/sql/logictest/testdata/logic_test/create_table | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pkg/sql/catalog/tabledesc/table.go b/pkg/sql/catalog/tabledesc/table.go index 6da84a050b8e..caee0dc0fd56 100644 --- a/pkg/sql/catalog/tabledesc/table.go +++ b/pkg/sql/catalog/tabledesc/table.go @@ -281,6 +281,10 @@ func EvalShardBucketCount( if paramVal != nil { shardBuckets = paramVal } + // Check if shardBuckets is NULL + if shardBuckets == tree.DNull { + return 0, pgerror.Newf(pgcode.InvalidParameterValue, invalidBucketCountMsg, "NULL") + } typedExpr, err := schemaexpr.SanitizeVarFreeExpr( ctx, shardBuckets, types.Int, "BUCKET_COUNT", semaCtx, volatility.Volatile, false, /*allowAssignmentCast*/ ) diff --git a/pkg/sql/logictest/testdata/logic_test/create_table b/pkg/sql/logictest/testdata/logic_test/create_table index 9d1f8a68c0b6..7a371a700152 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_table +++ b/pkg/sql/logictest/testdata/logic_test/create_table @@ -737,6 +737,10 @@ CREATE TABLE t_bad_param ( a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 5 WITH (bucket_count=5) ); +statement error pq: hash sharded index bucket count must be in range \[2, 2048\], got NULL +CREATE TABLE t_bad_param ( + a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = NULL +); statement error pq: invalid storage param "s2_max_level" on primary key CREATE TABLE t_bad_param (