Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
Description
Reproducible on maria-5.2, maria-5.3.
If a query containing a double ORDER BY is used in a VIEW, selecting from that view returns only some of the rows of the original query.
test case:
CREATE TABLE t1 ( f1 int NOT NULL , f10 int, f11 varchar(32), PRIMARY KEY (f1)) ;
INSERT IGNORE INTO t1 VALUES (6,0,'j'),(7,0,'z'),(8,0,'c'),(9,0,'a'),(10,0,'q');
CREATE TABLE t2 ( f11 int) ;
INSERT IGNORE INTO t2 VALUES (0),(0);
CREATE OR REPLACE VIEW v1 AS
SELECT alias2.f11 AS field1
FROM t2 STRAIGHT_JOIN
( t1 AS alias2
RIGHT JOIN t1 AS alias3 ON alias3.f10 = alias2.f10 )
ON alias3.f1 = alias2.f1
GROUP BY field1
ORDER BY alias3.f1 , alias2.f1 ;
SELECT * FROM v1;
should return 5 rows, returns only 1
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Re: Wrong result with double ORDER BY
Reproducible without views. Also reproducible with mysql-5.1 . So it is a legacy bug.
CREATE TABLE t1 ( b int) ;
INSERT INTO t1 VALUES (8),(9);
CREATE TABLE t2 ( a int, b int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (6,7),(7,7),(8,1),(9,7),(10,1),(11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5);
SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
explain: