[MDEV-29200] CREATE_TIME is newer than UPDATE_TIME in information_schema.TABLES Created: 2022-07-29  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Information Schema, Storage Engine - InnoDB
Affects Version/s: 10.3.34, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Allen Lee (Inactive) Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-29191 Use statx/btime instead of stat/ctime... Open

 Description   

This is the example of CREATE_TIME is newer than UPDATE_TIME in information_schema.TABLES.

MariaDB [information_schema]> select TABLE_SCHEMA,TABLE_NAME,ENGINE,CREATE_TIME,UPDATE_TIME from information_schema.TABLES where UPDATE_TIME < CREATE_TIME ;
+--------------+------------+--------+---------------------+---------------------+
| TABLE_SCHEMA | TABLE_NAME | ENGINE | CREATE_TIME | UPDATE_TIME |
+--------------+------------+--------+---------------------+---------------------+
| sysbench | sbtest23 | InnoDB | 2022-07-27 09:41:52 | 2022-07-27 09:39:22 |
+--------------+------------+--------+---------------------+---------------------+
1 row in set (0.006 sec)
----------------------------------------------

The above example shows that UPDATE_TIME is older than CREATE_TIME because I've run `alter table sbtest2 rename to sbtest23;` Restarting server/altering table would force UPDATE_TIME to set NULL, but change CREATE_TIME as current.
However, one of our customer said they did not run any type of alter/restarting server, but information_schema.TABLES shows CREATE_TIME is newer than UPDATE_TIME. I found the bug in mysql as well - https://dba.stackexchange.com/questions/312251/mysql-information-schema-tables-shows-create-time-later-than-update-time, but I am sure our implementation of information_schema.TABLES is different than mysql v8.x as we have many missing globals than mysql v8.

So, the question is what other cases can cause this other than rename table?



 Comments   
Comment by Marko Mäkelä [ 2022-07-29 ]

This seems to duplicate MDEV-29191.

Comment by Marko Mäkelä [ 2022-08-01 ]

allen.lee@mariadb.com, note that any operation that may rebuild the table may also update the create_time. Apart from ALTER TABLE and CREATE INDEX, these includes TRUNCATE and OPTIMIZE. Were any such statements executed?

Comment by Marko Mäkelä [ 2022-08-02 ]

Before this bug can be confirmed, the SQL statements for reproducing it must be provided, along with the exact version with which it was tested.

I can imagine that in some case of a table rebuild operation, update_time could be inherited from the old copy of the table. If the last operation on the table was such a rebuild (ALTER, OPTIMIZE, TRUNCATE), the create_time could be newer. Someone needs to provide the exact steps for reproducing this.

The update_time is not persisted anywhere by InnoDB. It only resides in the InnoDB data dictionary cache. It can disappear even from there if LRU eviction of the table definition takes place. On reload, I think it should be NULL.

Comment by Marko Mäkelä [ 2022-08-03 ]

I developed and debugged a test case of this on 10.6:

--source include/have_innodb.inc
create table t1(a int primary key)engine=innodb;
select create_time,update_time from information_schema.tables where table_name='t1';
insert into t1 set a=1;
select create_time,update_time from information_schema.tables where table_name='t1';
sleep 1;
alter table t1 rename to t2;
select create_time,update_time from information_schema.tables where table_name='t2';

I was under the impression that the create_time would be read from the .ibd file, but actually it is being read from the .frm file, which I suppose was rewritten by the ALTER TABLE t1 RENAME TO t2. Here is the relevant part from the ./mtr --rr trace:

10.6 212994f704496d01881f377e34e04bd007e5e298

#2  0x0000561c6e48d6b3 in os_file_get_status (
    path=0x7fd86e3f6cb0 "./test/t2.frm", stat_info=0x7fd86e3f6eb0, 
    check_rw_perm=false, read_only=false)
    at /mariadb/10.5/storage/innobase/os/os0file.cc:3494
#3  0x0000561c6e37b75f in ha_innobase::info_low (this=0x7fd86007d930, 
    flag=282, is_analyze=false)

If InnoDB read a creation timestamp from the .ibd file, it would not work for tables that are created in the system tablespace (innodb_file_per_table=0) or for temporary tables. Furthermore, after any operation that rebuilds the InnoDB tablespace (such as TRUNCATE or OPTIMIZE), a too new creation time
would be reported.

sanja or serg, does the .frm file store the original table creation file? If not, could it please be extended to store it? Ideally, storage engines would not have report any creation time to the SQL layer. They have a much better idea of update_time. After all, the SQL layer controls all DDL.

Generated at Thu Feb 08 10:06:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.