Skip to content

Commit

Permalink
sql: support hash sharded index default bucket count
Browse files Browse the repository at this point in the history
Fixes #74739

Release not (sql change): We used to always create hash sharded
index by specifying a bucket count. With this change, user does
not need to do that anymore. Hash index can be created with just
`USING HASH` instead of `USING HASH WITH BUCKET_COUNT = xxx`. A
default bucket count 8 will be used.
  • Loading branch information
chengxiong-ruan committed Jan 25, 2022
1 parent 421a767 commit 313d085
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ sql.cross_db_sequence_references.enabled boolean false if true, sequences refere
sql.cross_db_views.enabled boolean false if true, creating views that refer to other databases is allowed
sql.defaults.datestyle enumeration iso, mdy default value for DateStyle session setting [iso, mdy = 0, iso, dmy = 1, iso, ymd = 2]
sql.defaults.datestyle.enabled boolean false default value for datestyle_enabled session setting
sql.defaults.default_hash_sharded_index_bucket_count integer 8 used as bucket count if bucket count is not specified in hash sharded index definition
sql.defaults.default_int_size integer 8 the size, in bytes, of an INT type
sql.defaults.disallow_full_table_scans.enabled boolean false setting to true rejects queries that have planned a full table scan
sql.defaults.distsql enumeration auto default distributed SQL execution mode [off = 0, auto = 1, on = 2, always = 3]
Expand Down
1 change: 1 addition & 0 deletions docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<tr><td><code>sql.cross_db_views.enabled</code></td><td>boolean</td><td><code>false</code></td><td>if true, creating views that refer to other databases is allowed</td></tr>
<tr><td><code>sql.defaults.datestyle</code></td><td>enumeration</td><td><code>iso, mdy</code></td><td>default value for DateStyle session setting [iso, mdy = 0, iso, dmy = 1, iso, ymd = 2]</td></tr>
<tr><td><code>sql.defaults.datestyle.enabled</code></td><td>boolean</td><td><code>false</code></td><td>default value for datestyle_enabled session setting</td></tr>
<tr><td><code>sql.defaults.default_hash_sharded_index_bucket_count</code></td><td>integer</td><td><code>8</code></td><td>used as bucket count if bucket count is not specified in hash sharded index definition</td></tr>
<tr><td><code>sql.defaults.default_int_size</code></td><td>integer</td><td><code>8</code></td><td>the size, in bytes, of an INT type</td></tr>
<tr><td><code>sql.defaults.disallow_full_table_scans.enabled</code></td><td>boolean</td><td><code>false</code></td><td>setting to true rejects queries that have planned a full table scan</td></tr>
<tr><td><code>sql.defaults.distsql</code></td><td>enumeration</td><td><code>auto</code></td><td>default distributed SQL execution mode [off = 0, auto = 1, on = 2, always = 3]</td></tr>
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/alter_primary_key.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
alter_onetable_stmt ::=
'ALTER' 'TABLE' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'ALTER' 'TABLE' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')' 'USING' 'HASH'
| 'ALTER' 'TABLE' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')' 'USING' 'HASH'
| 'ALTER' 'TABLE' 'IF' 'EXISTS' table_name 'ALTER' 'PRIMARY' 'KEY' 'USING' 'COLUMNS' '(' index_params ')'
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/col_qualification.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ col_qualification ::=
| 'CONSTRAINT' constraint_name 'NOT' 'VISIBLE'
| 'CONSTRAINT' constraint_name 'UNIQUE'
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY'
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY' 'USING' 'HASH'
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'CONSTRAINT' constraint_name 'CHECK' '(' a_expr ')'
| 'CONSTRAINT' constraint_name 'DEFAULT' b_expr
Expand All @@ -20,6 +21,7 @@ col_qualification ::=
| 'NOT' 'VISIBLE'
| 'UNIQUE'
| 'PRIMARY' 'KEY'
| 'PRIMARY' 'KEY' 'USING' 'HASH'
| 'PRIMARY' 'KEY' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'CHECK' '(' a_expr ')'
| 'DEFAULT' b_expr
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/sql/bnf/create_index_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
create_index_stmt ::=
'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) opt_partition_by_index ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause
| 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) opt_partition_by_index ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause
'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) opt_index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets | 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) opt_partition_by_index ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause
| 'CREATE' ( 'UNIQUE' | ) 'INDEX' ( 'CONCURRENTLY' | ) 'IF' 'NOT' 'EXISTS' index_name 'ON' table_name ( 'USING' name | ) '(' ( ( ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) ( ( ',' ( func_expr_windowless index_elem_options | '(' a_expr ')' index_elem_options | name index_elem_options ) ) )* ) ')' ( 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets | 'USING' 'HASH' | ) ( ( 'COVERING' | 'STORING' | 'INCLUDE' ) '(' name_list ')' | ) opt_partition_by_index ( 'WITH' '(' ( ( storage_parameter ) ( ( ',' storage_parameter ) )* ) ')' ) opt_where_clause


8 changes: 8 additions & 0 deletions docs/generated/sql/bnf/index_def.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ index_def ::=
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
Expand All @@ -11,6 +15,10 @@ index_def ::=
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'COVERING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'USING' 'HASH' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'COVERING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'STORING' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
| 'UNIQUE' 'INDEX' opt_index_name '(' index_elem ( ( ',' index_elem ) )* ')' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_with_storage_parameter_list opt_where_clause
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ index_params ::=

opt_hash_sharded ::=
'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' a_expr
| 'USING' 'HASH'
|

opt_storing ::=
Expand Down Expand Up @@ -3307,6 +3308,7 @@ col_qualification_elem ::=
| 'NOT' 'VISIBLE'
| 'UNIQUE'
| 'PRIMARY' 'KEY'
| 'PRIMARY' 'KEY' 'USING' 'HASH'
| 'PRIMARY' 'KEY' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' a_expr
| 'CHECK' '(' a_expr ')'
| 'DEFAULT' b_expr
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/sql/bnf/table_constraint.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ table_constraint ::=
| 'CONSTRAINT' constraint_name 'UNIQUE' '(' index_params ')' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_where_clause
| 'CONSTRAINT' constraint_name 'UNIQUE' '(' index_params ')' opt_partition_by_index opt_where_clause
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY' '(' index_params ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY' '(' index_params ')' 'USING' 'HASH'
| 'CONSTRAINT' constraint_name 'PRIMARY' 'KEY' '(' index_params ')'
| 'CONSTRAINT' constraint_name 'FOREIGN' 'KEY' '(' name_list ')' 'REFERENCES' table_name opt_column_list key_match reference_actions
| 'CHECK' '(' a_expr ')'
Expand All @@ -13,5 +14,6 @@ table_constraint ::=
| 'UNIQUE' '(' index_params ')' 'INCLUDE' '(' name_list ')' opt_partition_by_index opt_where_clause
| 'UNIQUE' '(' index_params ')' opt_partition_by_index opt_where_clause
| 'PRIMARY' 'KEY' '(' index_params ')' 'USING' 'HASH' 'WITH' 'BUCKET_COUNT' '=' n_buckets
| 'PRIMARY' 'KEY' '(' index_params ')' 'USING' 'HASH'
| 'PRIMARY' 'KEY' '(' index_params ')'
| 'FOREIGN' 'KEY' '(' name_list ')' 'REFERENCES' table_name opt_column_list key_match reference_actions
1 change: 1 addition & 0 deletions pkg/sql/catalog/catconstants/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ go_library(
deps = [
"//pkg/clusterversion",
"//pkg/keys",
"//pkg/settings",
],
)
17 changes: 16 additions & 1 deletion pkg/sql/catalog/catconstants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

package catconstants

import "math"
import (
"math"

"github.com/cockroachdb/cockroach/pkg/settings"
)

// ReportableAppNamePrefix indicates that the application name can be
// reported in telemetry without scrubbing. (Note this only applies to
Expand Down Expand Up @@ -370,3 +374,14 @@ const (
PgExtensionSpatialRefSysTableID
MinVirtualID = PgExtensionSpatialRefSysTableID
)

// DefaultHashShardedIndexBucketCount is the cluster setting of default bucket
// count for hash sharded index when bucket count is not specified in index
// definition.
var DefaultHashShardedIndexBucketCount = settings.RegisterIntSetting(
settings.TenantWritable,
"sql.defaults.default_hash_sharded_index_bucket_count",
"used as bucket count if bucket count is not specified in hash sharded index definition",
8,
settings.NonNegativeInt,
).WithPublic()
27 changes: 17 additions & 10 deletions pkg/sql/catalog/tabledesc/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catconstants"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
Expand Down Expand Up @@ -221,18 +222,24 @@ func MakeColumnDefDescs(
func EvalShardBucketCount(
ctx context.Context, semaCtx *tree.SemaContext, evalCtx *tree.EvalContext, shardBuckets tree.Expr,
) (int32, error) {
var buckets int64
const invalidBucketCountMsg = `BUCKET_COUNT must be a 32-bit integer greater than 1, got %v`
typedExpr, err := schemaexpr.SanitizeVarFreeExpr(
ctx, shardBuckets, types.Int, "BUCKET_COUNT", semaCtx, tree.VolatilityVolatile,
)
if err != nil {
return 0, err
}
d, err := typedExpr.Eval(evalCtx)
if err != nil {
return 0, pgerror.Wrapf(err, pgcode.InvalidParameterValue, invalidBucketCountMsg, typedExpr)
// If shardBuckets is not specified, use default bucket count from cluster setting.
if _, ok := shardBuckets.(tree.DefaultVal); ok {
buckets = catconstants.DefaultHashShardedIndexBucketCount.Get(&evalCtx.Settings.SV)
} else {
typedExpr, err := schemaexpr.SanitizeVarFreeExpr(
ctx, shardBuckets, types.Int, "BUCKET_COUNT", semaCtx, tree.VolatilityVolatile,
)
if err != nil {
return 0, err
}
d, err := typedExpr.Eval(evalCtx)
if err != nil {
return 0, pgerror.Wrapf(err, pgcode.InvalidParameterValue, invalidBucketCountMsg, typedExpr)
}
buckets = int64(tree.MustBeDInt(d))
}
buckets := tree.MustBeDInt(d)
if buckets < 2 {
return 0, pgerror.Newf(pgcode.InvalidParameterValue, invalidBucketCountMsg, buckets)
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/hash_sharded_index
Original file line number Diff line number Diff line change
Expand Up @@ -939,3 +939,49 @@ t_hash_pre_split 92 t_hash_pre_split_idx_b /Table/92/2/4 /Table/92/2/5
t_hash_pre_split 92 t_hash_pre_split_idx_b /Table/92/2/5 /Table/92/2/6
t_hash_pre_split 92 t_hash_pre_split_idx_b /Table/92/2/6 /Table/92/2/7
t_hash_pre_split 92 t_hash_pre_split_idx_b /Table/92/2/7 /Max

subtest test_default_bucket_count

statement ok
CREATE TABLE t_default_bucket_8 (
a INT PRIMARY KEY USING HASH,
b INT,
c INT,
INDEX idx_t_default_bucket_8_b (b) USING HASH,
INDEX idx_t_default_bucket_8_c (c) USING HASH WITH BUCKET_COUNT = 4,
FAMILY fam_0_a (a),
FAMILY fam_1_c_b (c, b)
);

query T
SELECT @2 FROM [SHOW CREATE TABLE t_default_bucket_8]
----
CREATE TABLE public.t_default_bucket_8 (
crdb_internal_a_shard_8 INT4 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(a)), 8:::INT8)) VIRTUAL,
a INT8 NOT NULL,
b INT8 NULL,
c INT8 NULL,
crdb_internal_b_shard_8 INT4 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(b)), 8:::INT8)) VIRTUAL,
crdb_internal_c_shard_4 INT4 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(c)), 4:::INT8)) VIRTUAL,
CONSTRAINT t_default_bucket_8_pkey PRIMARY KEY (a ASC) USING HASH WITH BUCKET_COUNT = 8,
INDEX idx_t_default_bucket_8_b (b ASC) USING HASH WITH BUCKET_COUNT = 8,
INDEX idx_t_default_bucket_8_c (c ASC) USING HASH WITH BUCKET_COUNT = 4,
FAMILY fam_0_a (a),
FAMILY fam_1_c_b (c, b)
)

statement ok
SET CLUSTER SETTING sql.defaults.default_hash_sharded_index_bucket_count = 16

statement ok
CREATE TABLE t_default_bucket_16 (a INT PRIMARY KEY USING HASH);

query T
SELECT @2 FROM [SHOW CREATE TABLE t_default_bucket_16]
----
CREATE TABLE public.t_default_bucket_16 (
crdb_internal_a_shard_16 INT4 NOT VISIBLE NOT NULL AS (mod(fnv32(crdb_internal.datums_to_bytes(a)), 16:::INT8)) VIRTUAL,
a INT8 NOT NULL,
CONSTRAINT t_default_bucket_16_pkey PRIMARY KEY (a ASC) USING HASH WITH BUCKET_COUNT = 16,
FAMILY "primary" (a)
)
2 changes: 1 addition & 1 deletion pkg/sql/parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (l *lexer) Lex(lval *sqlSymType) int {

case WITH:
switch nextID {
case TIME, ORDINALITY:
case TIME, ORDINALITY, BUCKET_COUNT:
lval.id = WITH_LA
}
case NULLS:
Expand Down
18 changes: 16 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -6957,7 +6957,14 @@ col_qualification_elem:
{
$$.val = tree.PrimaryKeyConstraint{}
}
| PRIMARY KEY USING HASH WITH BUCKET_COUNT '=' a_expr
| PRIMARY KEY USING HASH
{
$$.val = tree.ShardedPrimaryKeyConstraint{
Sharded: true,
ShardBuckets: tree.DefaultVal{},
}
}
| PRIMARY KEY USING HASH WITH_LA BUCKET_COUNT '=' a_expr
{
$$.val = tree.ShardedPrimaryKeyConstraint{
Sharded: true,
Expand Down Expand Up @@ -7285,12 +7292,19 @@ opt_storing:
}

opt_hash_sharded:
USING HASH WITH BUCKET_COUNT '=' a_expr
USING HASH WITH_LA BUCKET_COUNT '=' a_expr
{
$$.val = &tree.ShardedIndexDef{
ShardBuckets: $6.expr(),
}
}
|
USING HASH
{
$$.val = &tree.ShardedIndexDef{
ShardBuckets: tree.DefaultVal{},
}
}
| /* EMPTY */
{
$$.val = (*tree.ShardedIndexDef)(nil)
Expand Down

0 comments on commit 313d085

Please sign in to comment.