-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column alias is not propagated to subquery #42732
Comments
Seems correlated subquery is broken for the order by clause. A workaround is to put the order by in the select list and use it in the order by. explain SELECT one.a, one.b as b2, (SELECT two.b FROM t2 two WHERE two.a = one.b) order_field FROM t1 one order by order_field; |
We split the column references into three parts:
e.g. Table has three columns(a, b, c). And there's the SQL The where clause can only see the col_set1. (can see a, b, c) We need to refactor the resolving logic of TiDB to solve the issue. |
Currently, TiDB translates the AST to a logical plan by the following steps:
When we build the where clause, we can only see the column set 1. So the columns will be projected to this scope to ensure the where clause will not see columns that are not visible to it. But we will begin to build the order by clause after building the where clause. At this time, the column set 2 and 3, which is not visible before now, become visible. We must add them back and ensure the whole plan tree is valid. This is the problem we need to solve. The previous pull #33640 tried one way but met this issue (and some other issues found by creating cases). Indicating that we need a more well-designed solution to solve the AST resolving issue. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
This is related to #26945 which was resolved in #33640 but is about column aliases.
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
(Also, tested locally against 6.5.0 and the issue still persisted)
The text was updated successfully, but these errors were encountered: