Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit a41355d

Browse files
craig[bot]RaduBerinde
andcommitted
40616: sql: fix getPlanColumns for hookFnNode r=RaduBerinde a=RaduBerinde `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 cockroachdb#40585. Release note: None Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
2 parents 3ad8bda + bdb9b87 commit a41355d

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

pkg/sql/plan_columns.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ func getPlanColumns(plan planNode, mut bool) sqlbase.ResultColumns {
4949
return n.columns
5050
case *groupNode:
5151
return n.columns
52-
case *hookFnNode:
53-
return n.header
5452
case *joinNode:
5553
return n.columns
5654
case *ordinalityNode:
@@ -120,6 +118,11 @@ func getPlanColumns(plan planNode, mut bool) sqlbase.ResultColumns {
120118
case *exportNode:
121119
return n.getColumns(mut, sqlbase.ExportColumns)
122120

121+
// The columns in the hookFnNode are returned by the hook function; we don't
122+
// know if they can be modified in place or not.
123+
case *hookFnNode:
124+
return n.getColumns(mut, n.header)
125+
123126
// Nodes that have the same schema as their source or their
124127
// valueNode helper.
125128
case *bufferNode:

pkg/sql/planhook.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func AddWrappedPlanHook(f wrappedPlanHookFn) {
110110
// provided function during Start and serves the results it returns over the
111111
// channel.
112112
type hookFnNode struct {
113+
optColumnsSlot
114+
113115
f PlanHookRowFn
114116
header sqlbase.ResultColumns
115117
subplans []planNode

0 commit comments

Comments
 (0)