Avoid generated code for constant string-to-timestamp casts during planning - #19514
Open
xiangfu0 wants to merge 1 commit into
Open
Avoid generated code for constant string-to-timestamp casts during planning#19514xiangfu0 wants to merge 1 commit into
xiangfu0 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #19514 +/- ##
=========================================
Coverage 67.74% 67.75%
- Complexity 1424 1430 +6
=========================================
Files 3489 3490 +1
Lines 224672 224708 +36
Branches 35468 35475 +7
=========================================
+ Hits 152210 152252 +42
+ Misses 60445 60432 -13
- Partials 12017 12024 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Timestamp range predicates such as
event_time >= CAST('2024-01-01 00:00:00' AS TIMESTAMP)compile a generated Java reducer for each constant cast during Calcite field trimming. Numeric epoch strings also pay this cost even though Calcite cannot parse them and leaves the casts for later Pinot planning.Add a narrow executor for ordinary CHAR/VARCHAR literal-to-TIMESTAMP casts. It calls the same Avatica parser and RexBuilder literal construction as Calcite's generated code. Unsupported expression batches still delegate to Calcite; a failed supported batch remains entirely unchanged. This preserves nulls, precision, invalid-input behavior and batch ordering.
Install the executor only during SQL-to-rel conversion, restoring the prior executor before optimization and preserving explicitly supplied executors. Installing it only in a RelBuilder context is insufficient because
RelBuilder.transformdiscards that context.Benchmark
Independently packaged baseline
c6116095f7d3834613649c770d75fed7dd5a874aand this change, with identical benchmark source and bytecode. The benchmark callsQueryEnvironment.compileand closes each compiled query, covering SQL parsing, validation, SQL-to-rel conversion and logical optimization. It cycles through 1,024 prebuilt synthetic account IDs. The measured window query filters a timestamp range and selects the latest event version usingROW_NUMBER().Warmed results on a shared Apple M4 Pro host with 24 GiB RAM, OpenJDK 25.0.4, JMH 1.37, one benchmark thread, 1 GiB heap and
ActiveProcessorCount=4:Each revision has two independent JVM forks, run baseline/PR/PR/baseline. Each fork uses five 3-second warmups and five 2-second measurements with the GC profiler. Means include every measured iteration. The control's direction reverses between pairs; one baseline control iteration is elevated and retained. These shared-host measurements establish a compilation benefit for these queries, not end-to-end query throughput or precise bounds on small regressions. Shorter pilot runs were excluded because they were still warming up.
Independent fork means and reproduction
Copy
BenchmarkConstantCastPlanning.javato a worktree at the baseline commit. Build each worktree separately with JDK 25:Run the following once in each worktree in baseline/PR/PR/baseline order, without concurrent builds. Use distinct result filenames for each run. Verify the packaged planner and benchmark jars match their module target jars before running.
The harness also includes a simple FILTER query and a LONG epoch-millis column control for additional experiments.
Separate matched JFR runs corroborate the mechanism: Janino occurs in 142/471 baseline JMH-worker execution samples and 0/750 PR samples. Sampling alone does not establish absence; the integration tests independently count generated reductions exactly.
Validation
ZstandardDecompressor.java:51: Zstd's provided JetBrains annotation dependency is absent from that module's compile classpath. This is reproduced on the identical baseline source; adding the annotation jar resolves that check. No unrelated dependency change is included here.