[MDEV-30469] Add support of ORDER BY and LIMIT to multidelete query and hints to normal DELETE. Created: 2023-01-25 Updated: 2024-02-04 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Parser |
| Fix Version/s: | 11.5 |
| Type: | New Feature | Priority: | Critical |
| Reporter: | Nilnandan Joshi | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Delete doesn't work with LIMIT and Hints and I don't find any specific reason behind this. Even not in documentation.
Doc says, "For the multiple-table syntax, DELETE deletes from each tbl_name the rows that satisfy the conditions. In this case, ORDER BY and LIMIT> cannot be used." But here there are no multiple tables. |
| Comments |
| Comment by Sergei Golubchik [ 2023-02-05 ] | |||||||||||
|
The documentation you quoted did not say you cannot use LIMIT with multiple tables, it said you cannot use LIMIT with multi-table DELETE syntax.
is the syntax for multi-table DELETE. The single-table DELETE syntax would've been
| |||||||||||
| Comment by Nilnandan Joshi [ 2023-02-06 ] | |||||||||||
|
What about hints? Single table delete doesn't work with hints like "use index"
If we can try to use alias then it works.
But then LIMIT doesn't work with aliases.
So what if we want to use both Hints and LIMIT with Delete? | |||||||||||
| Comment by Michael Widenius [ 2023-09-07 ] | |||||||||||
|
We could probably support with very little work: DELETE t1.* FROM test1 t1 use index(ix_id) WHERE ID = 1 limit 10; When there is only one table from which we delete. In theory it is possible to add hints to single table delete, but I think for this case it is easier to add limit to multi-table delete | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-09-07 ] | |||||||||||
|
igor Do I remember correctly that you made switching to SELECT-Like DELETE in some conditions, maybe we can do the same in case hints and LIMIT? | |||||||||||
| Comment by Michael Widenius [ 2023-09-08 ] | |||||||||||
|
There are two ways to solve this request:
I am leaning to adding hints to single table delete and single table update as this is easier to do and should solve the problem for the user | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-23 ] | |||||||||||
|
I looked on the support tickets, it is clear that user need ORDER BY (and use USE INDEX instead) to ordering for LIMIT | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-24 ] | |||||||||||
|
BTW maybe it is really syntax error becouse this is working:
| |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-24 ] | |||||||||||
|
and hints are working:
| |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-24 ] | |||||||||||
|
So it can be 2 separate asks:
niljoshi which of two or both the user need? Looking on the examples it looks like first part is needed, but I will not be surprised if both are | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-24 ] | |||||||||||
|
Actually hints are for joining tables, so I suspect they are not useful in single table operation. psergei Can be hints (like USE INDEX(XXX)) be somehow useful for singletable SELECT/UPDATE/DELETE (for example used for WHERE condition resolwing , i.e. used table access method) ? | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-24 ] | |||||||||||
|
update from psergei : the hints can be useful for single table operation | |||||||||||
| Comment by Nilnandan Joshi [ 2023-11-29 ] | |||||||||||
|
Hi sanja, customer was looking for single table delete syntax with using index and psergei also confirmed that hints can be useful for single table operation too so I think it would be great if both single delete and multi-delete scenario will be fixed. | |||||||||||
| Comment by Oleksandr Byelkin [ 2023-11-29 ] | |||||||||||
|
niljoshi why then all examples made by you in the description are multidelete syntax? Please next time make your part of work of descripting what is really needed. | |||||||||||
| Comment by Max Mether [ 2023-11-29 ] | |||||||||||
|
sanja The original issue was about LIMIT not working together with a table alias in a single table statement. The original query also had a hint (USE INDEX) in the same single table DELETE statement. So both should work with LIMIT. |