[MDEV-11822] Virtual columns: No warning on data truncation Created: 2017-01-17  Updated: 2017-04-26

Status: Open
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Virtual Columns
Affects Version/s: 10.1.20, 10.2.3
Fix Version/s: 10.2

Type: Bug Priority: Minor
Reporter: Nirbhay Choubey (Inactive) Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: innodb, virtual_columns

Issue Links:
Relates
relates to MDEV-7635 update defaults and simplify mysqld c... Closed

 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.



 Comments   
Comment by Alice Sherepa [ 2017-04-26 ]

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)

Generated at Thu Feb 08 07:52:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.