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: cockroachdb#130353
Release note: None
  • Loading branch information
vidit-bhat committed Sep 23, 2024
1 parent d644373 commit ff5e3cd
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 @@ -285,6 +285,10 @@ func EvalShardBucketCount(
if paramVal != nil {
shardBuckets = paramVal
}
// Check if shardBuckets is NULL
if shardBuckets == tree.DNull {
return 0, pgerror.Newf(pgcode.InvalidParameterValue, `"BUCKET_COUNT" cannot be 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 @@ -739,6 +739,10 @@ CREATE TABLE t_bad_param (
a INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 5 WITH (bucket_count=5)
);

statement error pq: "BUCKET_COUNT" cannot be 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 ff5e3cd

Please sign in to comment.