Details
-
Bug
-
Status: Stalled (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.3.27, 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL), 11.2(EOL)
-
None
-
Debian
Description
In this script, the ORDER BY AP.prio is not considered:
CREATE TABLE AP (
|
prid int not null,
|
prio int not null
|
);
|
|
CREATE TABLE APD (
|
prid int not null,
|
info varchar(64)
|
);
|
|
INSERT INTO AP VALUES (1,3), (2,3), (3,2), (4,2), (5,1), (6,1);
|
INSERT INTO APD (prid) VALUES (1), (2), (3), (4), (5), (6);
|
|
SELECT * FROM AP;
|
SELECT * FROM APD;
|
|
# The SELECT returns the correct values for prid (prid 3,5,6)
|
SELECT APD.prid, AP.prio FROM AP INNER JOIN APD ON AP.prid = APD.prid
|
ORDER BY AP.prio, AP.prid
|
LIMIT 3;
|
|
# The UPDATE with identical ORDER updates the columns with prid 1,2,3
|
UPDATE AP INNER JOIN APD ON AP.prid = APD.prid
|
SET info = 'UPDATED'
|
ORDER BY AP.prio, AP.prid
|
LIMIT 3;
|
|
SELECT * FROM APD;
|
The script returns this output:
+------+------+
|
| prid | prio |
|
+------+------+
|
| 1 | 3 |
|
| 2 | 3 |
|
| 3 | 2 |
|
| 4 | 2 |
|
| 5 | 1 |
|
| 6 | 1 |
|
+------+------+
|
6 rows in set (0.001 sec)
|
|
+------+------+
|
| prid | info |
|
+------+------+
|
| 1 | NULL |
|
| 2 | NULL |
|
| 3 | NULL |
|
| 4 | NULL |
|
| 5 | NULL |
|
| 6 | NULL |
|
+------+------+
|
6 rows in set (0.000 sec)
|
|
+------+------+
|
| prid | prio |
|
+------+------+
|
| 5 | 1 |
|
| 6 | 1 |
|
| 3 | 2 |
|
+------+------+
|
3 rows in set (0.000 sec)
|
|
Query OK, 3 rows affected (0.001 sec)
|
Rows matched: 3 Changed: 3 Warnings: 0
|
|
+------+---------+
|
| prid | info |
|
+------+---------+
|
| 1 | UPDATED |
|
| 2 | UPDATED |
|
| 3 | UPDATED |
|
| 4 | NULL |
|
| 5 | NULL |
|
| 6 | NULL |
|
+------+---------+
|
|
Attachments
Issue Links
- relates to
-
MDEV-13911 Support ORDER BY and LIMIT in multi-table update
-
- Closed
-
-
MDEV-31828 Multi-table update with `order by` gives wrong results
-
- Open
-
Activity
Field | Original Value | New Value |
---|---|---|
Link |
This issue relates to |
Description |
{noformat}
CREATE TABLE AP ( prid int not null, prio int not null ); CREATE TABLE APD ( prid int not null, info varchar(64) ); INSERT INTO AP VALUES (1,3), (2,3), (3,2), (4,2), (5,1), (6,1); INSERT INTO APD (prid) VALUES (1), (2), (3), (4), (5), (6); SELECT * FROM AP; SELECT * FROM APD; # The SELECT returns the correct values for prid (prid 3,5,6) SELECT APD.prid, AP.prio FROM AP INNER JOIN APD ON AP.prid = APD.prid ORDER BY AP.prio, AP.prid LIMIT 3; # The UPDATE with identical ORDER updates the columns with prid 1,2,3 UPDATE AP INNER JOIN APD ON AP.prid = APD.prid SET info = 'UPDATED' ORDER BY AP.prio, AP.prid LIMIT 3; SELECT * FROM APD; {noformat} The script returns this output: {noformat} +------+------+ | prid | prio | +------+------+ | 1 | 3 | | 2 | 3 | | 3 | 2 | | 4 | 2 | | 5 | 1 | | 6 | 1 | +------+------+ 6 rows in set (0.001 sec) +------+------+ | prid | info | +------+------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+------+ 6 rows in set (0.000 sec) +------+------+ | prid | prio | +------+------+ | 5 | 1 | | 6 | 1 | | 3 | 2 | +------+------+ 3 rows in set (0.000 sec) Query OK, 3 rows affected (0.001 sec) Rows matched: 3 Changed: 3 Warnings: 0 +------+---------+ | prid | info | +------+---------+ | 1 | UPDATED | | 2 | UPDATED | | 3 | UPDATED | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+---------+ {noformat} |
In this script, the ORDER BY AP.prio is not consider:
{noformat} CREATE TABLE AP ( prid int not null, prio int not null ); CREATE TABLE APD ( prid int not null, info varchar(64) ); INSERT INTO AP VALUES (1,3), (2,3), (3,2), (4,2), (5,1), (6,1); INSERT INTO APD (prid) VALUES (1), (2), (3), (4), (5), (6); SELECT * FROM AP; SELECT * FROM APD; # The SELECT returns the correct values for prid (prid 3,5,6) SELECT APD.prid, AP.prio FROM AP INNER JOIN APD ON AP.prid = APD.prid ORDER BY AP.prio, AP.prid LIMIT 3; # The UPDATE with identical ORDER updates the columns with prid 1,2,3 UPDATE AP INNER JOIN APD ON AP.prid = APD.prid SET info = 'UPDATED' ORDER BY AP.prio, AP.prid LIMIT 3; SELECT * FROM APD; {noformat} The script returns this output: {noformat} +------+------+ | prid | prio | +------+------+ | 1 | 3 | | 2 | 3 | | 3 | 2 | | 4 | 2 | | 5 | 1 | | 6 | 1 | +------+------+ 6 rows in set (0.001 sec) +------+------+ | prid | info | +------+------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+------+ 6 rows in set (0.000 sec) +------+------+ | prid | prio | +------+------+ | 5 | 1 | | 6 | 1 | | 3 | 2 | +------+------+ 3 rows in set (0.000 sec) Query OK, 3 rows affected (0.001 sec) Rows matched: 3 Changed: 3 Warnings: 0 +------+---------+ | prid | info | +------+---------+ | 1 | UPDATED | | 2 | UPDATED | | 3 | UPDATED | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+---------+ {noformat} |
Description |
In this script, the ORDER BY AP.prio is not consider:
{noformat} CREATE TABLE AP ( prid int not null, prio int not null ); CREATE TABLE APD ( prid int not null, info varchar(64) ); INSERT INTO AP VALUES (1,3), (2,3), (3,2), (4,2), (5,1), (6,1); INSERT INTO APD (prid) VALUES (1), (2), (3), (4), (5), (6); SELECT * FROM AP; SELECT * FROM APD; # The SELECT returns the correct values for prid (prid 3,5,6) SELECT APD.prid, AP.prio FROM AP INNER JOIN APD ON AP.prid = APD.prid ORDER BY AP.prio, AP.prid LIMIT 3; # The UPDATE with identical ORDER updates the columns with prid 1,2,3 UPDATE AP INNER JOIN APD ON AP.prid = APD.prid SET info = 'UPDATED' ORDER BY AP.prio, AP.prid LIMIT 3; SELECT * FROM APD; {noformat} The script returns this output: {noformat} +------+------+ | prid | prio | +------+------+ | 1 | 3 | | 2 | 3 | | 3 | 2 | | 4 | 2 | | 5 | 1 | | 6 | 1 | +------+------+ 6 rows in set (0.001 sec) +------+------+ | prid | info | +------+------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+------+ 6 rows in set (0.000 sec) +------+------+ | prid | prio | +------+------+ | 5 | 1 | | 6 | 1 | | 3 | 2 | +------+------+ 3 rows in set (0.000 sec) Query OK, 3 rows affected (0.001 sec) Rows matched: 3 Changed: 3 Warnings: 0 +------+---------+ | prid | info | +------+---------+ | 1 | UPDATED | | 2 | UPDATED | | 3 | UPDATED | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+---------+ {noformat} |
In this script, the ORDER BY AP.prio is not considered:
{noformat} CREATE TABLE AP ( prid int not null, prio int not null ); CREATE TABLE APD ( prid int not null, info varchar(64) ); INSERT INTO AP VALUES (1,3), (2,3), (3,2), (4,2), (5,1), (6,1); INSERT INTO APD (prid) VALUES (1), (2), (3), (4), (5), (6); SELECT * FROM AP; SELECT * FROM APD; # The SELECT returns the correct values for prid (prid 3,5,6) SELECT APD.prid, AP.prio FROM AP INNER JOIN APD ON AP.prid = APD.prid ORDER BY AP.prio, AP.prid LIMIT 3; # The UPDATE with identical ORDER updates the columns with prid 1,2,3 UPDATE AP INNER JOIN APD ON AP.prid = APD.prid SET info = 'UPDATED' ORDER BY AP.prio, AP.prid LIMIT 3; SELECT * FROM APD; {noformat} The script returns this output: {noformat} +------+------+ | prid | prio | +------+------+ | 1 | 3 | | 2 | 3 | | 3 | 2 | | 4 | 2 | | 5 | 1 | | 6 | 1 | +------+------+ 6 rows in set (0.001 sec) +------+------+ | prid | info | +------+------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+------+ 6 rows in set (0.000 sec) +------+------+ | prid | prio | +------+------+ | 5 | 1 | | 6 | 1 | | 3 | 2 | +------+------+ 3 rows in set (0.000 sec) Query OK, 3 rows affected (0.001 sec) Rows matched: 3 Changed: 3 Warnings: 0 +------+---------+ | prid | info | +------+---------+ | 1 | UPDATED | | 2 | UPDATED | | 3 | UPDATED | | 4 | NULL | | 5 | NULL | | 6 | NULL | +------+---------+ {noformat} |
Affects Version/s | 10.3 [ 22126 ] | |
Affects Version/s | 10.4 [ 22408 ] | |
Affects Version/s | 10.5 [ 23123 ] |
Fix Version/s | 10.3 [ 22126 ] | |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.5 [ 23123 ] |
Assignee | Sergei Golubchik [ serg ] |
Workflow | MariaDB v3 [ 119452 ] | MariaDB v4 [ 142619 ] |
Affects Version/s | 10.6 [ 24028 ] | |
Affects Version/s | 10.7 [ 24805 ] | |
Affects Version/s | 10.8 [ 26121 ] | |
Affects Version/s | 10.9 [ 26905 ] | |
Affects Version/s | 10.10 [ 27530 ] | |
Affects Version/s | 10.11 [ 27614 ] |
Fix Version/s | 10.6 [ 24028 ] | |
Fix Version/s | 10.8 [ 26121 ] | |
Fix Version/s | 10.9 [ 26905 ] | |
Fix Version/s | 10.10 [ 27530 ] | |
Fix Version/s | 10.11 [ 27614 ] | |
Fix Version/s | 10.3 [ 22126 ] |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Assignee | Sergei Golubchik [ serg ] | Rex Johnston [ JIRAUSER52533 ] |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Fix Version/s | 10.8 [ 26121 ] |
Affects Version/s | 11.0 [ 28320 ] | |
Affects Version/s | 11.1 [ 28549 ] | |
Affects Version/s | 11.2 [ 28603 ] |
Link | This issue relates to MDEV-31828 [ MDEV-31828 ] |
Status | In Progress [ 3 ] | Stalled [ 10000 ] |
Link |
This issue relates to |
Link |
This issue relates to |
Fix Version/s | 10.9 [ 26905 ] |
Fix Version/s | 10.10 [ 27530 ] |
Fix Version/s | 10.4 [ 22408 ] |
Thanks for the report!
as a temporary workaround:
MariaDB [test]> UPDATE AP INNER JOIN APD ON AP.prid = APD.prid
-> SET info = 'UPDATED', AP.prio=AP.prio
-> ORDER BY AP.prio, AP.prid
-> LIMIT 3;
Query OK, 3 rows affected (0.003 sec)
Rows matched: 6 Changed: 3 Warnings: 0
MariaDB [test]> SELECT * FROM APD;
+------+---------+
| prid | info |
+------+---------+
| 1 | NULL |
| 2 | NULL |
| 3 | UPDATED |
| 4 | NULL |
| 5 | UPDATED |
| 6 | UPDATED |
+------+---------+
6 rows in set (0.001 sec)