Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
119556: sql/rowenc: introduce NullEncDatum r=mgartner a=mgartner

This commit introduces the `NullEncDatum` function which is a fast-path
version of `DatumToEncDatum` when the datum to encode is a constant
`tree.DNull`. This eliminates unnecessary overhead that constitutes an
appreciable % of total CPU time in some workloads (most notably those
with joins of tables with many columns and using the row-by-row
execution engine).

Epic: None

Release note: None


119586: roachtest: update pg_regress r=yuzefovich a=yuzefovich

This patch only contains changes to the line numbers in the internal error stack trace.

Fixes: #119573.

Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
3 people committed Feb 23, 2024
3 parents 9f25851 + cb38b9e + 3119664 commit ec70230
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
36 changes: 18 additions & 18 deletions pkg/cmd/roachtest/testdata/regression.diffs
Original file line number Diff line number Diff line change
Expand Up @@ -226102,12 +226102,12 @@ diff -U3 --label=/mnt/data1/postgres/src/test/regress/expected/rangefuncs.out --
+github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:723: Run()
+github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:579: Run()
+github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:305: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:909: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1970: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:358: func2()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:361: runPlanInsidePlan()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:911: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1972: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:361: func2()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:364: runPlanInsidePlan()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:276: func2()
+github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1220: func2()
+github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1230: func2()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:239: startInternal()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:180: Start()
+github.com/cockroachdb/cockroach/pkg/sql/rowexec/project_set.go:208: nextInputRow()
Expand All @@ -226120,10 +226120,10 @@ diff -U3 --label=/mnt/data1/postgres/src/test/regress/expected/rangefuncs.out --
+github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:723: Run()
+github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:579: Run()
+github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:305: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:909: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1970: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1685: func3()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1688: PlanAndRunAll()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:911: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1972: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1687: func3()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1690: PlanAndRunAll()
+
+HINT: You have encountered an unexpected error.
+
Expand Down Expand Up @@ -226155,12 +226155,12 @@ diff -U3 --label=/mnt/data1/postgres/src/test/regress/expected/rangefuncs.out --
+github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:723: Run()
+github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:579: Run()
+github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:305: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:909: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1970: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:358: func2()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:361: runPlanInsidePlan()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:911: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1972: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:361: func2()
+github.com/cockroachdb/cockroach/pkg/sql/apply_join.go:364: runPlanInsidePlan()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:276: func2()
+github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1220: func2()
+github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder/scalar.go:1230: func2()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:239: startInternal()
+github.com/cockroachdb/cockroach/pkg/sql/routine.go:180: Start()
+github.com/cockroachdb/cockroach/pkg/sql/rowexec/project_set.go:208: nextInputRow()
Expand All @@ -226173,10 +226173,10 @@ diff -U3 --label=/mnt/data1/postgres/src/test/regress/expected/rangefuncs.out --
+github.com/cockroachdb/cockroach/pkg/sql/execinfra/processorsbase.go:723: Run()
+github.com/cockroachdb/cockroach/pkg/sql/flowinfra/flow.go:579: Run()
+github.com/cockroachdb/cockroach/pkg/sql/colflow/vectorized_flow.go:305: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:909: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1970: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1685: func3()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1688: PlanAndRunAll()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:911: Run()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1972: PlanAndRun()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1687: func3()
+github.com/cockroachdb/cockroach/pkg/sql/distsql_running.go:1690: PlanAndRunAll()
+
+HINT: You have encountered an unexpected error.
+
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/rowenc/encoded_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func DatumToEncDatum(ctyp *types.T, d tree.Datum) EncDatum {
return EncDatum{Datum: d}
}

// NullEncDatum initializes an EncDatum with the NULL value.
func NullEncDatum() EncDatum {
return EncDatum{Datum: tree.DNull}
}

// UnsetDatum ensures subsequent IsUnset() calls return false.
func (ed *EncDatum) UnsetDatum() {
ed.encoded = nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/sql/rowexec/joinerbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/errors"
)
Expand Down Expand Up @@ -60,11 +59,11 @@ func (jb *joinerBase) init(

jb.emptyLeft = make(rowenc.EncDatumRow, len(leftTypes))
for i := range jb.emptyLeft {
jb.emptyLeft[i] = rowenc.DatumToEncDatum(leftTypes[i], tree.DNull)
jb.emptyLeft[i] = rowenc.NullEncDatum()
}
jb.emptyRight = make(rowenc.EncDatumRow, len(rightTypes))
for i := range jb.emptyRight {
jb.emptyRight[i] = rowenc.DatumToEncDatum(rightTypes[i], tree.DNull)
jb.emptyRight[i] = rowenc.NullEncDatum()
}

rowSize := len(leftTypes) + len(rightTypes)
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/rowexec/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (s *samplerProcessor) mainLoop(
outRow := make(rowenc.EncDatumRow, len(s.outTypes))
// Emit the sampled rows.
for i := range outRow {
outRow[i] = rowenc.DatumToEncDatum(s.outTypes[i], tree.DNull)
outRow[i] = rowenc.NullEncDatum()
}
// Reuse the numRows column for the capacity of the sample reservoir.
outRow[s.numRowsCol] = rowenc.EncDatum{Datum: tree.NewDInt(tree.DInt(s.sr.Cap()))}
Expand All @@ -381,7 +381,7 @@ func (s *samplerProcessor) mainLoop(
}
// Emit the inverted sample rows.
for i := range outRow {
outRow[i] = rowenc.DatumToEncDatum(s.outTypes[i], tree.DNull)
outRow[i] = rowenc.NullEncDatum()
}
for col, invSr := range s.invSr {
// Reuse the numRows column for the capacity of the sample reservoir.
Expand All @@ -402,7 +402,7 @@ func (s *samplerProcessor) mainLoop(

// Emit the sketch rows.
for i := range outRow {
outRow[i] = rowenc.DatumToEncDatum(s.outTypes[i], tree.DNull)
outRow[i] = rowenc.NullEncDatum()
}
for i, si := range s.sketches {
outRow[s.sketchIdxCol] = rowenc.EncDatum{Datum: tree.NewDInt(tree.DInt(i))}
Expand All @@ -413,7 +413,7 @@ func (s *samplerProcessor) mainLoop(

// Emit the inverted sketch rows.
for i := range outRow {
outRow[i] = rowenc.DatumToEncDatum(s.outTypes[i], tree.DNull)
outRow[i] = rowenc.NullEncDatum()
}
for col, invSketch := range s.invSketch {
outRow[s.invColIdxCol] = rowenc.EncDatum{Datum: tree.NewDInt(tree.DInt(col))}
Expand Down

0 comments on commit ec70230

Please sign in to comment.