From bdb9b8797b8cf8f825ea610dd76069150153eb73 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Mon, 9 Sep 2019 18:43:38 -0400 Subject: [PATCH] sql: fix getPlanColumns for hookFnNode `getPlanColumns` allows the caller to directly mutate the columns of a `hookFnNode`; but these columns can be defined globally and should not be modified in place. Fixes #40585. Release note: None --- pkg/sql/plan_columns.go | 7 +++++-- pkg/sql/planhook.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/sql/plan_columns.go b/pkg/sql/plan_columns.go index f913585bf7a2..23f3bead4a34 100644 --- a/pkg/sql/plan_columns.go +++ b/pkg/sql/plan_columns.go @@ -49,8 +49,6 @@ func getPlanColumns(plan planNode, mut bool) sqlbase.ResultColumns { return n.columns case *groupNode: return n.columns - case *hookFnNode: - return n.header case *joinNode: return n.columns case *ordinalityNode: @@ -120,6 +118,11 @@ func getPlanColumns(plan planNode, mut bool) sqlbase.ResultColumns { case *exportNode: return n.getColumns(mut, sqlbase.ExportColumns) + // The columns in the hookFnNode are returned by the hook function; we don't + // know if they can be modified in place or not. + case *hookFnNode: + return n.getColumns(mut, n.header) + // Nodes that have the same schema as their source or their // valueNode helper. case *bufferNode: diff --git a/pkg/sql/planhook.go b/pkg/sql/planhook.go index d5443d7b85d6..0dfb5e0f1278 100644 --- a/pkg/sql/planhook.go +++ b/pkg/sql/planhook.go @@ -110,6 +110,8 @@ func AddWrappedPlanHook(f wrappedPlanHookFn) { // provided function during Start and serves the results it returns over the // channel. type hookFnNode struct { + optColumnsSlot + f PlanHookRowFn header sqlbase.ResultColumns subplans []planNode