Skip to content
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

limit in subquery pushed above where clause #5568

Closed
timsehn opened this issue Mar 14, 2023 · 2 comments
Closed

limit in subquery pushed above where clause #5568

timsehn opened this issue Mar 14, 2023 · 2 comments
Labels
analyzer bug Something isn't working sql Issue with SQL

Comments

@timsehn
Copy link
Contributor

timsehn commented Mar 14, 2023

mysql> explain select * from (select * from dolt_diff order by date desc limit 10) as last_10_changed where table_name='salaries';
+---------------------------------------------------------+
| plan                                                    |
+---------------------------------------------------------+
| SubqueryAlias                                           |
|  ├─ name: last_10_changed                               |
|  ├─ outerVisibility: false                              |
|  ├─ cacheable: true                                     |
|  └─ Limit(10)                                           |
|      └─ TopN(Limit: [10]; dolt_diff.date DESC)          |
|          └─ Filter                                      |
|              ├─ (dolt_diff.table_name = 'salaries')     |
|              └─ Table                                   |
|                  └─ name: dolt_diff                     |
+---------------------------------------------------------+

That limit is supposed to be below the filter. Testing to see if this applies to other tables that aren't system tables.

@timsehn
Copy link
Contributor Author

timsehn commented Mar 14, 2023

Not just a system table problem:

mysql> create table t (c1 int primary key, c2 int, c3 int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values (0,0,0), (1,1,1), (2,2,2);
Query OK, 3 rows affected (0.02 sec)

mysql> explain select * from (select * from t limit 2) as 2rows where c1=0;
+-------------------------------------+
| plan                                |
+-------------------------------------+
| SubqueryAlias                       |
|  ├─ name: 2rows                     |
|  ├─ outerVisibility: false          |
|  ├─ cacheable: true                 |
|  └─ Limit(2)                        |
|      └─ IndexedTableAccess(t)       |
|          ├─ index: [t.c1]           |
|          ├─ filters: [{[0, 0]}]     |
|          └─ columns: [c1 c2 c3]     |
+-------------------------------------+
9 rows in set (0.01 sec)

@timsehn timsehn added bug Something isn't working sql Issue with SQL analyzer labels Mar 14, 2023
@timsehn timsehn changed the title limit in subquery pushed above where clause using dolt_diff system table limit in subquery pushed above where clause Mar 23, 2023
@fulghum
Copy link
Contributor

fulghum commented May 3, 2023

Looks like @jcor11599's linked PR has fixed this issue.

@fulghum fulghum closed this as completed May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer bug Something isn't working sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

2 participants