[MDEV-27098] Subquery using the ALL keyword on TIME columns produces a wrong result Created: 2021-11-20  Updated: 2021-12-11  Resolved: 2021-11-20

Status: Closed
Project: MariaDB Server
Component/s: Data types, Temporal Types
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
Fix Version/s: 10.2.42, 10.3.33, 10.4.23, 10.5.14, 10.6.6

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-27072 Subquery using the ALL keyword on dat... Closed
relates to MDEV-27099 Subquery using the ALL keyword on INE... Closed
relates to MDEV-27100 Subquery using the ALL keyword on UUI... Closed
relates to MDEV-27101 Subquery using the ALL keyword on TIM... Closed

 Description   

This bug related to MDEV-27072 but happend because of a very different reason than MDEV-27072.

I create a table:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (d TIME);
INSERT INTO t1 VALUES ('120:00:00'), ('20:00:00'), ('-120:00:00'), ('-220:00:00');

Now I run this query:

SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1);

+-----------+
| d         |
+-----------+
| 120:00:00 |
| 20:00:00  |
+-----------+

The result is wrong. It should return only one row the maxumum value, which is '120:00:00'.

The same problem happens with this query:

SELECT * FROM t1 WHERE d <= ALL (SELECT * FROM t1);

+------------+
| d          |
+------------+
| -120:00:00 |
| -220:00:00 |
+------------+

It should return only one row with the minumum value, which is '-220:00:00'.

The problem happens because select_max_min_finder_subselect::cmp_str() is executed at some point during these queries. It compares values as strings, therefore:

  • '120:00:00' is erroneously compared as less than '20:00:00'
  • '-220:00:00' is erroneously compared as greater than '-120:00:00'

The TIME data type needs its own implementation, e.g. select_max_min_finder_subselect::cmp_time().



 Comments   
Comment by Alexander Barkov [ 2021-11-20 ]

The same problem is repeatable with the INET6 data type: See MDEV-27099.

Comment by Alexander Barkov [ 2021-11-20 ]

The same problem is repeatable with the UUID data type: see MDEV-27100

Generated at Thu Feb 08 09:50:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.