Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-23525

Wrong result of MIN(time_expr) and MAX(time_expr) with GROUP BY

    XMLWordPrintable

    Details

      Description

      I run this script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (i INT, d TIME);
      INSERT INTO t1 VALUES (1,'10:20:30');
      INSERT INTO t1 VALUES (1,'100:20:20');
      SELECT MIN(d), MAX(d) FROM t1;
      SELECT i, MIN(d), MAX(d) FROM t1 GROUP BY i;
      

      The first SELECT returns:

      +----------+-----------+
      | MIN(d)   | MAX(d)    |
      +----------+-----------+
      | 10:20:30 | 100:20:20 |
      +----------+-----------+
      

      Looks correct.

      The second SELECT returns:

      +------+-----------+----------+
      | i    | MIN(d)    | MAX(d)   |
      +------+-----------+----------+
      |    1 | 100:20:20 | 10:20:30 |
      +------+-----------+----------+
      

      Looks wrong. The MIN and MAX values swapped.

      The problem happens in this code:

      void Item_sum_min_max::update_field()
      {
      ...
          switch (Item_sum_min_max::type_handler()->cmp_type()) {
          case STRING_RESULT:
          case TIME_RESULT:
            min_max_update_str_field();
      

      Notice, it compares TIME values in text format.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: