Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Not a Bug
-
10.6
Description
Testcase:
use d1;
|
|
drop table if exists t1 ; |
|
create table t1 (id1 int, id2 int, id3 float); |
|
INSERT INTO `t1` (
|
with recursive series as (
|
select 1 as id union all |
select id +1 as id from series |
where id < 10) |
select FLOOR(RAND()*(3-1+1))+1,FLOOR(RAND()*(2-1+1))+1 ,(FLOOR(RAND()*(100-1+1))+1)/10 from series); |
|
SELECT b.*,
|
(@currank := @currank + 1) AS peringkat |
FROM ( select id1,id2,id3 from t1 a, (SELECT @curRank := 0) r ) b |
ORDER BY id1 desc,id2 desc,id3 desc;
|
with 10.3, 10.4 and 10.5 the order if the variable (peringkat) follow the final "order by" clause
+------+------+------+-----------+
|
| id1 | id2 | id3 | peringkat |
|
+------+------+------+-----------+
|
| 3 | 1 | 5.9 | 1 | |
| 3 | 1 | 2.9 | 2 | |
| 2 | 2 | 8.6 | 3 | |
| 2 | 2 | 6.8 | 4 | |
| 2 | 1 | 7.6 | 5 | |
| 1 | 2 | 7.2 | 6 | |
| 1 | 2 | 3.5 | 7 | |
| 1 | 2 | 0.2 | 8 | |
| 1 | 1 | 7.7 | 9 | |
| 1 | 1 | 2.2 | 10 | |
+------+------+------+-----------+
|
10 rows in set (0.001 sec) |
So not in 10.6
+------+------+------+-----------+
|
| id1 | id2 | id3 | peringkat |
|
+------+------+------+-----------+
|
| 3 | 2 | 5.6 | 1 | |
| 3 | 2 | 5.6 | 4 | |
| 3 | 2 | 4.2 | 6 | |
| 3 | 2 | 3.5 | 5 | |
| 3 | 1 | 9.3 | 8 | |
| 2 | 2 | 7.5 | 9 | |
| 2 | 1 | 2.3 | 7 | |
| 1 | 1 | 8.7 | 2 | |
| 1 | 1 | 7.4 | 10 | |
| 1 | 1 | 2.7 | 3 | |
+------+------+------+-----------+
|
10 rows in set (0.001 sec) |
workarround with row_number() works
SELECT b.*,row_number() over (order by id1 desc,id2 desc,id3 desc) as peringkat FROM ( select id1,id2,id3 from t1 a ) b;
|
Attachments
Issue Links
- is duplicated by
-
MDEV-29408 Calculation error in recent version of MariaDB test with 10.8-10.9-10.10
-
- Closed
-
- relates to
-
MDEV-24089 support oracle syntax: rownum
-
- Closed
-
changed after be093c81a7955aa8309e650 commit (
MDEV-24089https://github.com/MariaDB/server/commit/be093c81a7)on 10.6 -Using temporary :
10.6
MariaDB [test]> explain extended SELECT b.*, (@var:=@var+1) FROM (SELECT a.* , (@var := 0) r from t1 a) b order by id1;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 10 | 100.00 | Using temporary; Using filesort |
| 2 | DERIVED | a | ALL | NULL | NULL | NULL | NULL | 10 | 100.00 | |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
2 rows in set, 1 warning (0.001 sec)
10.5
MariaDB [test]> explain extended SELECT b.*, (@var:=@var+1) FROM (SELECT a.* , (@var := 0) r from t1 a) b order by id1;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 10 | 100.00 | Using filesort |
| 2 | DERIVED | a | ALL | NULL | NULL | NULL | NULL | 10 | 100.00 | |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------+
2 rows in set, 1 warning (0.002 sec)