Skip to content

Commit

Permalink
sql: fix CREATE AS sourcing crdb_internal.create_statements panic
Browse files Browse the repository at this point in the history
Fixes #106168

Fixes a bug discovered in #105895 that caused a panic when running these
statements because planner.semaCtx.NameResolver was nil:
CREATE TABLE t AS SELECT * FROM crdb_internal.create_statements;
CREATE MATERIALIZED VIEW v AS SELECT * FROM crdb_internal.create_statements;

Release note (bug fix): Fix panic executing CREATE AS with
crdb_internal.create_statements source. For example:
CREATE TABLE t AS SELECT * FROM crdb_internal.create_statements;
CREATE MATERIALIZED VIEW v AS SELECT * FROM crdb_internal.create_statements;
  • Loading branch information
ecwall committed Jul 5, 2023
1 parent eaa7742 commit 087f6fd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/sql/create_as_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ func TestCreateAsVTable(t *testing.T) {

// These are the vtables that need to be fixed.
// The map should be empty if all vtables are supported.
brokenTables := map[string]struct{}{
// TODO(sql-foundations): Fix nil pointer dereference.
// See https://github.com/cockroachdb/cockroach/issues/106168.
`"".crdb_internal.create_statements`: {},
}
brokenTables := map[string]struct{}{}

ctx := context.Background()
testCluster := serverutils.StartNewTestCluster(t, 1, base.TestClusterArgs{})
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func newInternalPlanner(
p.semaCtx.SearchPath = &sd.SearchPath
p.semaCtx.TypeResolver = p
p.semaCtx.FunctionResolver = p
p.semaCtx.NameResolver = p
p.semaCtx.DateStyle = sd.GetDateStyle()
p.semaCtx.IntervalStyle = sd.GetIntervalStyle()

Expand Down

0 comments on commit 087f6fd

Please sign in to comment.