thswlsqls opened a new issue, #40067:
URL: https://github.com/apache/shardingsphere/issues/40067

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   master @ 7712a28fffe
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   Both (MySQL dialect)
   
   ### Expected behavior
   An `ANY`/`ALL`/`SOME` subquery can reference a table alias declared two or 
more query levels out, as `EXISTS` and scalar subqueries already can.
   
   ### Actual behavior
   Binding fails with `ColumnNotFoundException: Unknown column 'o.user_id' in 
'where clause'`.
   
   ### Reason analyze (If you can)
   `ExpressionSegmentBinder.bind()` passes only `tableBinderContexts` to 
`QuantifySubqueryExpressionBinder`, which forwards it to 
`SubquerySegmentBinder` as the outer contexts. The `ExistsSubqueryExpression` 
and `SubqueryExpressionSegment` branches merge `outerTableBinderContexts` with 
`tableBinderContexts` first, so the quantified branch drops every scope above 
the current one. #36135 fixed the same loss in `NotExpressionBinder`.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   Bind this MySQL statement (the quantified subquery must be nested at depth 2 
or more; a non-nested correlated `ALL` works):
   ```sql
   SELECT o.order_id FROM t_order o WHERE EXISTS (SELECT 1 FROM t_order_item i 
WHERE i.order_id = o.order_id
     AND i.price > ALL (SELECT p.price FROM t_product p WHERE p.user_id = 
o.user_id))
   ```
   
   ### Example codes for reproduce this issue (such as a github link).
   N/A
   
   


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

Reply via email to