Skip to content

Commit

Permalink
fix alter table panics (#2866)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman authored Mar 3, 2025
1 parent 6e5d21a commit a98abd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions enginetest/queries/alter_table_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ var AlterTableScripts = []ScriptTest{
},
},
},
{
Name: "issue 8917: exec error nested in block doesn't panic",
SetUpScript: []string{
"CREATE TABLE b(b int primary key)",
"CREATE TABLE a(a int primary key, b int, CONSTRAINT `fk` FOREIGN KEY (b) REFERENCES b (b))",
},
Assertions: []ScriptTestAssertion{
{
Query: "alter table a add column c varchar(100), modify column b varchar(100)",
ExpectedErr: sql.ErrForeignKeyTypeChange,
},
},
},
{
Name: "variety of alter column statements in a single statement",
SetUpScript: []string{
Expand Down
4 changes: 4 additions & 0 deletions sql/rowexec/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (b *BaseBuilder) buildBlock(ctx *sql.Context, n *plan.Block, row sql.Row) (
}

handleError := func(err error) error {
if n.Pref == nil {
// alter table blocks do not have a proc reference
return err
}
scope := n.Pref.InnermostScope
for i := len(scope.Handlers) - 1; i >= 0; i-- {
if !scope.Handlers[i].Cond.Matches(err) {
Expand Down

0 comments on commit a98abd7

Please sign in to comment.