charles-paperman commented on issue #26672:
URL: https://github.com/apache/datafusion/issues/26672#issuecomment-6954862946

   Here a bug links to uncorrelated_scalar_subquery optim: 
   
     SET datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery = 
true;
   
     SELECT
       (SELECT COUNT(*) FROM generate_series(1, 2)) AS deux,
       (SELECT COUNT(*) FROM generate_series(1, 4)) AS quatre;
   
     Expected: (2, 4). Actual:
   
     +------+--------+
     | deux | quatre |
     +------+--------+
     | 2    | 2      |
     +------+--------+
   
     Additional checks:
   
     • Each COUNT(*) executed separately returns the correct result.
     • Reversing the two scalar subqueries returns (4, 4): the first result 
appears to be reused.
     • Giving the table-function invocations distinct aliases returns the 
correct (2, 4):
   
     SELECT
       (SELECT COUNT(*) FROM generate_series(1, 2) AS serie_deux) AS deux,
       (SELECT COUNT(*) FROM generate_series(1, 4) AS serie_quatre) AS quatre;
   
     EXPLAIN for the failing query shows both output columns referencing the 
same __common_expr_1, with only one scalar subquery plan, scanning 
generate_series with start=1,
     end=2. This suggests incorrect deduplication of distinct table-function 
subqueries.
   
     Disabling physical uncorrelated scalar subqueries also restores the 
correct result for this reproducer:
   
     SET datafusion.optimizer.enable_physical_uncorrelated_scalar_subquery = 
false;
   
     The setting is enabled by default at the tested commit.


-- 
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