Skip to content

fix(#6179): an expression whose modifier or CASE branch reads the record is no longer "early calculated" - #6182

Merged
lvca merged 2 commits into
mainfrom
issue-6179-earlycalculated-contract
Aug 15, 2026
Merged

lvca merged 2 commits into
mainfrom
issue-6179-earlycalculated-contract

Conversation

@lvca

@lvca lvca commented Aug 14, 2026

Copy link
Copy Markdown
Member

Closes #6179.

The issue was filed as a contract/naming trap found while implementing #6172, with the note "not a live bug as far as I can tell". It is one: two nodes answer isEarlyCalculated() - "can this be computed without a record" - without looking at the part of themselves that reads one.

The bug

  • BaseExpression judged the expression on its leftmost term alone and never consulted the modifier chain, so 'Mr.'.append(surname) and ['a','b'][idx] were reported as record-free. (isBaseIdentifier(), twelve lines above, already checks modifier == null.)
  • CaseExpression keeps its branches outside childExpressions, so MathExpression's inherited walker found an empty list and returned true for a CASE that reads the record on every branch.

The planner takes that answer as licence to resolve the equality through an index and to evaluate the expression against a null record, so the record-dependent part silently resolves to null. The query then answers differently depending on whether an index exists. On the fixture in the new test the indexed type returns no rows where the identical unindexed type returns two:

SELECT fullName FROM Person       WHERE fullName = 'Mr.'.append(surname)   -- indexed:   []
SELECT fullName FROM PersonNoIndex WHERE fullName = 'Mr.'.append(surname)  -- scan:      [Mr.Smith, Mr.Jones]

The same classification also promotes a per-record LET to a global one (SelectExecutionPlanner.splitLet), with the same effect.

The fix walks what was skipped: the modifier chain (method-call arguments, array range and index selectors; a suffix reads a property of the value it is applied to, so it still needs no record; a filter or nested projection is never assumed record-free) and every CASE branch. A traversal method (.out(), .in(), ...) is excluded like FunctionCall already excludes traversal functions.

The contract, written down where it is read

isEarlyCalculated says nothing about purity, determinism or constant-ness - any function over literals qualifies, uuid() included - and there is no marker anywhere on SQLFunction that would say otherwise. That is now in its Javadoc, in FunctionCall's, and in MethodCall's.

A caller that intends to evaluate an expression while planning wants a constant instead. Expression.isLiteral() is that predicate, raised to the parser from the private walk PostgresNetworkExecutor grew in #6172 - which now calls it and drops its copy. The optional isLiteral(true) form admits a bound input parameter, for callers whose result does not outlive the execution.

Two plan-time evaluation sites move onto it:

  • partitioned-bucket pruning binds a partition coordinate only from a literal now. The bucket it derives is baked into the plan, so the value must be fixed for the plan's life and free to compute; a function was neither. The path was safe only because FunctionCall.isCacheable() is true for traversals alone - two unrelated predicates in different files happening to line up, exactly the accident the issue flagged. Pruning no longer leans on it, so widening isCacheable() later cannot silently break it. The explicit containsInputParameter() guard goes with it: isLiteral() already excludes parameters.
  • the MATCH index-cost estimate (WhereClause.getEqualityOperations) evaluates literals and bound parameters only, instead of invoking a user function once per planning pass just to sharpen an estimate.

Tests

  • Issue6179EarlyCalculatedModifierTest - indexed and unindexed types with identical rows must answer identically for a method call, a collection selector and a CASE over a record field; a modifier over a literal and a function over literals must still be resolved through the index (the contract's other half).
  • Issue6179LiteralExpressionTest - the two predicates side by side, above all where they disagree: functions and modifiers over literals are early calculated but not literal; a parameter is a literal only for the caller that says so; null is the one shape that is a literal but has never been early calculated (an index lookup on a null key is not the filter's question, and must not start to be).
  • PartitionPruningPlannerTest.computedPredicateDoesNotNarrowIndexFilterBuckets - a computed value no longer prunes, and the rows still come back.

Verified red before / green after for both the modifier and the CASE case. Full engine suite green (11931 tests); PostgresWJdbcIT green (44), including the #6172 probe tests that assert uuid() = 'nomatch' is not folded.

Spotted while testing, not touched here

SELECT FROM Doc WHERE @rid > :p returns zero rows for a parameter bound either to a RID or to its string form, while the same query with a RID literal answers correctly. Pre-existing and unrelated to this change (SelectExecutionPlanner.isRidRange evaluates the right side unguarded); will file separately.

@mergify

mergify Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

codacy-production Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 40 complexity

Metric Results
Complexity 40

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for 2abaed91
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2abaed9) Report Missing Report Missing Report Missing
Head commit (6786e6e) 190257 137404 72.22%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6182) 1 1 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@lvca lvca self-assigned this Aug 14, 2026
@lvca lvca added this to the 26.9.1 milestone Aug 14, 2026
@claude

claude Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review

I read through the full diff plus the surrounding context (the current checkout already has this PR merged in, so I could cross-reference every override against its base class in place).

Summary

This is a solid, well-scoped fix. The root cause analysis is correct and the two bugs described really do exist in the pre-PR code:

  • BaseExpression.isEarlyCalculated() only looked at number/inputParam/string/expression/identifier, never at modifier, so 'Mr.'.append(surname) was misclassified as record-free.
  • CaseExpression keeps its branches outside MathExpression.childExpressions, so the inherited walker saw an empty list and returned true unconditionally.

I traced the new Modifier.isEarlyCalculated() chain (method call args, array range/index selectors, suffix-is-safe, condition/rightBinaryCondition/nestedProjection-are-not) and it's exhaustive against Modifier's actual fields. Same for CaseExpression.isEarlyCalculated() walking caseExpression/every alternative/elseExpression, and correctly refusing to assume a simple-form (WHERE-based) WHEN is record-free.

The new isLiteral()/isLiteral(boolean) predicate is a clean split from isEarlyCalculated(), and the two plan-time evaluation call sites (SelectExecutionPlanner partition pruning, WhereClause.getEqualityOperations) are the right places to have moved onto it — both used to evaluate anything "early calculated," including live function calls, which is exactly the coupling the PR calls out. The Postgres change is a good simplification: it deletes a hand-rolled, narrower duplicate of the same predicate and reuses the new one, consistent with the project's reuse-over-duplication guidance.

Test coverage is strong: the indexed-vs-scan differential test is exactly the right shape to catch this class of bug, the literal/early-calculated matrix test pins the two predicates against each other at the cases where they actually diverge (null, functions-over-literals, modifiers-over-literals, parameters), and the partition-pruning regression test checks the plan shape (bucket ids), not just the returned rows.

Things I checked and found to be non-issues

  • Expression.isLiteral(boolean) vs Expression.isEarlyCalculated() asymmetry on SimpleNode.value. isEarlyCalculated() has branches for value instanceof Number/String/MathExpression, but isLiteral(boolean) doesn't touch value at all — it only falls through to false. That looked like a real gap at first (a literal reachable only through the legacy value field would be "early calculated" but never "literal"), but InputParameter.bindFromInputParams() — the only place that populates Expression.value with a substituted literal — has zero callers anywhere in the tree. It's dead code from the pre-ANTLR executor, so the asymmetry is unreachable, not a bug. Since the new Javadoc already calls this out ("value holds a parameter the old executor substituted by hand, which is not one either"), it might still be worth a one-line comment directly on isLiteral(boolean)'s return false; (not just the class-level Javadoc) so a future reader who greps for value doesn't have to rediscover this the way I did.
  • CaseExpression never overrides isLiteral(). A fully-literal CASE (e.g. CASE WHEN true THEN 1 ELSE 2 END) reports isLiteral() == false via the MathExpression default (childExpressions is empty for CaseExpression, so the base impl bails out). That's conservative-safe, just a missed constant-fold opportunity, not a correctness issue.
  • WhereClause.getEqualityOperations still calls b.right.execute((Result) null, context) unguarded after the isLiteral(true) check, with no try/catch. A literal like 1/0 would throw at planning time instead of execution time. This is pre-existing behavior (the old code had the same unguarded execute() call), not something this PR introduces.

Style / CLAUDE.md conformance

No new dependencies, no System.out debug leftovers, imports used instead of FQNs, final used consistently on new locals/params, Apache-2.0 headers present on the new test files — all consistent with the project's conventions.

Nothing here blocks the PR from my read. I wasn't able to execute mvn verify in this review sandbox (build/test tool invocations were blocked), so this is a static review; I'm relying on the test results described in the PR body (11931 engine tests green, 44 PostgresWJdbcIT green) for runtime confirmation.

@claude

claude Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review

I went through the diff carefully, tracing the isEarlyCalculated/isLiteral dispatch across every MathExpression/Modifier/selector subclass and cross-checking against the actual call sites (BinaryCondition.isIndexAware, SelectExecutionPlanner.splitLet, partition pruning, WhereClause.getEqualityOperations, Postgres's isConstantFalseComparison). Overall this is a well-reasoned, carefully scoped fix. Notes below are minor/confirmatory, not blockers.

Correctness

  • The root-cause fix is in the right place: BaseExpression.isEarlyCalculated now consults the modifier chain, and CaseExpression.isEarlyCalculated/isLiteral now walk branches explicitly since they sit outside childExpressions. Because BinaryCondition.isIndexAware and SelectExecutionPlanner.splitLet both call the shared isEarlyCalculated, they're fixed transitively without needing their own changes — nice, that keeps the diff smaller than touching every call site.
  • I checked Modifier.isEarlyCalculated against all 8 fields (methodCall, arrayRange, condition, arraySingleValues, rightBinaryCondition, suffix, nestedProjection, next) — every field is accounted for (suffix is correctly treated as free since it's a static property name, never a sub-expression).
  • BaseIdentifier.isLiteral only reads levelZero, ignoring suffix — at first glance that looks like it could wrongly classify a collection.property chain as literal. But levelZero and suffix are mutually exclusive in this class (confirmed via SQLASTBuilder); any real value.suffix chain goes through BaseExpression.modifier instead, which unconditionally disqualifies isLiteral when a modifier is present. So this is fine, just worth knowing the invariant it leans on isn't enforced by the type itself.
  • The new WhereClause.getEqualityOperations uses isLiteral(true) (bound params count, matching what execute() does), while the partition-pruning site in SelectExecutionPlanner uses isLiteral() (params excluded — correctly replacing the old isEarlyCalculated(...) && !containsInputParameter() combo, since a partition-pruning decision gets baked into a cached plan). Good attention to which of the two forms belongs where.
  • Expression.isLiteral(boolean) intentionally doesn't mirror the base isEarlyCalculated's handling of the legacy value instanceof Number/String path (pre-ANTLR param substitution via ValueExpression). I traced ValueExpression usage — it's only constructed in FetchFromIndexStep at execution time, never on a path that calls isLiteral(), so the documented "unreachable, not a gap" claim checks out.

Test coverage

Good split between a parser-level unit test (Issue6179LiteralExpressionTest, pinning both predicates and where they diverge — null literal, function-over-literals, input params, modifiers, CASE) and a full-database regression test (Issue6179EarlyCalculatedModifierTest) that reproduces the actual indexed-vs-scanned divergence from the issue, plus an EXPLAIN-based check that the index is no longer chosen, and a control test confirming uuid() over literals is still routed through the index. The PartitionPruningPlannerTest addition mirrors this for the partition-pruning path. This is thorough regression coverage for a subtle planner bug.

Minor observations

  • isLiteral treats any modifier as disqualifying, even a bare property suffix on an otherwise-literal base (e.g. hypothetically {'a':1}.a if that's valid syntax) — more conservative than strictly necessary, but conservative is the safe direction here and it's consistent with the documented contract, so not a concern.
  • The Javadoc additions on Expression.isEarlyCalculated/isLiteral are a nice touch — the original bug was essentially a contract that was never written down, and now it is, in the three places (Expression, FunctionCall, MethodCall) most likely to be misread by a future caller.

No security or performance concerns — all the changes are on the planning path, not the per-row hot path.

@codecov

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.02%. Comparing base (9ca99d2) to head (6786e6e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...edb/query/sql/executor/SelectExecutionPlanner.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6182      +/-   ##
==========================================
+ Coverage   69.96%   70.02%   +0.05%     
==========================================
  Files        1832     1833       +1     
  Lines      157831   157914      +83     
  Branches    33301    33312      +11     
==========================================
+ Hits       110430   110578     +148     
+ Misses      33588    33516      -72     
- Partials    13813    13820       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lvca

lvca commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

@claude please resolve conflicts with main

@claude

claude Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Claude finished @lvca's task in 7m 43s —— View job


Resolving conflicts with main

  • Fetch/inspect latest main and diagnose the conflicts
  • Determine what actually overlaps
  • Merge/rebase onto main — not something I'm able to do (see below)

I looked into this and want to flag a limitation before going further, plus what I found.

What's actually happening: this isn't a simple rebase. main has moved forward with, among other things, #6181/#6174 ("fold a constant-false filter and LIMIT 0 at plan time"), which — independently and concurrently — added its own Expression.isLiteral(), WhereClause.isAlwaysFalse(), a BooleanExpression.isAlwaysFalse() family (AndBlock/OrBlock/ParenthesisBlock/BinaryCondition), Limit.isAlwaysEmpty(), and even simplified PostgresNetworkExecutor the same way this PR's description says this PR does (drop the private isAlwaysFalse/isConstantFalseComparison walk in favor of a shared predicate). That's real, line-level overlapping work in Expression.java, MathExpression.java, SelectExecutionPlanner.java, WhereClause.java, and PostgresNetworkExecutor.java — not a mechanical conflict, a judgment call about which implementation of overlapping logic survives. Main has also picked up several unrelated commits (HA-raft leader redirect, trigger fixes, grpc changes) that should merge cleanly.

The limitation: I can create and push commits on this branch, but I don't have the ability to run git merge/git rebase or otherwise rewrite branch history — that's outside what I'm permitted to do here. Actually resolving "conflicts with main" requires exactly that (a real merge/rebase so the branch history includes main's tip), which I can't perform. Hand-editing files into a merged shape without an actual merge commit wouldn't make GitHub's conflict detection go away, so it would be busywork that doesn't solve the problem — I don't want to fake progress here.

Recommended resolution (for whoever runs the actual merge locally):

  • Keep this PR's Expression.isLiteral() / isLiteral(boolean) (the richer two-overload version with RID and input-parameter handling) and its isEarlyCalculated fixes across BaseExpression, Modifier, CaseExpression, etc. — this PR's version is the one with test coverage for the contract (Issue6179LiteralExpressionTest, Issue6179EarlyCalculatedModifierTest).
  • Keep main's new machinery from perf(#6174): fold a constant-false filter and LIMIT 0 at plan time instead of scanning the target #6181 (BooleanExpression.isAlwaysFalse family, Limit.isAlwaysEmpty, EmptySourceStep, SelectExecutionPlanner.emptyByConstructionReason/foldEmptyByConstruction/handleSkipAndLimitAfterHardwired) as-is — its call sites only use the no-arg isLiteral(), which is signature-compatible with this PR's version, so no rewrite needed there.
  • In WhereClause.getEqualityOperations, keep this PR's isLiteral(true) change (not main's still-buggy isEarlyCalculated(context)).
  • In SelectExecutionPlanner's partition-pruning block (~line 2370), keep this PR's isLiteral() + drop of containsInputParameter() (not main's old isEarlyCalculated(context) + separate parameter guard).
  • PostgresNetworkExecutor: main already did the exact simplification this PR's description describes (dropped the private walk, calls where.isAlwaysFalse(context)) — take main's version there, this PR's own Postgres diff becomes a no-op.

I'm not able to push a resolved branch myself here. Let me know if you'd like me to instead prepare the fully-merged file contents as a patch/diff you can apply locally, or take any other action within what I can actually do (edit + commit + push without history rewriting).

lvca added 2 commits August 14, 2026 17:14
…ord is no longer "early calculated"

isEarlyCalculated() answers "can this be computed without a record", and two nodes answered
it without looking at the part that reads one:

- BaseExpression judged the expression on its leftmost term alone and ignored the modifier
  chain, so 'Mr.'.append(surname) and ['a','b'][idx] were reported as record-free;
- CaseExpression keeps its branches outside childExpressions, so the inherited walker found
  an empty list and said yes to a CASE that reads the record on every branch.

The planner takes that answer as licence to use an index and to evaluate the expression
against a null record, so the record-dependent part resolved to null and the query answered
differently depending on whether an index existed: on the fixture in the new test the indexed
type returned no rows where the plain scan returned two. The same classification promotes a
per-record LET to a global one, with the same effect.

The classification now walks the modifier chain (method call arguments, array range and index
selectors; a suffix reads a property of the value it is applied to and still needs no record;
a filter or nested projection is never assumed record-free) and every CASE branch.

The contract is also the trap the issue is named for, so it is now written down where it is
read: isEarlyCalculated says nothing about purity, determinism or constant-ness - any function
over literals qualifies, uuid() included - and a caller that intends to *evaluate* an
expression while planning wants a constant instead. Expression.isLiteral() is that predicate,
raised to the parser from the private walk PostgresNetworkExecutor grew in #6172, which now
calls it. Its optional allowInputParameters form admits a bound parameter for callers whose
result does not outlive the execution.

Two plan-time evaluation sites move onto it:

- partitioned-bucket pruning binds a coordinate only from a literal now. The bucket it derives
  is baked into the plan, so the value must be fixed for the plan's life and free to compute;
  a function was neither, and the path was safe only because FunctionCall.isCacheable() is
  true for traversals alone, an accidental coupling in an unrelated file that pruning no
  longer leans on;
- the MATCH index-cost estimate evaluates literals and bound parameters only, instead of
  invoking a user function once per planning pass just to sharpen an estimate.
…here the value field went

Two points from the review:

- CaseExpression kept the MathExpression default for isLiteral() too, so a CASE over literals
  alone reported false. Conservative, but inconsistent with the predicate's own definition:
  the extended form now qualifies when its case, when, then and else expressions all do. The
  simple form's WHEN is a WhereClause and carries no constant-ness, so it still cannot.
- The comment on the isLiteral() fall-through now names what isEarlyCalculated() reads there
  and this does not: the inherited value field, where the pre-ANTLR executor substituted a
  parameter by hand and which nothing assigns any more. The asymmetry is unreachable rather
  than a gap, and a reader should not have to prove that again.

The unguarded execute() the review also flagged in WhereClause.getEqualityOperations stays as
it is: it now only ever runs on a literal or a bound parameter, and an expression that throws
there (1/0) would throw at execution too, so failing at planning is the same outcome sooner.
@lvca
lvca force-pushed the issue-6179-earlycalculated-contract branch from b5feb2d to 6786e6e Compare August 14, 2026 21:20
@lvca

lvca commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

Rebased onto main after #6181 (the #6174 constant-false fold) landed. That PR introduced its own Expression.isLiteral() for the same reason this one did, so the conflict was semantic rather than textual and the two are now one predicate:

Because the no-arg form now routes through the same walker, #6181's fold also picks up the shapes this PR taught the predicate to recognise: a RID literal, a collection of literals, a parenthesised literal, an array literal, and a CASE whose branches are all literals. Each is written in the statement and cannot change between executions, which is #6181's own stated definition - its exclusion of RIDs was conservative rather than principled, and folding #12:0 = #12:1 is correct. ConstantFalseFilterFoldingTest passes unchanged.

The postgresw change from the first push is gone: #6181 moved that walk onto the AST (WhereClause.isAlwaysFalse), which is where this PR was heading, so PostgresNetworkExecutor is no longer touched at all. Its regression tests still cover the path - PostgresWJdbcIT 44/44 green, uuid() = 'nomatch' still not folded.

Re-verified after the rebase: engine SQL suite 2546 green (including ConstantFalseFilterFoldingTest), PostgresWJdbcIT 44 green.

@claude

claude Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review

This is a careful, well-scoped fix. I read through the full diff (all 21 files) and traced the isEarlyCalculated/isLiteral call chains across the two parallel AST hierarchies (Expression and MathExpression/BaseExpression/CaseExpression) to check the new logic is actually reachable and correct, not just documented as such.

Correctness

  • The core insight is right: isEarlyCalculated() ("computable without a record") and isLiteral() ("fixed for the plan's life") are genuinely different questions, and the old code conflated them by construction (BaseExpression only looking at the leftmost term, CaseExpression branches living outside childExpressions). Separating them into two properly-walked predicates is the correct fix, not a workaround.
  • I manually traced 'Mr.'.append(surname): BaseExpression.isEarlyCalculated → Modifier.isEarlyCalculated → MethodCall.isEarlyCalculated → param.isEarlyCalculated on surname, which bottoms out in Identifier.isEarlyCalculated (false, since it isn't a declared script variable) → correctly propagates to false. Good, the fix isn't just plausible, it's actually reachable through the chain.
  • LevelZeroIdentifier.isLiteral, Modifier.isEarlyCalculated, and the various Array*Selector.isEarlyCalculated additions correctly only check the fields that can carry record-dependence (expression/expressionValue), leaving rid/inputParam/integer unguarded since those are inherently fixed — consistent with the rest of the file.
  • CaseExpression's simple form (CASE WHEN cond THEN ...) is conservatively treated as never early-calculated/literal, since the WHEN is a WhereClause with no constant-ness predicate of its own. Safe, and called out in the Javadoc.
  • The partition-pruning and WhereClause.getEqualityOperations call sites now correctly use isLiteral()/isLiteral(true) instead of isEarlyCalculated(), closing the "accidental coupling via FunctionCall.isCacheable()" issue described in the PR body. Removing the now-redundant containsInputParameter() guard in SelectExecutionPlanner is correct since isLiteral() (no-arg) already excludes input params.

Test coverage

Strong — the two new test classes (Issue6179EarlyCalculatedModifierTest, Issue6179LiteralExpressionTest) pin both the bug fix (indexed vs. non-indexed types must answer identically) and the "other half of the contract" (a function/modifier over literals must still fold through the index, so this doesn't regress the optimization the original design was going for). PartitionPruningPlannerTest.computedPredicateDoesNotNarrowIndexFilterBuckets closes the loop on the pruning path specifically. The null-vs-early-calculated asymmetry (theNullLiteralIsALiteralButNotEarlyCalculated) is a nice, easy-to-miss edge case to have pinned explicitly.

Minor/non-blocking observations

  1. WhereClause.getEqualityOperations still calls execute((Result) null, context) unguarded. The PR body already flags this as a known, accepted tradeoff ("an expression that throws there would throw at execution too"), and now that the input is restricted to isLiteral(true) it's a much smaller surface than before. Just noting I agree with the reasoning — no action needed.
  2. Style: the isEarlyCalculated/isLiteral(boolean) methods added to ArrayNumberSelector, ArrayRangeSelector, ArraySelector, ArraySingleValuesSelector, and Modifier aren't declared against a common interface (these classes extend SimpleNode directly, not Expression/MathExpression), so there's no compiler-enforced guarantee that every node in the modifier chain implements this method — a future new selector type could silently fall back to no isEarlyCalculated override and there'd be no compile error to catch it. This matches the pre-existing pattern in the file for other duck-typed methods (e.g. isAggregate), so it's consistent with the codebase rather than a new problem, just worth knowing as a standing sharp edge.
  3. The Javadoc additions on Expression.isEarlyCalculated/isLiteral are unusually thorough and genuinely useful for future readers — calling out explicitly that "early calculated" says nothing about purity/determinism (uuid() qualifies) is exactly the kind of contract note that would have prevented this bug in the first place.

Performance

No concerns — the added walks are all bounded by the expression tree size already being walked for other purposes (containsInputParameter, existing isEarlyCalculated), and the plan-time evaluation sites got stricter (fewer things get executed at plan time now, not more).

Nice fix, and the regression tests are exactly the kind that would catch this class of bug again if it recurs elsewhere in the modifier/CASE handling.

@lvca
lvca merged commit 33a4f2c into main Aug 15, 2026
31 of 32 checks passed
@lvca
lvca deleted the issue-6179-earlycalculated-contract branch August 15, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isEarlyCalculated() reads as a purity check but only means "needs no record", and BaseExpression ignores its modifier

1 participant