Skip to content

Update optimizer to avoid reducing subqueries with WHERE#1940

Closed
plypaul wants to merge 3 commits intomainfrom
p/where_filter_query_rewriting__01
Closed

Update optimizer to avoid reducing subqueries with WHERE#1940
plypaul wants to merge 3 commits intomainfrom
p/where_filter_query_rewriting__01

Conversation

@plypaul
Copy link
Contributor

@plypaul plypaul commented Nov 20, 2025

This PR updates SqlRewritingSubQueryReducer to avoid reducing subqueries when there is a WHERE clause and there are column identifier changes. For example:

-- src2
SELECT
  src1.bookings AS bookings
  , src1.ds AS ds
FROM (
  -- src1
  SELECT
    src0.bookings AS bookings
    , src0.created_at AS ds
  FROM demo.fct_bookings src0
) src1
WHERE ds >= "2020-01-01"

->

-- Potential error
SELECT
  src0.bookings AS bookings
  , src0.created_at AS ds
FROM demo.fct_bookings src0
WHERE  ds >= "2020-01-01"

Due to the evaluation of the WHERE clause before the column expressions in some SQL engines, the example above would have produced an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant