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

SEC_TO_TIME executes side effect two times

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL)
    • 10.4.0
    • OTHER
    • None

    Description

      Item_func_sec_to_time::get_date() executes val_str() to print warnings. So value methods for args[0] are executed two times:
      1. val_int() or val_decimal() in get_deconds(), to get the "sec + sec_part" pair.
      2. val_str(), to generate a warning, in case of overflow.

      This looks wrong, especially for functions with side effect.

      Example 1:

      I run this script:

      SET @a=10000000;
      SELECT SEC_TO_TIME(@a:=@a+1);
      SELECT @a;
      

      It returns 838:59:59 from the first SELECT, with a warning as expected. But then the second SELECT returns a wrong result:

      +----------+
      | @a       |
      +----------+
      | 10000002 |
      +----------+
      

      The expected result should be 10000001.

      Example 2:

      SELECT SEC_TO_TIME(LAST_VALUE(SLEEP(0.33),10000000));
      

      +-----------------------------------------------+
      | SEC_TO_TIME(LAST_VALUE(SLEEP(0.33),10000000)) |
      +-----------------------------------------------+
      | 838:59:59                                     |
      +-----------------------------------------------+
      1 row in set, 1 warning (0.66 sec)
      

      Notice, it says 0.66 sec in the query statistics. The expected timing should be 0.33 sec, as in SLEEP.

      Example 3:

      DROP TABLE IF EXISTS t1;
      DROP FUNCTION IF EXISTS f1;
      CREATE TABLE t1 (a TEXT);
      DELIMITER $$
      CREATE FUNCTION f1() RETURNS INT
      BEGIN
        INSERT INTO t1 VALUES ('f1 was called');
        RETURN 10000000;
      END;
      $$
      DELIMITER ;
      SELECT SEC_TO_TIME(f1());
      SELECT * FROM t1;
      

      +---------------+
      | a             |
      +---------------+
      | f1 was called |
      | f1 was called |
      +---------------+
      

      Notice, the INSERT happened two times. The expected behavior would be to do INSERT only once.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.