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

Virtual columns: No warning on data truncation

Details

    Description

      MariaDB [test]> SET sql_mode = '';
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> CREATE TABLE t1(a INT);
      Query OK, 0 rows affected (0.05 sec)
       
      MariaDB [test]> INSERT INTO t1 VALUES(2147483647);
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [test]> ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED;
      Query OK, 1 row affected, 1 warning (0.16 sec)     
      Records: 1  Duplicates: 0  Warnings: 1
       
      MariaDB [test]> SHOW WARNINGS;
      +---------+------+--------------------------------------------+
      | Level   | Code | Message                                    |
      +---------+------+--------------------------------------------+
      | Warning | 1264 | Out of range value for column 'b' at row 1 |
      +---------+------+--------------------------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL;
      Query OK, 0 rows affected (0.10 sec)
      Records: 0  Duplicates: 0  Warnings: 0  <-- No warning
       
      MariaDB [test]> SELECT * FROM t1;
      +------------+-------+-------+
      | a          | b     | c     |
      +------------+-------+-------+
      | 2147483647 | 32767 | 32767 |
      +------------+-------+-------+
      1 row in set (0.00 sec)
      

      Note: This only happens with InnoDB.

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            I've got the same warnings on 10.1.22

            CREATE TABLE t1(a int) engine=innodb
            --------------
            Query OK, 0 rows affected (0.34 sec)
             
            --------------
            INSERT INTO t1 VALUES(128)
            --------------
            Query OK, 1 row affected (0.02 sec)
             
            --------------
            ALTER TABLE t1 ADD COLUMN d tinyint AS (a) VIRTUAL, ALGORITHM=COPY
            --------------
            Query OK, 1 row affected, 1 warning (0.71 sec)     
            Records: 1  Duplicates: 0  Warnings: 1
             
            Warning (Code 1264): Out of range value for column 'd' at row 1
            --------------
            ALTER TABLE t1 ADD COLUMN e tinyint AS (a) VIRTUAL
            --------------
            Query OK, 0 rows affected (0.40 sec)
            Records: 0  Duplicates: 0  Warnings: 0
             
            --------------
            SELECT * FROM t1
            --------------
            +------+------+------+
            | a    | d    | e    |
            +------+------+------+
            |  128 |  127 |  127 |
            +------+------+------+
            1 row in set (0.00 sec)
            
            

            I tried also with different types, it seems it appears only with bigint, smallint, tinyint. In other cases there is no warnings in both cases.

            CREATE TABLE t1(a decimal (5,2)) engine=innodb
            --------------
            Query OK, 0 rows affected (0.24 sec)
             
            --------------
            INSERT INTO t1 VALUES(1000)
            --------------
            Query OK, 1 row affected, 1 warning (0.03 sec)
             
            Warning (Code 1264): Out of range value for column 'a' at row 1
            --------------
            ALTER TABLE t1 ADD COLUMN d int AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED
            --------------
            Query OK, 1 row affected (0.52 sec)                
            Records: 1  Duplicates: 0  Warnings: 0
             
            --------------
            ALTER TABLE t1 ADD COLUMN e int AS (a) VIRTUAL
            --------------
            Query OK, 0 rows affected (0.46 sec)
            Records: 0  Duplicates: 0  Warnings: 0
             
            --------------
            SELECT * FROM t1
            --------------
             
            +--------+------+------+
            | a      | d    | e    |
            +--------+------+------+
            | 999.99 | 1000 | 1000 |
            +--------+------+------+
            1 row in set (0.01 sec)
            

            alice Alice Sherepa added a comment - I've got the same warnings on 10.1.22 CREATE TABLE t1(a int ) engine=innodb -------------- Query OK, 0 rows affected (0.34 sec)   -------------- INSERT INTO t1 VALUES (128) -------------- Query OK, 1 row affected (0.02 sec)   -------------- ALTER TABLE t1 ADD COLUMN d tinyint AS (a) VIRTUAL, ALGORITHM=COPY -------------- Query OK, 1 row affected, 1 warning (0.71 sec) Records: 1 Duplicates: 0 Warnings: 1   Warning (Code 1264): Out of range value for column 'd' at row 1 -------------- ALTER TABLE t1 ADD COLUMN e tinyint AS (a) VIRTUAL -------------- Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0   -------------- SELECT * FROM t1 -------------- + ------+------+------+ | a | d | e | + ------+------+------+ | 128 | 127 | 127 | + ------+------+------+ 1 row in set (0.00 sec) I tried also with different types, it seems it appears only with bigint, smallint, tinyint. In other cases there is no warnings in both cases. CREATE TABLE t1(a decimal (5,2)) engine=innodb -------------- Query OK, 0 rows affected (0.24 sec)   -------------- INSERT INTO t1 VALUES (1000) -------------- Query OK, 1 row affected, 1 warning (0.03 sec)   Warning (Code 1264): Out of range value for column 'a' at row 1 -------------- ALTER TABLE t1 ADD COLUMN d int AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED -------------- Query OK, 1 row affected (0.52 sec) Records: 1 Duplicates: 0 Warnings: 0   -------------- ALTER TABLE t1 ADD COLUMN e int AS (a) VIRTUAL -------------- Query OK, 0 rows affected (0.46 sec) Records: 0 Duplicates: 0 Warnings: 0   -------------- SELECT * FROM t1 --------------   + --------+------+------+ | a | d | e | + --------+------+------+ | 999.99 | 1000 | 1000 | + --------+------+------+ 1 row in set (0.01 sec)

            People

              serg Sergei Golubchik
              nirbhay_c Nirbhay Choubey (Inactive)
              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.