[MDEV-5208] Wrong insert with ordering due to join or subquery Created: 2013-10-30 Updated: 2013-11-07 Due: 2013-11-27 Resolved: 2013-11-07 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Pelvillain Laurent | Assignee: | Oleksandr Byelkin |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
Debian squeeze (x64) |
||
| Description |
|
I need to insert data from a SELECT query with an ORDER BY and a SQL variable (like @a). The final query look like this :
Result look like :
It work but when I want to add a JOIN in this query, the ordering does not work (use natural ordering) :
I already test it with an INNER JOIN or a subquery but it return the same result. |
| Comments |
| Comment by Elena Stepanova [ 2013-11-01 ] |
|
Hi, When you are saying that it works fine on MySQL, which version do you have in mind? From all I see the last version that was this lucky is 5.0, is it really what you are using? I'm getting the "misordered" result on all of MySQL 5.1-5.7 as well as MariaDB 5.1-10.0: create table rank (position INT, petId INT, userId INT, oldPosition INT, PRIMARY KEY (userId, petId)) engine=MyISAM; MySQL thinks it's not a bug, here is the example: However, I haven't found anything in documentation that says so, thus I'll go for the expert opinion. Assigning to Sanja for this purpose. |
| Comment by Pelvillain Laurent [ 2013-11-06 ] |
|
Hello Elena, We are using Mysql 5.1.61-0+squeeze1. The main difference with your test is that we are not using MyISAM but InnoDB engine. |
| Comment by Oleksandr Byelkin [ 2013-11-07 ] |
|
SELECT list (and so variables) calculated on unsorted data, and then ORDER BY applied to the result. So if above query was working somewhere then it is just good luck, result of it very depends on execution plan, used storage engine and for some engines even in which order the tables was filled. You should use some other (more reliable) mechanistam to get what you want, the first what came to my mind is intermidiate (temporary?) table with autoincrement. Maybe there is some other solution also... |