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

Comparison ROW(stored_func(),1)=ROW(1,1) calls the function twice per row

Details

    Description

      I run this script:

      DELIMITER /
      CREATE OR REPLACE FUNCTION f1() RETURNS INT
      BEGIN
        SET @counter= COALESCE(@counter, 0) + 1;
        RETURN @counter;
      END;
      /
      DELIMITER ;
      SET @counter=0;
      SELECT f1()=1, @counter FROM seq_1_to_5;
      

      +--------+----------+
      | f1()=1 | @counter |
      +--------+----------+
      |      1 |        1 |
      |      0 |        2 |
      |      0 |        3 |
      |      0 |        4 |
      |      0 |        5 |
      +--------+----------+
      

      So far so good: the counter increments by one every row.

      Now I change the query to use ROWs:

      SELECT ROW(f1(),1) = ROW(1,1), @counter FROM seq_1_to_5;
      

      +------------------+----------+
      | (f1(),1) = (1,1) | @counter |
      +------------------+----------+
      |                0 |        7 |
      |                0 |        9 |
      |                0 |       11 |
      |                0 |       13 |
      |                0 |       15 |
      +------------------+----------+
      

      Now the counter increments twice per row. Looks wrong.

      Tracing in gdb reveals that Item_func_sp::execute() is indeed called twice per row:

      • From Item_func_sp::bring_value()
      • From Arg_comparator::compare_int_signed() when Arg_comparator::compare_row() evaluates equality of its members.

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov added a comment -

            Hello sanja_byelkin,

            Please review a patch for this issue for 11.8:

            https://github.com/MariaDB/server/commit/d9fbadaf2a13edd97fd9eca0f86cbaa6165da47d

            Thanks.

            bar Alexander Barkov added a comment - Hello sanja_byelkin , Please review a patch for this issue for 11.8: https://github.com/MariaDB/server/commit/d9fbadaf2a13edd97fd9eca0f86cbaa6165da47d Thanks.
            sanja Oleksandr Byelkin added a comment -

            OK to push after edding comment to Item::bring value and end 11.8 version tests marker to tests

            sanja Oleksandr Byelkin added a comment - OK to push after edding comment to Item::bring value and end 11.8 version tests marker to tests

            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.