xiedeyantu opened a new pull request, #22692:
URL: https://github.com/apache/datafusion/pull/22692

   ## Which issue does this PR close?
   
   - Closes #22691 .
   
   ## Rationale for this change
   
   Queries with an embedded correlated `EXISTS` predicate can be decorrelated 
into a `LeftMark` join. If the subquery side is later optimized to 
`EmptyRelation`, `PropagateEmptyRelation` could replace the mark join with only 
the surviving input and drop the synthetic `mark` column. The parent filter 
still referenced that column, causing planning to fail with errors like:
   
   `Schema error: No field named __correlated_sq_1.mark`
   
   ## What changes are included in this PR?
   
   This PR updates `PropagateEmptyRelation` handling for mark joins:
   
   - `LeftMark` with an empty right side now preserves left rows and projects 
`FALSE AS mark`.
   - `RightMark` with an empty left side now preserves right rows and projects 
`FALSE AS mark`.
   - Mark joins with an empty preserved side still produce an empty relation 
with the join schema.
   
   ## Are these changes tested?
   
   Yes.
   
   Added optimizer unit coverage for `LeftMark` and `RightMark` joins with an 
empty opposite side.
   
   Added a sqllogictest regression for a correlated `EXISTS` under `OR` where 
the subquery is optimized to empty by a constant-false predicate.
   
   Verified with:
   
   ```bash
   cargo test --package datafusion-optimizer mark_join_ -- --nocapture
   cargo test --features backtrace,parquet_encryption --profile ci --package 
datafusion-sqllogictest --test sqllogictests -- subquery.slt
   cargo fmt --all
   ```
   
   ## Are there any user-facing changes?
   
   Yes. Affected SQL queries now plan and execute correctly instead of failing 
with a schema error. No API changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to