Bug #98283 DEFAULT_VALUE in I_S.innodb_columns shows wrong result.
Submitted: 19 Jan 2020 7:51 Modified: 20 Jan 2020 10:09
Reporter: tom wang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Information schema Severity:S3 (Non-critical)
Version:8.0.12, 8.0.19 OS:Any
Assigned to: CPU Architecture:Any

[19 Jan 2020 7:51] tom wang
Description:
After do instant add column on table t1, when create another table t2 ,the value of DEFAULT_VALUE of table t2 on I_S.innodb_columns is wrong .

How to repeat:
mysql> create table t1 (a int primary key ,b int);
mysql> select * from information_schema.innodb_tables;
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+
| TABLE_ID | NAME                            | FLAG | N_COLS | SPACE      | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE | INSTANT_COLS |
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+
|     1025 | mysql/db                        |  161 |     25 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1026 | mysql/user                      |  161 |     52 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1027 | mysql/default_roles             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1028 | mysql/role_edges                |  161 |      8 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1029 | mysql/global_grants             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1030 | mysql/password_history          |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1031 | mysql/func                      |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1032 | mysql/plugin                    |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1033 | mysql/servers                   |  161 |     12 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1034 | mysql/tables_priv               |  161 |     11 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1035 | mysql/columns_priv              |  161 |     10 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1054 | mysql/help_topic                |  161 |      9 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1055 | mysql/help_category             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1057 | mysql/help_relation             |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1056 | mysql/help_keyword              |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1040 | mysql/time_zone_name            |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1041 | mysql/time_zone                 |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1042 | mysql/time_zone_transition      |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1043 | mysql/time_zone_transition_type |  161 |      8 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1044 | mysql/time_zone_leap_second     |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1045 | mysql/procs_priv                |  161 |     11 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1046 | mysql/component                 |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1047 | mysql/slave_relay_log_info      |  161 |     12 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1048 | mysql/slave_master_info         |  161 |     30 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1049 | mysql/slave_worker_info         |  161 |     16 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1050 | mysql/gtid_executed             |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1051 | mysql/server_cost               |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1052 | mysql/engine_cost               |  161 |      9 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1053 | mysql/proxies_priv              |  161 |     10 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1058 | sys/sys_config                  |   33 |      7 |          1 | Dynamic    |             0 | Single     |            0 |
|     1059 | sbtest/t1                       |   33 |      5 |          2 | Dynamic    |             0 | Single     |            0 |
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+
31 rows in set (0.01 sec)

mysql> select * from information_schema.innodb_columns where table_id = 1059;
+----------+------+-----+-------+--------+-----+-------------+---------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE |
+----------+------+-----+-------+--------+-----+-------------+---------------+
|     1059 | a    |   0 |     6 |   1283 |   4 |           0 | NULL          |
|     1059 | b    |   1 |     6 |   1027 |   4 |           0 | NULL          |
+----------+------+-----+-------+--------+-----+-------------+---------------+
2 rows in set (0.02 sec)

mysql> alter table t1 add column c int default 2;
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from information_schema.innodb_columns where table_id = 1059;
+----------+------+-----+-------+--------+-----+-------------+---------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE |
+----------+------+-----+-------+--------+-----+-------------+---------------+
|     1059 | a    |   0 |     6 |   1283 |   4 |           0 | NULL          |
|     1059 | b    |   1 |     6 |   1027 |   4 |           0 | NULL          |
|     1059 | c    |   2 |     6 |   1027 |   4 |           1 | 80000002      |
+----------+------+-----+-------+--------+-----+-------------+---------------+

mysql> create table t2 (a int primary key , b int);
Query OK, 0 rows affected (0.07 sec)

mysql> select * from information_schema.innodb_tables;
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+
| TABLE_ID | NAME                            | FLAG | N_COLS | SPACE      | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE | INSTANT_COLS |
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+
|     1025 | mysql/db                        |  161 |     25 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1026 | mysql/user                      |  161 |     52 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1027 | mysql/default_roles             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1028 | mysql/role_edges                |  161 |      8 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1029 | mysql/global_grants             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1030 | mysql/password_history          |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1031 | mysql/func                      |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1032 | mysql/plugin                    |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1033 | mysql/servers                   |  161 |     12 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1034 | mysql/tables_priv               |  161 |     11 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1035 | mysql/columns_priv              |  161 |     10 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1054 | mysql/help_topic                |  161 |      9 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1055 | mysql/help_category             |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1057 | mysql/help_relation             |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1056 | mysql/help_keyword              |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1040 | mysql/time_zone_name            |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1041 | mysql/time_zone                 |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1042 | mysql/time_zone_transition      |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1043 | mysql/time_zone_transition_type |  161 |      8 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1044 | mysql/time_zone_leap_second     |  161 |      5 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1045 | mysql/procs_priv                |  161 |     11 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1046 | mysql/component                 |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1047 | mysql/slave_relay_log_info      |  161 |     12 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1048 | mysql/slave_master_info         |  161 |     30 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1049 | mysql/slave_worker_info         |  161 |     16 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1050 | mysql/gtid_executed             |  161 |      6 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1051 | mysql/server_cost               |  161 |      7 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1052 | mysql/engine_cost               |  161 |      9 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1053 | mysql/proxies_priv              |  161 |     10 | 4294967294 | Dynamic    |             0 | General    |            0 |
|     1058 | sys/sys_config                  |   33 |      7 |          1 | Dynamic    |             0 | Single     |            0 |
|     1059 | sbtest/t1                       |   33 |      6 |          2 | Dynamic    |             0 | Single     |            2 |
|     1060 | sbtest/t2                       |   33 |      5 |          3 | Dynamic    |             0 | Single     |            0 |
+----------+---------------------------------+------+--------+------------+------------+---------------+------------+--------------+

mysql> select * from information_schema.innodb_columns where table_id = 1060;
+----------+------+-----+-------+--------+-----+-------------+---------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE |
+----------+------+-----+-------+--------+-----+-------------+---------------+
|     1060 | a    |   0 |     6 |   1283 |   4 |           0 | 80000002      |
|     1060 | b    |   1 |     6 |   1027 |   4 |           0 | 80000002      |
+----------+------+-----+-------+--------+-----+-------------+---------------+
[20 Jan 2020 9:15] MySQL Verification Team
Hello tom wang,

Thank you for the bug report and test case.
Imho this is known and documented behavior which I can confirm from the latest GA build 8.0.19 results. Quoting from manual 

" DEFAULT_VALUE

The initial default value of a column that was added instantly using ALTER TABLE ... ADD COLUMN with ALGORITHM=INSTANT. If the default value is NULL or was not specified, this column reports NULL. An explicitly specified non-NULL default value is shown in an internal binary format. Subsequent modifications of the column default value do not change the value reported by this column. " 

For more details, please see https://dev.mysql.com/doc/refman/8.0/en/innodb-columns-table.html

-- Also, same confirmed from my tests

 bin/mysql -uroot -S /tmp/mysql_ushastry.sock                                                                                                                         Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database if not exists bug98283;
Query OK, 1 row affected (0.00 sec)

mysql> use bug98283;
Database changed
mysql> create table t1 (a int primary key ,b int);
Query OK, 0 rows affected (0.01 sec)

mysql> select * from information_schema.innodb_tables where name='bug98283/t1';
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
| TABLE_ID | NAME        | FLAG | N_COLS | SPACE | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE | INSTANT_COLS |
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
|     1059 | bug98283/t1 |   33 |      5 |     2 | Dynamic    |             0 | Single     |            0 |
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
1 row in set (0.01 sec)

mysql> select * from information_schema.innodb_columns where table_id = 1059;
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE                |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
|     1059 | a    |   0 |     6 |   1283 |   4 |           0 | 0x                           |
|     1059 | b    |   1 |     6 |   1027 |   4 |           0 | 0x                           |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
2 rows in set (0.27 sec)

mysql> alter table t1 add column c int default 2;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from information_schema.innodb_columns where table_id = 1059;
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE                |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
|     1059 | a    |   0 |     6 |   1283 |   4 |           0 | 0x                           |
|     1059 | b    |   1 |     6 |   1027 |   4 |           0 | 0x                           |
|     1059 | c    |   2 |     6 |   1027 |   4 |           1 | 0x3830303030303032           |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
3 rows in set (0.26 sec)

mysql> create table t2 (a int primary key , b int);
Query OK, 0 rows affected (0.01 sec)

mysql> select * from information_schema.innodb_tables where name='bug98283/t2';
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
| TABLE_ID | NAME        | FLAG | N_COLS | SPACE | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE | INSTANT_COLS |
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
|     1060 | bug98283/t2 |   33 |      5 |     3 | Dynamic    |             0 | Single     |            0 |
+----------+-------------+------+--------+-------+------------+---------------+------------+--------------+
1 row in set (0.00 sec)

mysql> select * from information_schema.innodb_columns where table_id = 1060;
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE                |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
|     1060 | a    |   0 |     6 |   1283 |   4 |           0 | 0x3830303030303032           |
|     1060 | b    |   1 |     6 |   1027 |   4 |           0 | 0x3830303030303032           |
+----------+------+-----+-------+--------+-----+-------------+------------------------------+
2 rows in set (0.27 sec)

regards,
Umesh
[20 Jan 2020 9:41] tom wang
Hi Umesh Shastry

quoting from manual
" If the default value is NULL or was not specified, this column reports NULL. An explicitly specified non-NULL default value is shown in an internal binary format."

so DEFAULT_VALUE of column a and b in table  'bug98283/t2'  should be NULL like 'bug98283/t1' rather than 0x3830303030303032. 
 
another case:
master8>create table t3 (a int primary key ,b int default 0);

master8>select * from information_schema.innodb_tables where name like '%t3';
+----------+-----------+------+--------+-------+------------+---------------+------------+--------------+
| TABLE_ID | NAME      | FLAG | N_COLS | SPACE | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE | INSTANT_COLS |
+----------+-----------+------+--------+-------+------------+---------------+------------+--------------+
|     1061 | sbtest/t3 |   33 |      5 |     4 | Dynamic    |             0 | Single     |            0 |
+----------+-----------+------+--------+-------+------------+---------------+------------+--------------+

master8>select * from information_schema.innodb_columns where table_id = 1061;
+----------+------+-----+-------+--------+-----+-------------+---------------+
| TABLE_ID | NAME | POS | MTYPE | PRTYPE | LEN | HAS_DEFAULT | DEFAULT_VALUE |
+----------+------+-----+-------+--------+-----+-------------+---------------+
|     1061 | a    |   0 |     6 |   1283 |   4 |           0 | 80000002      |
|     1061 | b    |   1 |     6 |   1027 |   4 |           0 | 80000002      |
+----------+------+-----+-------+--------+-----+-------------+---------------+

DEFAULT_VALUE of column b in table t3 should not be 80000002.
[20 Jan 2020 10:09] MySQL Verification Team
Agree, thank you for the feedback.
If this is intended behavior then doc should be modified to avoid confusion.

regards,
Umesh