| Bug #113551 | Discrepancy in MySQL 8.2.0 Documentation Regarding Subquery Scoping Rules | ||
|---|---|---|---|
| Submitted: | 4 Jan 2024 10:04 | Modified: | 10 Jan 2024 7:34 |
| Reporter: | Kang Rong | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
| Version: | 8.2.0 | OS: | Linux (mysql docker image 8.2.0) |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | alias, document, scope rule, subquery | ||
[4 Jan 2024 10:04]
Kang Rong
[9 Jan 2024 13:56]
MySQL Verification Team
Hello! Thank you for the bug report. Imho this is not a bug, as per the documentation https://dev.mysql.com/doc/refman/8.2/en/correlated-subqueries.html Notice that the subquery contains a reference to a column of t1, even though the subquery's FROM clause does not mention a table t1. So, MySQL looks outside the subquery, and finds t1 in the outer query. Regards, Ashwini Patil
[9 Jan 2024 14:25]
Kang Rong
Dear Ashwini Patil and the MySQL Verification Team, Thank you for your response. While I understand MySQL's approach to column scoping in subqueries, it appears to deviate from the current documentation, potentially leading to misunderstandings. As a reader, I interpret the documentation to imply that an alias in a subquery shadows the same alias in outer queries, yet there is no mention of MySQL searching outer scopes for a column missing in inner scopes. To enhance clarity, might we consider updating the documentation? A revised note could read: ``` Note: In subqueries, if a referenced column is not found within the immediate table alias, MySQL will continue to search for the column in the enclosing queries. This behavior ensures that MySQL does not immediately throw an error if an inner query's alias lacks the column, but instead looks for the column at outer query levels. ``` I believe such an update would greatly benefit users by clearly setting expectations for MySQL's behavior. Warm regards, Rong
[10 Jan 2024 7:34]
MySQL Verification Team
Hello Rong, Thank you for the feedback. Regards, Ashwini Patil
