Skip to content

Commit

Permalink
sql: internal error with BUCKET_COUNT = NULL
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vidit-bhat committed Sep 23, 2024
1 parent a0080c7 commit ff1bb00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/sql/catalog/tabledesc/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/create_table
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit ff1bb00

Please sign in to comment.