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

Negative SP variable in LIMIT is treated as big positive

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5, 10.0, 10.1, 10.2, 10.3
    • 10.4
    • Prepared Statements
    • None

    Description

      This script erroneously returns a row:

      DROP PROCEDURE IF EXISTS p1;
      DELIMITER $$
      CREATE PROCEDURE p1()
      BEGIN
        DECLARE a INT DEFAULT -1;
        SELECT 1 FROM DUAL LIMIT a;
      END;
      $$
      DELIMITER ;
      CALL p1;
      

      +---+
      | 1 |
      +---+
      | 1 |
      +---+
      

      Note, if I rewrite the query using a prepared statement with a negative user variable, it correctly returns an error:

      DROP PROCEDURE IF EXISTS p1;
      DELIMITER $$
      CREATE PROCEDURE p1()
      BEGIN
        SET @a=-1;
        PREPARE stmt FROM 'SELECT 1 FROM DUAL LIMIT ?';
        EXECUTE stmt USING @a;
      END;
      $$
      DELIMITER ;
      CALL p1;
      

      ERROR 1210 (HY000): Incorrect arguments to EXECUTE
      

      Note, If in the version 10.2 or higher (which support any kind of expressions in PS parameters) I use a prepared statement with a negative SP variable, it also correctly returns an error:

      DROP PROCEDURE IF EXISTS p1;
      DELIMITER $$
      CREATE PROCEDURE p1()
      BEGIN
        DECLARE a INT DEFAULT -1;
        PREPARE stmt FROM 'SELECT 1 FROM DUAL LIMIT ?';
        EXECUTE stmt USING a;
      END;
      $$
      DELIMITER ;
      CALL p1;
      

      ERROR 1210 (HY000): Incorrect arguments to EXECUTE
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:

              Git Integration

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