From c17b2639eda1b2dd11d3f0170a5dedc35b3c9abc Mon Sep 17 00:00:00 2001 From: Tommy Reilly Date: Wed, 27 Sep 2023 11:50:38 -0400 Subject: [PATCH] sql: fix an exported gist out of bounds error Fixes: #111346 Release note: None Epic: None --- pkg/sql/opt/exec/explain/result_columns.go | 4 ++- pkg/sql/opt/exec/explain/testdata/gists | 30 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pkg/sql/opt/exec/explain/result_columns.go b/pkg/sql/opt/exec/explain/result_columns.go index 9ef00112bd62..20bdb0424ccc 100644 --- a/pkg/sql/opt/exec/explain/result_columns.go +++ b/pkg/sql/opt/exec/explain/result_columns.go @@ -258,7 +258,9 @@ func groupByColumns( columns := make(colinfo.ResultColumns, 0, len(groupCols)+len(aggregations)) if inputCols != nil { for _, col := range groupCols { - columns = append(columns, inputCols[col]) + if len(inputCols) > int(col) { + columns = append(columns, inputCols[col]) + } } } for _, agg := range aggregations { diff --git a/pkg/sql/opt/exec/explain/testdata/gists b/pkg/sql/opt/exec/explain/testdata/gists index 441bda114816..c30c8552c1b5 100644 --- a/pkg/sql/opt/exec/explain/testdata/gists +++ b/pkg/sql/opt/exec/explain/testdata/gists @@ -1122,3 +1122,33 @@ explain(shape): syntax: "select 123" explain(gist): • show completions + +# Regression for #111346 +explain-plan-gist +AgFWBgCPAQIAABNWCgsGBwwHHA0UAXoCBgEFUCJ6AQ== +---- +• upsert +│ into: ?() +│ auto commit +│ +└── • lookup join (left outer) + │ table: ?@? + │ equality: (_, _, _) = (?,?,?) + │ equality cols are key + │ + └── • distinct + │ distinct on + │ + └── • render + │ + └── • render + │ + └── • group (hash) + │ group by: _, _, _ + │ + └── • index join + │ table: ?@? + │ + └── • scan + table: ?@? + spans: 1 span