diff --git a/pkg/sql/opt/exec/explain/plan_gist_test.go b/pkg/sql/opt/exec/explain/plan_gist_test.go index 9b841fc325aa..a77828ec096c 100644 --- a/pkg/sql/opt/exec/explain/plan_gist_test.go +++ b/pkg/sql/opt/exec/explain/plan_gist_test.go @@ -118,6 +118,8 @@ func TestPlanGistBuilder(t *testing.T) { } // RFC: should I move this to opt_tester? datadriven.RunTest(t, datapathutils.TestDataPath(t, "gists"), testGists) + // Reset the catalog for the next test. + catalog = testcat.New() datadriven.RunTest(t, datapathutils.TestDataPath(t, "gists_tpce"), testGists) } diff --git a/pkg/sql/opt/exec/explain/result_columns.go b/pkg/sql/opt/exec/explain/result_columns.go index 495ed57dcb3d..a1d19c5bd0f6 100644 --- a/pkg/sql/opt/exec/explain/result_columns.go +++ b/pkg/sql/opt/exec/explain/result_columns.go @@ -11,6 +11,8 @@ package explain import ( + "fmt" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/opt/cat" @@ -255,6 +257,12 @@ func tableColumns(table cat.Table, ordinals exec.TableColumnOrdinalSet) colinfo. Name: string(col.ColName()), Typ: col.DatumType(), }) + } else { + // Give downstream operators something to chew on so that they don't panic. + cols = append(cols, colinfo.ResultColumn{ + Name: fmt.Sprintf("unknownCol-%d", i), + Typ: types.Unknown, + }) } } return cols diff --git a/pkg/sql/opt/exec/explain/testdata/gists b/pkg/sql/opt/exec/explain/testdata/gists index 441bda114816..a9ee4557554d 100644 --- a/pkg/sql/opt/exec/explain/testdata/gists +++ b/pkg/sql/opt/exec/explain/testdata/gists @@ -1122,3 +1122,47 @@ explain(shape): syntax: "select 123" explain(gist): • show completions + +exec-ddl +CREATE TABLE ts (a int, b STRING) +---- + +gist-explain-roundtrip +SELECT max(a), b FROM ts WHERE a = 1 AND b LIKE '$ internal%' GROUP BY b +---- +hash: 6959966538333657501 +plan-gist: AgF0AgADAAAAAwsCBgQ= +explain(shape): +• group (hash) +│ group by: b +│ +└── • filter + │ filter: (a = _) AND (b LIKE _) + │ + └── • scan + table: ts@ts_pkey + spans: FULL SCAN +explain(gist): +• group (hash) +│ group by: a +│ +└── • filter + │ + └── • scan + table: ts@ts_pkey + spans: FULL SCAN + +# The above query produces this gist when run via EXPLAIN (GIST) in a real DB and when +# run in a DB w/o that table panics, this tests that the panic is fixed. Essentially we're +# exercising the "unknown" table code. +explain-plan-gist +AgHQAQIAAwAAAAMLAgYE +---- +• group (hash) +│ group by: unknownCol-0 +│ +└── • filter + │ + └── • scan + table: ?@? + spans: FULL SCAN diff --git a/pkg/sql/opt/exec/explain/testdata/gists_tpce b/pkg/sql/opt/exec/explain/testdata/gists_tpce index 056d8e969109..ba0fe225ef9f 100644 --- a/pkg/sql/opt/exec/explain/testdata/gists_tpce +++ b/pkg/sql/opt/exec/explain/testdata/gists_tpce @@ -22,7 +22,7 @@ GROUP BY b_name ORDER BY 2 DESC ---- hash: 14732118561700026222 -plan-gist: AgGUAQQAPAAAAAGqAQQAAwIAABQAogEEAgAUAJgBBAIAFACsAQQCAAkAAgIAARQAhgECAgEHBAsCBwQRBgQ= +plan-gist: AgGKAQQAPAAAAAGgAQQAAwIAABQAmAEEAgAUAI4BBAIAFACiAQQCAAkAAgIAARQAfAICAQcECwIHBBEGBA== explain(shape): • sort │ order: -sum @@ -116,7 +116,7 @@ LEFT JOIN last_trade ON lt_s_symb = hs_s_symb LIMIT 10; ---- hash: 10378570089558454947 -plan-gist: AgF4BAAFAgAAE3gCFAGAAQICABQBpAECAgEHBgsCBwYYBgY= +plan-gist: AgFuBAAFAgAAE24CFAF2AgIAFAGaAQICAQcGCwIHBhgGBg== explain(shape): • top-k │ order: +"coalesce" @@ -211,7 +211,7 @@ update_trade_submitted AS ( SELECT * FROM request_list; ---- hash: 7096273538769246907 -plan-gist: AgGkAQIAHwIAAAcQBRAhpAEAAAcCMAGUAQIAHwAAAAMHCDAxBQIUAJQBAgIBBQgHCAUII5QBAAcCMDEFAgcGBQYwH5IBADEFAhQFkAECAgEqMQUCFAWwAQICASoHAjAxBQIUAJABAgIBBRwHIAUgMCGQAQAAMQUCFAWwAQICASoHAjAxBQgGCA== +plan-gist: AgGaAQIAHwIAAAcQBRAhmgEAAAcCMAGKAQIAHwAAAAMHCDAxBQIUAIoBAgIBBQgHCAUII4oBAAcCMDEFAgcGBQYwH4gBADEFAhQFhgECAgEqMQUCFAWmAQICASoHAjAxBQIUAIYBAgIBBRwHIAUgMCGGAQAAMQUCFAWmAQICASoHAjAxBQgGCA== explain(shape): • root │