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

user variable assignment and if function

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Stalled (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.1.40, 10.3.20
    • Fix Version/s: N/A
    • Component/s: Variables
    • Labels:
      None

      Description

      Hello,

      we ran into a problem while using user variables and using different collations. It seems that a variable assignment can take place even if the condition to do so is not met.

      Out server is set to use utf8mb4_unicode_ci. But some connections are using utf8_unicode_ci, and only those connections show the following problem.

      We broke it down to the following example SQL (the real statement is much more complex and not so easy to work around the shown behaviour):

      SET NAMES UTF8mb4 COLLATE UTF8MB4_UNICODE_CI;
      create TABLE t1 (side VARCHAR(10)) COLLATE utf8mb4_unicode_ci;
       
      INSERT INTO t1 (side) VALUES ('L');
       
      SET NAMES UTF8 COLLATE UTF8_unicode_CI;
      SET @bla = 'foo';
      SELECT if(@bla = 'bar', @bla := s.side, @bla := 'bar') FROM t1 s;
       
      DROP TABLE t1;
      

      My expectation is, that the result is a single value 'bar', because the if condition should fail and therefore the "else" statement should be executed. But we observe that the result is 'L', which can only be if the if condition succeeds. A quick check shows that @bla is really 'bar'. How can this be?

      If I leave out the line "set names utf8 collate utf8_unicode_ci", that is if I continue to use utf8mb4_unicode_ci, I get the expected result and behavior.

      Is this a bug, or a somehow intended behavior?

      Best regards,

      Thomas Mischke

        Attachments

          Activity

            People

            Assignee:
            bar Alexander Barkov
            Reporter:
            thomas.mischke Thomas Mischke
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: