Skip to content

Commit a98abd7

Browse files
authored
fix alter table panics (#2866)
1 parent 6e5d21a commit a98abd7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ var AlterTableScripts = []ScriptTest{
4545
},
4646
},
4747
},
48+
{
49+
Name: "issue 8917: exec error nested in block doesn't panic",
50+
SetUpScript: []string{
51+
"CREATE TABLE b(b int primary key)",
52+
"CREATE TABLE a(a int primary key, b int, CONSTRAINT `fk` FOREIGN KEY (b) REFERENCES b (b))",
53+
},
54+
Assertions: []ScriptTestAssertion{
55+
{
56+
Query: "alter table a add column c varchar(100), modify column b varchar(100)",
57+
ExpectedErr: sql.ErrForeignKeyTypeChange,
58+
},
59+
},
60+
},
4861
{
4962
Name: "variety of alter column statements in a single statement",
5063
SetUpScript: []string{

sql/rowexec/other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func (b *BaseBuilder) buildBlock(ctx *sql.Context, n *plan.Block, row sql.Row) (
160160
}
161161

162162
handleError := func(err error) error {
163+
if n.Pref == nil {
164+
// alter table blocks do not have a proc reference
165+
return err
166+
}
163167
scope := n.Pref.InnermostScope
164168
for i := len(scope.Handlers) - 1; i >= 0; i-- {
165169
if !scope.Handlers[i].Cond.Matches(err) {

0 commit comments

Comments
 (0)