Bug #68330 Search with clause IN return duplicates records when 'order by' is added
| Submitted: | 10 Feb 2013 10:24 | Modified: | 4 Mar 2013 15:10 |
|---|---|---|---|
| Reporter: | Luis A S Junior Camargo | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S1 (Critical) |
| Version: | 5.6.10 | OS: | Windows |
| Assigned to: | CPU Architecture: | Any |
[10 Feb 2013 10:24]
Luis A S Junior Camargo
[10 Feb 2013 10:25]
Luis A S Junior Camargo
table products
Attachment: products.sql (application/octet-stream, text), 1.81 KiB.
[10 Feb 2013 10:25]
Luis A S Junior Camargo
table colors
Attachment: colors.sql (application/octet-stream, text), 2.42 KiB.
[10 Feb 2013 23:59]
MySQL Verification Team
Thank you for the bug report. Verified with mysql-trunk source: mysql 5.7 >select id,name from colors where id in(select distinctrow(color) from products where categ=296) order by id; +----+----------------+ | id | name | +----+----------------+ | 1 | Branco | | 1 | Branco | | 1 | Branco | | 1 | Branco | | 2 | Preto | | 2 | Preto | | 2 | Preto | | 2 | Preto | | 3 | Vermelho | | 4 | Azul | | 4 | Azul | | 4 | Azul | | 4 | Azul | | 5 | Amarelo | | 5 | Amarelo | | 5 | Amarelo | | 6 | Verde | | 10 | Pink | | 10 | Pink | | 10 | Pink | | 10 | Pink | | 11 | Azul escuro | | 12 | Laranja | | 12 | Laranja | | 12 | Laranja | | 20 | Verde Menta | | 20 | Verde Menta | | 20 | Verde Menta | | 21 | Vermelho Bord¶ | +----+----------------+ 29 rows in set (0.00 sec) mysql 5.7 >alter table products drop key categ; Query OK, 29 rows affected (0.06 sec) Records: 29 Duplicates: 0 Warnings: 0 mysql 5.7 >alter table products drop key color; Query OK, 29 rows affected (0.06 sec) Records: 29 Duplicates: 0 Warnings: 0 mysql 5.7 >select id,name from colors where id in(select distinctrow(color) from products where categ=296) order by id; +----+----------------+ | id | name | +----+----------------+ | 1 | Branco | | 2 | Preto | | 3 | Vermelho | | 4 | Azul | | 5 | Amarelo | | 6 | Verde | | 10 | Pink | | 11 | Azul escuro | | 12 | Laranja | | 20 | Verde Menta | | 21 | Vermelho Bord¶ | +----+----------------+ 11 rows in set (0.00 sec)
[11 Feb 2013 7:32]
Roy Lyseng
Hi Luis, a quick workaround for you, please try it out: set optimizer_switch='loosescan=off';
[11 Feb 2013 11:16]
Luis A S Junior Camargo
Hi Roy, Thank you, now i have tested with: set optimizer_switch='loosescan=off'; The returning result are correct after this.
[4 Mar 2013 15:10]
Paul DuBois
Noted in 5.6.11, 5.7.1 changelogs. Adding an ORDER BY clause following an IN subquery could cause duplicate rows to be returned.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.056 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.