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

MariaDB 10.3.10 When referring to bigint to generate timestamp data in the virtual generated column, the value of the generated column does not change when the time zone changes

Details

    Description

      When creating a virtual column, if the virtual column is timestamp, the value of the virtual column does not change when the time zone changes, and the mysql version changes.

      mariadb10.3:

       
       create table test_timestamp (`create_timestamp` timestamp(3) NOT NULL COMMENT '记录创建时间',`create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` )) VIRTUAL COMMENT '记录创建时间');
       
      insert into test_timestamp (`create_timestamp`) value (1569495326.861);
       
       
      mysql> select * from test_timestamp;
      +------------------+-------------------------+
      | create_timestamp | create_time             |
      +------------------+-------------------------+
      |    1569495326861 | 2019-09-26 10:55:26.861 |
      +------------------+-------------------------+
      1 row in set (0.01 sec)
       
      mysql> set time_zone = "+01:00";
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> select * from test_timestamp;
      +------------------+-------------------------+
      | create_timestamp | create_time             |
      +------------------+-------------------------+
      |    1569495326861 | 2019-09-26 10:55:26.861 |
      +------------------+-------------------------+
      1 row in set (0.00 sec)
       

      mysql5.7:

       mysql> create table test_timestamp (`create_timestamp` bigint(20) NOT NULL COMMENT '记录创建时间',
          ->   `create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` / 1000)) VIRTUAL COMMENT '记录创建时间');
      Query OK, 0 rows affected (0.31 sec)
       
      mysql> insert into test_timestamp (`create_timestamp`) value (1569495326861);
      Query OK, 1 row affected (0.03 sec)
       
      mysql> select * from test_timestamp;
      +------------------+-------------------------+
      | create_timestamp | create_time             |
      +------------------+-------------------------+
      |    1569495326861 | 2019-09-26 10:55:26.861 |
      +------------------+-------------------------+
      1 row in set (0.01 sec)
       
      mysql> set time_zone = "+01:00";
      Query OK, 0 rows affected (0.00 sec)
       
      mysql> select * from test_timestamp;
      +------------------+-------------------------+
      | create_timestamp | create_time             |
      +------------------+-------------------------+
      |    1569495326861 | 2019-09-26 11:55:26.861 |
      +------------------+-------------------------+
      1 row in set (0.00 sec)
      

      Attachments

        Issue Links

          Activity

            1152175253@qq.com hongsheng zhou created issue -
            1152175253@qq.com hongsheng zhou made changes -
            Field Original Value New Value
            Description mariadb 创建一个虚拟列时,如果虚拟列为timestamp时,当时区发生变化时,虚拟列的值不发生变化,而mysql版本会发生变化

            mariadb10.3环境:

             create table test_timestamp (`create_timestamp` timestamp(3) NOT NULL COMMENT '记录创建时间',`create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` )) VIRTUAL COMMENT '记录创建时间');

            insert into test_timestamp (`create_timestamp`) value (1569495326.861);


            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
             


            mysql5.7环境:

             mysql> create table test_timestamp (`create_timestamp` bigint(20) NOT NULL COMMENT '记录创建时间',
                -> `create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` / 1000)) VIRTUAL COMMENT '记录创建时间');
            Query OK, 0 rows affected (0.31 sec)

            mysql> insert into test_timestamp (`create_timestamp`) value (1569495326861);
            Query OK, 1 row affected (0.03 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 11:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
            When creating a virtual column, if the virtual column is timestamp, the value of the virtual column does not change when the time zone changes, and the mysql version changes.

            mariadb10.3:

             create table test_timestamp (`create_timestamp` timestamp(3) NOT NULL COMMENT '记录创建时间',`create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` )) VIRTUAL COMMENT '记录创建时间');

            insert into test_timestamp (`create_timestamp`) value (1569495326.861);


            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
             


            mysql5.7:

             mysql> create table test_timestamp (`create_timestamp` bigint(20) NOT NULL COMMENT '记录创建时间',
                -> `create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` / 1000)) VIRTUAL COMMENT '记录创建时间');
            Query OK, 0 rows affected (0.31 sec)

            mysql> insert into test_timestamp (`create_timestamp`) value (1569495326861);
            Query OK, 1 row affected (0.03 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 11:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
            Environment 生产环境 ubuntu 16.04 ubuntu 16.04 mariadb 10.3
            Summary mariadb 10.3.10 虚拟生成列中引用bigint 生成timestamp类型的数据时,当时区变化时,生成列的值不变化  MariaDB 10.3.10 When referring to bigint to generate timestamp data in the virtual generated column, the value of the generated column does not change when the time zone changes
            alice Alice Sherepa made changes -
            Description When creating a virtual column, if the virtual column is timestamp, the value of the virtual column does not change when the time zone changes, and the mysql version changes.

            mariadb10.3:

             create table test_timestamp (`create_timestamp` timestamp(3) NOT NULL COMMENT '记录创建时间',`create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` )) VIRTUAL COMMENT '记录创建时间');

            insert into test_timestamp (`create_timestamp`) value (1569495326.861);


            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
             


            mysql5.7:

             mysql> create table test_timestamp (`create_timestamp` bigint(20) NOT NULL COMMENT '记录创建时间',
                -> `create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` / 1000)) VIRTUAL COMMENT '记录创建时间');
            Query OK, 0 rows affected (0.31 sec)

            mysql> insert into test_timestamp (`create_timestamp`) value (1569495326861);
            Query OK, 1 row affected (0.03 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 11:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
            When creating a virtual column, if the virtual column is timestamp, the value of the virtual column does not change when the time zone changes, and the mysql version changes.

            mariadb10.3:

            {noformat}

             create table test_timestamp (`create_timestamp` timestamp(3) NOT NULL COMMENT '记录创建时间',`create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` )) VIRTUAL COMMENT '记录创建时间');

            insert into test_timestamp (`create_timestamp`) value (1569495326.861);


            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
             {noformat}


            mysql5.7:
            {noformat}
             mysql> create table test_timestamp (`create_timestamp` bigint(20) NOT NULL COMMENT '记录创建时间',
                -> `create_time` timestamp(3) GENERATED ALWAYS AS (from_unixtime(`create_timestamp` / 1000)) VIRTUAL COMMENT '记录创建时间');
            Query OK, 0 rows affected (0.31 sec)

            mysql> insert into test_timestamp (`create_timestamp`) value (1569495326861);
            Query OK, 1 row affected (0.03 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 10:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.01 sec)

            mysql> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.00 sec)

            mysql> select * from test_timestamp;
            +------------------+-------------------------+
            | create_timestamp | create_time |
            +------------------+-------------------------+
            | 1569495326861 | 2019-09-26 11:55:26.861 |
            +------------------+-------------------------+
            1 row in set (0.00 sec)
            {noformat}
            alice Alice Sherepa made changes -
            Affects Version/s 5.5 [ 15800 ]
            Affects Version/s 10.0 [ 16000 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 10.4 [ 22408 ]
            alice Alice Sherepa made changes -
            Labels datatype datatype virtual_columns
            alice Alice Sherepa added a comment -

            Thanks a lot! I repeated on MariaDb 5.5-10.4:

            create table t1 (a int, b timestamp GENERATED ALWAYS AS (from_unixtime(a)) VIRTUAL);
            insert into t1 (a) value (1569495327);
             
            select a, b, from_unixtime(a) from t1;
            set time_zone = "+01:00";
            select a, b, from_unixtime(a) from t1;
             
            drop table t1;
            

            MariaDB [test]> select a, b, from_unixtime(a) from t1;
            +------------+---------------------+---------------------+
            | a          | b                   | from_unixtime(a)    |
            +------------+---------------------+---------------------+
            | 1569495327 | 2019-09-26 12:55:27 | 2019-09-26 12:55:27 |
            +------------+---------------------+---------------------+
            1 row in set (0.000 sec)
             
            MariaDB [test]> set time_zone = "+01:00";
            Query OK, 0 rows affected (0.000 sec)
             
            MariaDB [test]> select a, b, from_unixtime(a) from t1;
            +------------+---------------------+---------------------+
            | a          | b                   | from_unixtime(a)    |
            +------------+---------------------+---------------------+
            | 1569495327 | 2019-09-26 12:55:27 | 2019-09-26 11:55:27 |
            +------------+---------------------+---------------------+
            1 row in set (0.000 sec)
            

            alice Alice Sherepa added a comment - Thanks a lot! I repeated on MariaDb 5.5-10.4: create table t1 (a int , b timestamp GENERATED ALWAYS AS (from_unixtime(a)) VIRTUAL); insert into t1 (a) value (1569495327);   select a, b, from_unixtime(a) from t1; set time_zone = "+01:00" ; select a, b, from_unixtime(a) from t1;   drop table t1; MariaDB [test]> select a, b, from_unixtime(a) from t1; +------------+---------------------+---------------------+ | a | b | from_unixtime(a) | +------------+---------------------+---------------------+ | 1569495327 | 2019-09-26 12:55:27 | 2019-09-26 12:55:27 | +------------+---------------------+---------------------+ 1 row in set (0.000 sec)   MariaDB [test]> set time_zone = "+01:00"; Query OK, 0 rows affected (0.000 sec)   MariaDB [test]> select a, b, from_unixtime(a) from t1; +------------+---------------------+---------------------+ | a | b | from_unixtime(a) | +------------+---------------------+---------------------+ | 1569495327 | 2019-09-26 12:55:27 | 2019-09-26 11:55:27 | +------------+---------------------+---------------------+ 1 row in set (0.000 sec)
            alice Alice Sherepa made changes -
            Fix Version/s 5.5 [ 15800 ]
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            alice Alice Sherepa made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            alice Alice Sherepa made changes -
            Assignee Sergei Golubchik [ serg ]
            serg Sergei Golubchik made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Component/s Virtual Columns [ 10803 ]
            Component/s Data Manipulation - Insert [ 10101 ]
            Fix Version/s 10.2.31 [ 24017 ]
            Fix Version/s 10.3.22 [ 24018 ]
            Fix Version/s 10.4.12 [ 24019 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 5.5 [ 15800 ]
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 101724 ] MariaDB v4 [ 157066 ]

            People

              serg Sergei Golubchik
              1152175253@qq.com hongsheng zhou
              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.