Skip to content

Commit f928c8b

Browse files
craig[bot]rafiss
andcommitted
Merge #149252
149252: sql: improve error message for schema_locked r=rafiss a=rafiss This also unskips a logictest that was accidentally skipped. Epic: CRDB-41681 Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents 8b5e34a + 5a5f6ee commit f928c8b

File tree

9 files changed

+67
-15
lines changed

9 files changed

+67
-15
lines changed

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/testdata/logic_test/create_statements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LogicTest: !weak-iso-level-configs schema-locked-disabled
1+
# LogicTest: !weak-iso-level-configs
22
# This test is skipped under READ COMMITTED and REPEATABLE READ, since it
33
# asserts on the NOTICE output, and weak isolation level schema changes always
44
# send out extra notices.

pkg/sql/logictest/testdata/logic_test/schema_locked

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,43 +87,43 @@ statement ok
8787
INSERT INTO t SELECT i, i+1 FROM generate_series(1,10) AS tmp(i);
8888

8989
onlyif config local-mixed-25.1 local-legacy-schema-changer
90-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
90+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
9191
ALTER TABLE t ADD COLUMN k INT DEFAULT 30;
9292

9393
onlyif config local-mixed-25.1 local-legacy-schema-changer
94-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
94+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
9595
ALTER TABLE t DROP COLUMN j;
9696

9797
onlyif config local-mixed-25.1
98-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
98+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
9999
ALTER TABLE t RENAME TO t2;
100100

101101
onlyif config local-mixed-25.1
102-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
102+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
103103
ALTER TABLE t RENAME COLUMN j TO j2;
104104

105105
onlyif config local-mixed-25.1
106-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
106+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
107107
ALTER INDEX idx RENAME TO idx2;
108108

109109
onlyif config local-mixed-25.1
110-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
110+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
111111
ALTER INDEX idx INVISIBLE;
112112

113113
onlyif config local-mixed-25.1 local-legacy-schema-changer
114-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
114+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
115115
DROP INDEX idx;
116116

117117
onlyif config local-mixed-25.1 local-legacy-schema-changer
118-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
118+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
119119
CREATE INDEX idx2 ON t(j);
120120

121121
statement ok
122122
CREATE TABLE ref (a INT PRIMARY KEY, b INT)
123123

124124
# Locked tables cannot be referenced by foreign keys.
125125
onlyif config local-mixed-25.1 local-legacy-schema-changer
126-
statement error pgcode 57000 schema changes are disallowed on table "t" because it is locked
126+
statement error pgcode 57000 this schema change is disallowed because table "t" is locked and this operation cannot automatically unlock the table
127127
ALTER TABLE ref ADD CONSTRAINT fk FOREIGN KEY (b) REFERENCES t(j);
128128

129129
# GRANT statements are allowed on the table, as they only affect the

pkg/sql/logictest/tests/fakedist-disk/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/fakedist/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/local-vec-off/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/local/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/sqlerrors/errors.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ const EnforceHomeRegionFurtherInfo = "For more information, see https://www.cock
4444
// NewSchemaChangeOnLockedTableErr creates an error signaling schema
4545
// change statement is attempted on a table with locked schema.
4646
func NewSchemaChangeOnLockedTableErr(tableName string) error {
47-
return errors.WithHintf(pgerror.Newf(pgcode.OperatorIntervention,
48-
`schema changes are disallowed on table %q because it is locked`, tableName),
49-
"To unlock the table, try \"ALTER TABLE %v SET (schema_locked = false);\" "+
50-
"\nAfter schema change completes, we recommend setting it back to true with "+
51-
"\"ALTER TABLE %v SET (schema_locked = true);\"", tableName, tableName)
47+
return errors.WithHintf(
48+
errors.WithDetailf(
49+
pgerror.Newf(
50+
pgcode.OperatorIntervention,
51+
`this schema change is disallowed because table %q is locked and this operation cannot automatically unlock the table`,
52+
tableName,
53+
),
54+
"To unlock the table, execute `ALTER TABLE %v SET (schema_locked = false);`"+
55+
"\nAfter the schema change completes, we recommend setting it back to true with "+
56+
"`ALTER TABLE %v SET (schema_locked = true);`.",
57+
tableName, tableName,
58+
),
59+
"Locking the table improves changefeed performance; see %s",
60+
docs.URL("changefeed-best-practices.html#lock-the-schema-on-changefeed-watched-tables"),
61+
)
5262
}
5363

5464
// NewDisallowedSchemaChangeOnLDRTableErr creates an error that indicates that

0 commit comments

Comments
 (0)