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

IF NOT EXISTS AND NOT EXISTS crash DB server

Details

    Description

      Call stored procedure with IF NOT EXISTS AND NOT EXISTS condition crash the DB server.

      The case can be reproduced as follows:

      1. Create tables 'test' and 'test2' and insert values into them:

      CREATE TABLE `test` (
        `name` varchar(100) NOT NULL,
        `address` varchar(100) DEFAULT NULL,
        PRIMARY KEY (`name`));
       
      CREATE TABLE `test2` (
        `name` varchar(100) NOT NULL,
        `address` varchar(100) DEFAULT NULL,
        PRIMARY KEY (`name`));
       
      INSERT INTO test VALUES ('a', 'aaa');
      INSERT INTO test2 VALUES ('a', 'aaa');
      

      2. Create stored procedure 'test_if':

      DELIMITER ;;
      DROP PROCEDURE IF EXISTS `test_if` ;
      CREATE  PROCEDURE `test_if`(
              IN in_name NVARCHAR(20)
      )
      BEGIN
       
          If NOT EXISTS (select name from test where name = name)
          AND NOT EXISTS (select name from test2 where name = name)
          THEN
             select "NOT EXISTS";
          ELSE
             select "EXISTS";
          END IF;
       
          SELECT * FROM test;
      END ;;
      DELIMITER ;
      

      3. Run: call test_if('a'); (OK, no error)
      4. Run again: call test_if('a'); , it will crash the DB server

      The error message 'error.txt' is attached for your reference.

      Please investigate.

      Thanks,

      Chow King Tak

      Attachments

        Issue Links

          Activity

            ktchow_ogcio Chow King Tak created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            Component/s Stored routines [ 13905 ]
            Component/s Server [ 13907 ]
            Fix Version/s 10.4 [ 22408 ]
            elenst Elena Stepanova made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            Assignee Oleksandr Byelkin [ sanja ]
            elenst Elena Stepanova made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            alice Alice Sherepa made changes -
            Affects Version/s 10.4 [ 22408 ]
            serg Sergei Golubchik made changes -
            Description Call stored procedure with IF NOT EXISTS AND NOT EXISTS condition crash the DB server.

            The case can be reproduced as follows:

            1. Create tables 'test' and 'test2' and insert values into them:
            CREATE TABLE `test` (
              `name` varchar(100) NOT NULL,
              `address` varchar(100) DEFAULT NULL,
              PRIMARY KEY (`name`));

            CREATE TABLE `test2` (
              `name` varchar(100) NOT NULL,
              `address` varchar(100) DEFAULT NULL,
              PRIMARY KEY (`name`));

            INSERT INTO test VALUES ('a', 'aaa');
            INSERT INTO test2 VALUES ('a', 'aaa');

            2. Create stored procedure 'test_if':

            DELIMITER ;;
            DROP PROCEDURE IF EXISTS `test_if` ;
            CREATE PROCEDURE `test_if`(
                    IN in_name NVARCHAR(20)
            )
            BEGIN

                If NOT EXISTS (select name from test where name = name)
                AND NOT EXISTS (select name from test2 where name = name)
                THEN
                   select "NOT EXISTS";
                ELSE
                   select "EXISTS";
                END IF;

                SELECT * FROM test;
            END ;;
            DELIMITER ;


            3. Run: call test_if('a'); (OK, no error)
            4. Run again: call test_if('a'); , it will crash the DB server

            The error message 'error.txt' is attached for your reference.

            Please investigate.

            Thanks,

            Chow King Tak

            Call stored procedure with IF NOT EXISTS AND NOT EXISTS condition crash the DB server.

            The case can be reproduced as follows:

            1. Create tables 'test' and 'test2' and insert values into them:
            {code:sql}
            CREATE TABLE `test` (
              `name` varchar(100) NOT NULL,
              `address` varchar(100) DEFAULT NULL,
              PRIMARY KEY (`name`));

            CREATE TABLE `test2` (
              `name` varchar(100) NOT NULL,
              `address` varchar(100) DEFAULT NULL,
              PRIMARY KEY (`name`));

            INSERT INTO test VALUES ('a', 'aaa');
            INSERT INTO test2 VALUES ('a', 'aaa');
            {code}
            2. Create stored procedure 'test_if':
            {code:sql}
            DELIMITER ;;
            DROP PROCEDURE IF EXISTS `test_if` ;
            CREATE PROCEDURE `test_if`(
                    IN in_name NVARCHAR(20)
            )
            BEGIN

                If NOT EXISTS (select name from test where name = name)
                AND NOT EXISTS (select name from test2 where name = name)
                THEN
                   select "NOT EXISTS";
                ELSE
                   select "EXISTS";
                END IF;

                SELECT * FROM test;
            END ;;
            DELIMITER ;
            {code}

            3. Run: call test_if('a'); (OK, no error)
            4. Run again: call test_if('a'); , it will crash the DB server

            The error message 'error.txt' is attached for your reference.

            Please investigate.

            Thanks,

            Chow King Tak

            alice Alice Sherepa made changes -
            Affects Version/s 10.5 [ 23123 ]
            alice Alice Sherepa made changes -
            Fix Version/s 10.5 [ 23123 ]
            sanja Oleksandr Byelkin made changes -
            Fix Version/s 10.5.4 [ 24264 ]
            Fix Version/s 10.4.13 [ 24223 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Resolution Duplicate [ 3 ]
            Status Confirmed [ 10101 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 100349 ] MariaDB v4 [ 156847 ]
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 169530 128337

            People

              sanja Oleksandr Byelkin
              ktchow_ogcio Chow King Tak
              Votes:
              2 Vote for this issue
              Watchers:
              9 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.