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

BIGINT UNSIGNED value is out of range in '`test`.`edge`.`x1` - 1'

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Duplicate
    • 10.5.4
    • 10.5.11
    • Data types
    • None

    Description

      When executing the following example server sends metadata + error packet instead of sending metadata and data:

      static int test_ps(MYSQL *mysql)
      {
        MYSQL_STMT *stmt;
        int rc, i;
        MYSQL_BIND bind[5];
        unsigned char vals[5]= {1,1,1,1,1};
       
        rc= mysql_query(mysql, "CREATE TEMPORARY TABLE edge ( id INTEGER NOT NULL AUTO_INCREMENT, x1 INTEGER, y1 INTEGER, x2 INTEGER, y2 INTEGER, PRIMARY KEY (id))ENGINE=MyISAM");
        check_mysql_rc(rc, mysql);
       
        rc= mysql_query(mysql, "INSERT INTO edge (x1, y1, x2, y2) VALUES (0, 0, 3, 5)");
        check_mysql_rc(rc, mysql);
       
        rc= mysql_query(mysql, "INSERT INTO edge (x1, y1, x2, y2) VALUES (0, 1, 3, 5)");
        check_mysql_rc(rc, mysql);
       
        stmt= mysql_stmt_init(mysql);
        check_stmt_rc(rc, stmt);
       
        rc= mysql_stmt_prepare(stmt, SL("SELECT edge.id AS edge_id, edge.x1 AS edge_x1, edge.y1 AS edge_y1, edge.x2 AS edge_x2, edge.y2 AS edge_y2 FROM edge WHERE (edge.x1 - ?) * (edge.x1 - ?) + (edge.y1 - ?) * (edge.y1 - ?) <= ?"));
        check_stmt_rc(rc, stmt);
       
        memset(bind, 0, sizeof(MYSQL_BIND) * 5);
        for (i=0; i < 5; i++)
        {
          bind[i].buffer_type= MYSQL_TYPE_TINY;
          bind[i].buffer= &vals[i];
          bind[i].is_unsigned= 1;
        }
       
        rc= mysql_stmt_bind_param(stmt, bind);
        check_stmt_rc(rc, stmt);
       
        rc= mysql_stmt_execute(stmt);
        check_stmt_rc(rc, stmt);
       
        /* Error will be read here */
        rc= mysql_stmt_store_result(stmt);
        check_stmt_rc(rc, stmt);
       
        mysql_stmt_close(stmt);
        return OK;
      }
      

      Output:

      Error: BIGINT UNSIGNED value is out of range in '`test`.`edge`.`x1` - 1'
      

      Running the same statement in text protocol returns correct result:

      mysql> SELECT edge.id AS edge_id, edge.x1 AS edge_x1, edge.y1 AS edge_y1, edge.x2 AS edge_x2, edge.y2 AS edge_y2 FROM edge WHERE (edge.x1 - 1) * (edge.x1 - 1) + (edge.y1 - 1) * (edge.y1 - 1) <= 1;
      +---------+---------+---------+---------+---------+
      | edge_id | edge_x1 | edge_y1 | edge_x2 | edge_y2 |
      +---------+---------+---------+---------+---------+
      |       2 |       0 |       1 |       3 |       5 |
      +---------+---------+---------+---------+---------+
      1 row in set (0,00 sec)
      

      Attachments

        Issue Links

          Activity

            georg Georg Richter added a comment -

            Note: When setting bind[i].is_unsigned=0 everything works as expected.

            georg Georg Richter added a comment - Note: When setting bind [i] .is_unsigned=0 everything works as expected.

            As we figured it out, it is normal when after metadata goes error packet

            sanja Oleksandr Byelkin added a comment - As we figured it out, it is normal when after metadata goes error packet

            ah, problem is error at all

            sanja Oleksandr Byelkin added a comment - ah, problem is error at all

            [MySQL-10.5.11-MariaDB-debug-log][1690] BIGINT UNSIGNED value is out of range i
            n '`client_test_db`.`edge`.`x1` - 1'

            is the error.

            sanja Oleksandr Byelkin added a comment - [MySQL-10.5.11-MariaDB-debug-log] [1690] BIGINT UNSIGNED value is out of range i n '`client_test_db`.`edge`.`x1` - 1' is the error.

            test suite for client test, without unneeded thing, with cleanup:

            static void test_mdev_23481()
            {
              MYSQL_STMT *stmt;
              int rc;
              MYSQL_BIND bind[1];
              unsigned char vals[1]= {1};
             
              rc= mysql_query(mysql, "CREATE TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1 INTEGER, PRIMARY KEY (id))ENGINE=MyISAM");
              myquery(rc);
             
              rc= mysql_query(mysql, "INSERT INTO t1 (x1) VALUES (0)");
              myquery(rc);
             
              stmt= mysql_stmt_init(mysql);
              DIE_UNLESS(stmt != 0);
             
              rc= mysql_stmt_prepare(stmt, STRING_WITH_LEN("SELECT id FROM t1 WHERE (x1 - ?)"));
              check_execute(stmt, rc);
             
              memset(bind, 0, sizeof(MYSQL_BIND));
              bind[0].buffer_type= MYSQL_TYPE_TINY;
              bind[0].buffer= &vals[0];
              bind[0].is_unsigned= 1;
             
              rc= mysql_stmt_bind_param(stmt, bind);
              check_execute(stmt, rc);
             
              rc= mysql_stmt_execute(stmt);
              check_execute(stmt, rc);
             
              /* Error will be read here */
              rc= mysql_stmt_store_result(stmt);
              check_execute(stmt, rc);
             
              mysql_stmt_close(stmt);
              rc= mysql_query(mysql, "DROP TABLE t1");
              myquery(rc);
            }
            

            sanja Oleksandr Byelkin added a comment - test suite for client test, without unneeded thing, with cleanup: static void test_mdev_23481() { MYSQL_STMT *stmt; int rc; MYSQL_BIND bind[1]; unsigned char vals[1]= {1};   rc= mysql_query(mysql, "CREATE TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1 INTEGER, PRIMARY KEY (id))ENGINE=MyISAM"); myquery(rc);   rc= mysql_query(mysql, "INSERT INTO t1 (x1) VALUES (0)"); myquery(rc);   stmt= mysql_stmt_init(mysql); DIE_UNLESS(stmt != 0);   rc= mysql_stmt_prepare(stmt, STRING_WITH_LEN("SELECT id FROM t1 WHERE (x1 - ?)")); check_execute(stmt, rc);   memset(bind, 0, sizeof(MYSQL_BIND)); bind[0].buffer_type= MYSQL_TYPE_TINY; bind[0].buffer= &vals[0]; bind[0].is_unsigned= 1;   rc= mysql_stmt_bind_param(stmt, bind); check_execute(stmt, rc);   rc= mysql_stmt_execute(stmt); check_execute(stmt, rc);   /* Error will be read here */ rc= mysql_stmt_store_result(stmt); check_execute(stmt, rc);   mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE t1"); myquery(rc); }

            It has nothing to do with PS, here is text protocol example of the same bahaviour:

            CREATE TEMPORARY TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1
            INTEGER, y1 INTEGER UNSIGNED, PRIMARY KEY (id))ENGINE=MyISAM;
             
            INSERT INTO t1 (x1, y1) VALUES (0, 1);
             
            SELECT id, x1, y1 FROM t1 WHERE (x1 - y1);
             
            DROP TABLE t1;
            

            result:

            CREATE TEMPORARY TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1
            INTEGER, y1 INTEGER UNSIGNED, PRIMARY KEY (id))ENGINE=MyISAM;
            INSERT INTO t1 (x1, y1) VALUES (0, 1);
            SELECT id, x1, y1 FROM t1 WHERE (x1 - y1);
            main.test                                [ fail ]
                    Test ended at 2021-06-09 13:39:00
             
            CURRENT_TEST: main.test
            mysqltest: At line 6: query 'SELECT id, x1, y1 FROM t1 WHERE (x1 - y1)' failed: 1690: BIGINT UNSIGNED value is out of range in '`test`.`t1`.`x1` - `test`.`t1`.`y1`'
            

            sanja Oleksandr Byelkin added a comment - It has nothing to do with PS, here is text protocol example of the same bahaviour: CREATE TEMPORARY TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1 INTEGER, y1 INTEGER UNSIGNED, PRIMARY KEY (id))ENGINE=MyISAM;   INSERT INTO t1 (x1, y1) VALUES (0, 1);   SELECT id, x1, y1 FROM t1 WHERE (x1 - y1);   DROP TABLE t1; result: CREATE TEMPORARY TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, x1 INTEGER, y1 INTEGER UNSIGNED, PRIMARY KEY (id))ENGINE=MyISAM; INSERT INTO t1 (x1, y1) VALUES (0, 1); SELECT id, x1, y1 FROM t1 WHERE (x1 - y1); main.test [ fail ] Test ended at 2021-06-09 13:39:00   CURRENT_TEST: main.test mysqltest: At line 6: query 'SELECT id, x1, y1 FROM t1 WHERE (x1 - y1)' failed: 1690: BIGINT UNSIGNED value is out of range in '`test`.`t1`.`x1` - `test`.`t1`.`y1`'

            People

              sanja Oleksandr Byelkin
              georg Georg Richter
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.