Skip to content

Commit

Permalink
Merge #77004
Browse files Browse the repository at this point in the history
77004: sql: add bucket count limit for hash sharded index r=chengxiong-ruan a=chengxiong-ruan

Fixes #77000

Release note (sql change): Previously we only require the bucket
count a positive Int32 integer (greater than 1). Now it's limited
to inclusive range of [2, 2048].

Co-authored-by: Chengxiong Ruan <[email protected]>
  • Loading branch information
craig[bot] and chengxiong-ruan committed Feb 25, 2022
2 parents cdd55fb + d873a27 commit bc8cbe6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/catalog/tabledesc/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package tabledesc
import (
"context"
"fmt"
"math"
"sort"
"strings"

Expand Down Expand Up @@ -239,7 +238,8 @@ func EvalShardBucketCount(
}

var buckets int64
const invalidBucketCountMsg = `BUCKET_COUNT must be a 32-bit integer greater than 1, got %v`
const maxBucketAllowed = 2048
const invalidBucketCountMsg = `hash sharded index bucket count must be in range [2, 2048], got %v`
// If shardBuckets is not specified, use default bucket count from cluster setting.
if legacyBucketNotGiven && paramVal == nil {
buckets = catconstants.DefaultHashShardedIndexBucketCount.Get(&evalCtx.Settings.SV)
Expand All @@ -262,7 +262,7 @@ func EvalShardBucketCount(
if buckets < 2 {
return 0, pgerror.Newf(pgcode.InvalidParameterValue, invalidBucketCountMsg, buckets)
}
if buckets > math.MaxInt32 {
if buckets > maxBucketAllowed {
return 0, pgerror.Newf(pgcode.InvalidParameterValue, invalidBucketCountMsg, buckets)
}
return int32(buckets), nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/hash_sharded_index
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ sharded_primary CREATE TABLE public.sharded_primary (
CONSTRAINT sharded_primary_pkey PRIMARY KEY (a ASC) USING HASH WITH (bucket_count=10)
)

statement error pgcode 22023 BUCKET_COUNT must be a 32-bit integer greater than 1, got -1
statement error pgcode 22023 hash sharded index bucket count must be in range \[2, 2048\], got -1
CREATE TABLE invalid_bucket_count (k INT PRIMARY KEY USING HASH WITH (bucket_count=-1))

statement error pgcode 22023 BUCKET_COUNT must be a 32-bit integer greater than 1, got 1099511627776
CREATE TABLE invalid_bucket_count (k INT PRIMARY KEY USING HASH WITH (bucket_count=1099511627776))
statement error pgcode 22023 hash sharded index bucket count must be in range \[2, 2048\], got 999999999
CREATE TABLE invalid_bucket_count (k INT PRIMARY KEY USING HASH WITH (bucket_count=999999999))

statement error pgcode 22023 BUCKET_COUNT must be a 32-bit integer greater than 1, got 1
statement error pgcode 22023 hash sharded index bucket count must be in range \[2, 2048\], got 1
CREATE TABLE invalid_bucket_count (k INT PRIMARY KEY USING HASH WITH (bucket_count=1))

statement error expected BUCKET_COUNT expression to have type int, but '2.32' has type decimal
Expand Down

0 comments on commit bc8cbe6

Please sign in to comment.