perf(sql): optimize expression evaluation - #4075
Merged
ngjaying merged 3 commits intoJul 17, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4075 +/- ##
==========================================
+ Coverage 70.74% 70.78% +0.03%
==========================================
Files 463 463
Lines 54283 54347 +64
==========================================
+ Hits 38402 38466 +64
- Misses 12888 12889 +1
+ Partials 2993 2992 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ngjaying
marked this pull request as ready for review
July 17, 2026 03:03
Signed-off-by: Jiayin Ng <ngjaying@gmail.com>
Signed-off-by: Jiayin Ng <ngjaying@gmail.com>
Signed-off-by: Jiayin Ng <ngjaying@gmail.com>
ngjaying
force-pushed
the
agent/optimize-expression-evaluation
branch
from
July 17, 2026 06:15
843316b to
175ccd8
Compare
Yisaer
approved these changes
Jul 17, 2026
ngjaying
added a commit
that referenced
this pull request
Aug 5, 2026
## Summary - Reuse the project evaluator and its valuer chain across input rows. - Normalize numeric operands with one type switch instead of repeated type checks and cast dispatch. - Compare common `changed_cols` value types directly before falling back to `reflect.DeepEqual`. ## Why - SQL expression evaluation runs for every input row, so small setup and dispatch costs accumulate in projection, arithmetic, filtering, sorting, and change detection. - The project operator rebuilt the same evaluator scaffolding for every row even though only the current tuple, window, and aggregate data changed. - Numeric normalization inspected each operand type multiple times, while `changed_cols` used reflection even for primitive values. ## Changes In This PR - Expose reusable internal multi-valuer implementations and reset their per-row data from `ProjectOp` without changing expression indices or SliceTuple output semantics. - Replace `convertNum` helper dispatch with a single type switch that preserves the existing integer and floating-point conversions. - Add primitive fast paths for string, int64, float64, bool, and int comparisons in `changed_cols`; complex values retain `reflect.DeepEqual` behavior. - Add focused regression tests and benchmarks for all three paths. - Organize the changes as three independent commits for review. ## Notes - Benchmark medians on linux/amd64, Intel i9-14900HX, seven runs: - int64 `SimpleDataEval`: 10.82 ns/op to 8.08 ns/op (about 25% faster), 0 allocations before and after. - SliceTuple projection: 158.6 ns/op to 54.9 ns/op (about 65% faster), from 112 B / 4 allocations to 0 B / 0 allocations. - stable `changed_cols`: 337.0 ns/op to 304.8 ns/op (about 10% faster), with allocations unchanged. - Passed `go test -race ./internal/xsql ./internal/topo/operator -count=1` and focused race tests for the changed column functions. - `git diff --check` passes. - A full local binder/function run still hits the pre-existing `TestIncAggFunctionErr` failure, reproduced unchanged on `upstream/master`. `go vet` likewise reports the existing lock-copy warning in untouched `internal/xsql/row.go:187`. --------- Signed-off-by: Jiayin Ng <ngjaying@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
changed_colsvalue types directly before falling back toreflect.DeepEqual.Why
changed_colsused reflection even for primitive values.Changes In This PR
ProjectOpwithout changing expression indices or SliceTuple output semantics.convertNumhelper dispatch with a single type switch that preserves the existing integer and floating-point conversions.changed_cols; complex values retainreflect.DeepEqualbehavior.Notes
SimpleDataEval: 10.82 ns/op to 8.08 ns/op (about 25% faster), 0 allocations before and after.changed_cols: 337.0 ns/op to 304.8 ns/op (about 10% faster), with allocations unchanged.go test -race ./internal/xsql ./internal/topo/operator -count=1and focused race tests for the changed column functions.git diff --checkpasses.TestIncAggFunctionErrfailure, reproduced unchanged onupstream/master.go vetlikewise reports the existing lock-copy warning in untouchedinternal/xsql/row.go:187.