piyush15102003 opened a new pull request, #27837: URL: https://github.com/apache/datafusion/pull/27837
## Which issue does this PR close? - Closes #27535. ## Rationale for this change Two scalar subqueries over the same table function with different arguments return the first one's result for both: ```sql SELECT (SELECT * FROM generate_series(1, 1)) AS first, (SELECT * FROM generate_series(2, 2)) AS second; -- got 1 1, expected 1 2 ``` Table functions are planned as a `TableScan` whose `table_name` is only the function name, and `TableScan`'s `PartialEq`/`Hash` ignore `source`. So the two subquery plans compare equal, and the physical planner's scalar-subquery dedup map plans them once. This is a **draft to pick a direction**: I listed three options on the issue (https://github.com/apache/datafusion/issues/27535#issuecomment-7137644206) and implemented the smallest one so the trade-off is concrete. ## What changes are included in this PR? `TableScan`'s `PartialEq` also requires `Arc::ptr_eq(&self.source, &other.source)`. `Hash` is unchanged, which stays consistent (equal scans still hash equal). What this costs, measured locally: - 3 optimizer unit tests fail: `eliminate_join::tests::global_min_removes_unused_outer_join`, `unions_to_filter::tests::keep_union_distinct_same_metadata_different_root_sources`, `..._different_nested_sources`. They build the expected plan with a new source for the same table, so it no longer compares equal (the printed plans are identical). - 1 proto test fails: `roundtrip_logical_plan::roundtrip_custom_listing_tables_schema_table_scan_projection`, since a decoded plan gets a new source. If this direction is acceptable I will update those tests (compare the displayed plan, or reuse the source). If not, the alternative without these effects is letting a `TableSource` report an identity (function name plus arguments) that `PartialEq`/`Hash` use, which adds a public trait method. Happy to switch. ## What is the testing strategy for this PR? Two `sqllogictest` cases in `subquery.slt` (`generate_series` and `range`). Both fail on `main` (`1 1`) and pass with the change. Notes from my Windows machine: 8 other `datafusion-proto` `roundtrip_parquet_*` tests fail on `main` without this change as well, and the `datafusion-substrait` build script does not run locally, so I rely on CI for that crate. ## Are there any user-facing changes? The wrong result is fixed. No public API change. -- 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]
