[MDEV-23314] strange/random select results Created: 2020-07-28 Updated: 2020-08-05 Resolved: 2020-08-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Subquery |
| Affects Version/s: | 5.5, 10.2.32, 10.3.23, 10.4.13 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Miguel Dias | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Strange select results when running this query "select * FROM tmp WHERE id in (select cast(rand()*10 as int)+1);" against a simple small table. This is easy enough to reproduce: CREATE TABLE `tmp` ( INSERT INTO `tmp` VALUES (1,80),(2,253),(3,333),(4,569),(5,606),(6,618),(7,660),(8,663),(9,690),(10,693); select * FROM tmp WHERE id in (select cast(rand()*10 as int)+1); select * FROM tmp WHERE id in (select cast(rand()*10 as int)+1);
---
---
---
--- but when I run select cast(rand()*10 as int)+1 alone, I only ever get one result... |
| Comments |
| Comment by Elena Stepanova [ 2020-08-05 ] |
|
The value is recalculated for every row, and on each recalculation rand() returns a different result, hence the randomness. |