Skip to content

Commit

Permalink
sql: add a notice to primary key changes about async jobs
Browse files Browse the repository at this point in the history
Fixes #45730.

Release note: None
  • Loading branch information
rohany committed Mar 5, 2020
1 parent 63a60d3 commit de9786a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/cli/interactive_tests/test_notice.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ send "CREATE TABLE drop_index_test(a int); CREATE INDEX drop_index_test_index ON
eexpect "NOTICE: index \"drop_index_test_index\" will be dropped asynchronously and will be complete after the GC TTL"
end_test

start_test "Check that altering the primary key of a table prints a message about async jobs."
send "CREATE TABLE alterpk (x INT NOT NULL); ALTER TABLE alterpk ALTER PRIMARY KEY USING COLUMNS (x);\r"
eexpect "NOTICE: primary key changes spawn async cleanup jobs. Future schema changes on \"alterpk\" may be delayed as these jobs finish"
end_test

send "\\q\r"
eexpect eof
8 changes: 8 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,14 @@ func (n *alterTableNode) startExec(params runParams) error {
// Mark descriptorChanged so that a mutation job is scheduled at the end of startExec.
descriptorChanged = true

// Send a notice to users about the async cleanup jobs.
params.p.noticeSender.AppendNotice(
pgerror.Noticef(
"primary key changes spawn async cleanup jobs. Future schema changes on %q may be delayed as these jobs finish",
n.tableDesc.Name,
),
)

case *tree.AlterTableDropColumn:
if params.SessionData().SafeUpdates {
return pgerror.DangerousStatementf("ALTER TABLE DROP COLUMN will remove all data in that column")
Expand Down

0 comments on commit de9786a

Please sign in to comment.