Skip to content

Revert "refactor: Change all Visitors to be iterative, child-based"#36905

Merged
antiguru merged 1 commit into
mainfrom
revert-36852-mir-visitor-iterative
Jun 4, 2026
Merged

Revert "refactor: Change all Visitors to be iterative, child-based"#36905
antiguru merged 1 commit into
mainfrom
revert-36852-mir-visitor-iterative

Conversation

@antiguru

@antiguru antiguru commented Jun 4, 2026

Copy link
Copy Markdown
Member

Reverts #36852

Causes SQL-332.

@antiguru antiguru requested review from a team as code owners June 4, 2026 15:51
@antiguru antiguru requested a review from ggevay June 4, 2026 15:51
@antiguru antiguru enabled auto-merge (squash) June 4, 2026 15:52
@antiguru antiguru merged commit 261d61d into main Jun 4, 2026
119 checks passed
@antiguru antiguru deleted the revert-36852-mir-visitor-iterative branch June 4, 2026 16:16
antiguru pushed a commit that referenced this pull request Jun 5, 2026
maheshwarip pushed a commit that referenced this pull request Jun 5, 2026
antiguru added a commit that referenced this pull request Jun 8, 2026
### Motivation

The iterative, child-based `Visitor` refactor (#36852) was reverted in
#36905 because it introduced a regression: SQL-332, where `mz_now()`
used as a direct argument to a value window function (e.g.
`first_value`, `last_value`) or an aggregate window function (e.g.
`max`) was no longer recognized as temporal, so the query failed to
receive a timestamp near the current time. For example, `SELECT
first_value(mz_now()) OVER () < '3000-01-01'` returned `false` instead
of `true`.

This PR re-lands the refactor with that regression fixed, so it doesn't
ship again.

### Description

This PR consists of two commits:

1. **Reapply "refactor: Change all `Visitor`s to be iterative,
child-based" (#36852)** — reverts the revert (#36905), restoring the
iterative traversal.

2. **Fix temporal detection (SQL-332)** — the root cause of the
regression. The iterative `Visit` traversals walk expressions via the
new `VisitChildren::children()` / `children_mut()` iterators. For
`ValueWindowExpr` and `AggregateWindowExpr`, the new `children()` impls
descended *into* the argument expression and yielded *its* children,
rather than yielding the argument expression itself — which is what the
canonical `visit_children` does, and what the impl-level doc comments
promise (*"Yields `args`; does not descend into it"*).

`contains_temporal()` runs over this traversal (via `visit_post`). When
the argument is a leaf like `mz_now()` (a `CallUnmaterializable` with no
children), descending skipped it entirely, so the `mz_now()` node was
never visited and the query was planned as a constant.

The fix yields the argument expression itself via
`std::iter::once(...)`, matching `visit_children`.

### Verification

Green CI. Added regression tests in `test/sqllogictest/temporal.slt`
covering `mz_now()` as the direct argument of `first_value`,
`last_value`, and `max` window functions — each asserts the value is `<
'3000-01-01'`, confirming the query receives a current timestamp rather
than `u64::MAX`.

https://claude.ai/code/session_017Xe6H3p7ZETe4LW5bqPiWZ

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants