Skip to content

Commit 0140d8b

Browse files
committed
opt: refactor placeholder scan execbuilding
This is a purely mechanical change that moves a block of code in `buildPlaceholderScan`. An early exit now occurs earlier, avoiding unnecessary computation. Release note: None
1 parent cc575e1 commit 0140d8b

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

pkg/sql/opt/exec/execbuilder/relational.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -972,22 +972,7 @@ func (b *Builder) buildPlaceholderScan(
972972
return execPlan{}, colOrdMap{}, errors.AssertionFailedf("PlaceholderScan cannot have constraints")
973973
}
974974

975-
md := b.mem.Metadata()
976-
tab := md.Table(scan.Table)
977-
idx := tab.Index(scan.Index)
978-
979-
// Build the index constraint.
980-
spanColumns := make([]opt.OrderingColumn, len(scan.Span))
981-
for i := range spanColumns {
982-
col := idx.Column(i)
983-
ordinal := col.Ordinal()
984-
colID := scan.Table.ColumnID(ordinal)
985-
spanColumns[i] = opt.MakeOrderingColumn(colID, col.Descending)
986-
}
987-
var columns constraint.Columns
988-
columns.Init(spanColumns)
989-
keyCtx := constraint.MakeKeyContext(b.ctx, &columns, b.evalCtx)
990-
975+
// Evaluate the scalar expressions.
991976
values := make([]tree.Datum, len(scan.Span))
992977
for i, expr := range scan.Span {
993978
// The expression is either a placeholder or a constant.
@@ -1014,6 +999,22 @@ func (b *Builder) buildPlaceholderScan(
1014999
values[i] = val
10151000
}
10161001

1002+
md := b.mem.Metadata()
1003+
tab := md.Table(scan.Table)
1004+
idx := tab.Index(scan.Index)
1005+
1006+
// Build the index constraint.
1007+
spanColumns := make([]opt.OrderingColumn, len(scan.Span))
1008+
for i := range spanColumns {
1009+
col := idx.Column(i)
1010+
ordinal := col.Ordinal()
1011+
colID := scan.Table.ColumnID(ordinal)
1012+
spanColumns[i] = opt.MakeOrderingColumn(colID, col.Descending)
1013+
}
1014+
var columns constraint.Columns
1015+
columns.Init(spanColumns)
1016+
keyCtx := constraint.MakeKeyContext(b.ctx, &columns, b.evalCtx)
1017+
10171018
key := constraint.MakeCompositeKey(values...)
10181019
var span constraint.Span
10191020
span.Init(key, constraint.IncludeBoundary, key, constraint.IncludeBoundary)

0 commit comments

Comments
 (0)