Skip to content

Commit

Permalink
sql: fix panic when resolving a target on non-existent db
Browse files Browse the repository at this point in the history
When trying to resolve a target on non-existent DB, we would have a nil
deference panic due to a missing error check.

Some ways that could have triggered this panic:
- Resolving {types,sequences}
- Renaming a table

Release note (bug fix): Fix a crash that may occur when referencing a
database that does not exist when trying to create a type, sequence or
when renaming a table.
  • Loading branch information
pbardea committed Aug 20, 2020
1 parent 4c6864b commit 635efa0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/enums
Original file line number Diff line number Diff line change
Expand Up @@ -1135,3 +1135,6 @@ public greeting2 hello
public int Z|S of int
public notbad dup|DUP
uds typ schema

statement error pq: cannot create "fakedb.typ" because the target database or schema does not exist
CREATE TYPE fakedb.typ AS ENUM ('schema')
3 changes: 3 additions & 0 deletions pkg/sql/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (p *planner) ResolveTargetObject(
p.runWithOptions(resolveFlags{skipCache: true}, func() {
prefix, namePrefix, err = resolver.ResolveTargetObject(ctx, p, un)
})
if err != nil {
return nil, namePrefix, err
}
return prefix.Database, namePrefix, err
}

Expand Down

0 comments on commit 635efa0

Please sign in to comment.