Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: Allow unique-without-index not valid constraint in table creation #115354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/create_table
Original file line number Diff line number Diff line change
Expand Up @@ -1039,3 +1039,30 @@ public generated_by_default_t_notnull_b_seq INT8
public generated_always_t_notnull_b_seq INT8
public generated_by_default_t_b_seq INT8
public generated_always_t_b_seq INT8

subtest end

# This subtest ensures we can create not valid unique-without-index constraint
# during table creation, which will be treated as a "normal"
# unique-without-index constraint (meaning the NOT VALID will be dropped).
subtest 115352

statement ok
SET experimental_enable_unique_without_index_constraints = true

statement ok
CREATE TABLE t_115352 (i INT, UNIQUE WITHOUT INDEX (i) NOT VALID);

# NOT VALID constraint specified within `CREATE TABLE` is a no-op and does not
# skip validation.
query T
SELECT create_statement FROM [SHOW CREATE t_115352];
----
CREATE TABLE public.t_115352 (
i INT8 NULL,
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
CONSTRAINT t_115352_pkey PRIMARY KEY (rowid ASC),
CONSTRAINT unique_i UNIQUE WITHOUT INDEX (i)
)

subtest end
2 changes: 1 addition & 1 deletion pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -9821,7 +9821,7 @@ table_elem:
{
def := $1.constraintDef()
valBehavior := $2.validationBehavior()
if u, ok := def.(*tree.UniqueConstraintTableDef); ok && valBehavior == tree.ValidationSkip {
if u, ok := def.(*tree.UniqueConstraintTableDef); ok && valBehavior == tree.ValidationSkip && !u.WithoutIndex {
typ := "PRIMARY KEY"
if !u.PrimaryKey {
typ = "UNIQUE"
Expand Down