Skip to content

Commit 232d8bb

Browse files
author
aditya
committed
Bug #17299181 CREATE_TIME AND UPDATE_TIME ARE WRONG FOR PARTITIONED TABLES
PROBLEM Create time is calculated as last status change time of .frm file. The first problem was that innodb was passing file name as "table_name#po#p0.frm" to the stat() call which calculates the create time. Since there is no frm file with this name create_time will be stored as NULL. The second problem is ha_partition::info() updates stats for create time when HA_STATUS_CONST flag was set ,where as innodb calculates this statistic when HA_STATUS_TIME is set,which causes create_time to be set as NULL. Fix Pass proper .frm name to stat() call and calculate create time when HA_STATUS_CONST flag is set.
1 parent c01d13b commit 232d8bb

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

mysql-test/r/partition_innodb.result

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,33 +365,33 @@ DROP TABLE t1;
365365
create table t1 (a int) engine=innodb partition by hash(a) ;
366366
show table status like 't1';
367367
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
368-
t1 InnoDB 10 Compact 2 8192 16384 0 0 # NULL NULL NULL NULL latin1_swedish_ci NULL partitioned
368+
t1 InnoDB 10 Compact 2 8192 16384 0 0 # NULL # NULL NULL latin1_swedish_ci NULL partitioned
369369
drop table t1;
370370
create table t1 (a int)
371371
engine = innodb
372372
partition by key (a);
373373
show table status;
374374
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
375-
t1 InnoDB 10 Compact 2 8192 16384 0 0 # NULL NULL NULL NULL latin1_swedish_ci NULL partitioned
375+
t1 InnoDB 10 Compact 2 8192 16384 0 0 # NULL # NULL NULL latin1_swedish_ci NULL partitioned
376376
insert into t1 values (0), (1), (2), (3);
377377
show table status;
378378
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
379-
t1 InnoDB 10 Compact 4 4096 16384 0 0 # NULL NULL NULL NULL latin1_swedish_ci NULL partitioned
379+
t1 InnoDB 10 Compact 4 4096 16384 0 0 # NULL # NULL NULL latin1_swedish_ci NULL partitioned
380380
drop table t1;
381381
create table t1 (a int auto_increment primary key)
382382
engine = innodb
383383
partition by key (a);
384384
show table status;
385385
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
386-
t1 InnoDB 10 Compact 2 8192 16384 0 0 # 1 NULL NULL NULL latin1_swedish_ci NULL partitioned
386+
t1 InnoDB 10 Compact 2 8192 16384 0 0 # 1 # NULL NULL latin1_swedish_ci NULL partitioned
387387
insert into t1 values (NULL), (NULL), (NULL), (NULL);
388388
show table status;
389389
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
390-
t1 InnoDB 10 Compact 4 4096 16384 0 0 # 5 NULL NULL NULL latin1_swedish_ci NULL partitioned
390+
t1 InnoDB 10 Compact 4 4096 16384 0 0 # 5 # NULL NULL latin1_swedish_ci NULL partitioned
391391
insert into t1 values (NULL), (NULL), (NULL), (NULL);
392392
show table status;
393393
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
394-
t1 InnoDB 10 Compact 8 2048 16384 0 0 # 9 NULL NULL NULL latin1_swedish_ci NULL partitioned
394+
t1 InnoDB 10 Compact 8 2048 16384 0 0 # 9 # NULL NULL latin1_swedish_ci NULL partitioned
395395
drop table t1;
396396
create table t1 (a int)
397397
partition by key (a)
@@ -572,3 +572,14 @@ a b
572572
1 2
573573
0 1
574574
DROP TABLE t1;
575+
#
576+
# Bug #17299181 CREATE_TIME AND UPDATE_TIME ARE
577+
# WRONG FOR PARTITIONED TABLES
578+
#
579+
CREATE TABLE t1 (a int, PRIMARY KEY (a)) ENGINE=InnoDB
580+
PARTITION BY HASH (a) PARTITIONS 2;
581+
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE
582+
CREATE_TIME IS NOT NULL AND TABLE_NAME='t1';
583+
COUNT(*)
584+
1
585+
DROP TABLE t1;

mysql-test/t/partition_innodb.test

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ DROP TABLE t1;
387387
create table t1 (a int) engine=innodb partition by hash(a) ;
388388
# Data_free for InnoDB tablespace varies depending on which
389389
# tests have been run before this one
390-
--replace_column 10 #
390+
--replace_column 10 # 12 #
391391
show table status like 't1';
392392
drop table t1;
393393

@@ -399,12 +399,12 @@ engine = innodb
399399
partition by key (a);
400400
# Data_free for InnoDB tablespace varies depending on which
401401
# tests have been run before this one
402-
--replace_column 10 #
402+
--replace_column 10 # 12 #
403403
show table status;
404404
insert into t1 values (0), (1), (2), (3);
405405
# Data_free for InnoDB tablespace varies depending on which
406406
# tests have been run before this one
407-
--replace_column 10 #
407+
--replace_column 10 # 12 #
408408
show table status;
409409
drop table t1;
410410

@@ -413,17 +413,17 @@ engine = innodb
413413
partition by key (a);
414414
# Data_free for InnoDB tablespace varies depending on which
415415
# tests have been run before this one
416-
--replace_column 10 #
416+
--replace_column 10 # 12 #
417417
show table status;
418418
insert into t1 values (NULL), (NULL), (NULL), (NULL);
419419
# Data_free for InnoDB tablespace varies depending on which
420420
# tests have been run before this one
421-
--replace_column 10 #
421+
--replace_column 10 # 12 #
422422
show table status;
423423
insert into t1 values (NULL), (NULL), (NULL), (NULL);
424424
# Data_free for InnoDB tablespace varies depending on which
425425
# tests have been run before this one
426-
--replace_column 10 #
426+
--replace_column 10 # 12 #
427427
show table status;
428428
drop table t1;
429429

@@ -660,3 +660,15 @@ ALTER TABLE t1 ADD UNIQUE KEY (b);
660660
SHOW CREATE TABLE t1;
661661
SELECT * FROM t1;
662662
DROP TABLE t1;
663+
--echo #
664+
--echo # Bug #17299181 CREATE_TIME AND UPDATE_TIME ARE
665+
--echo # WRONG FOR PARTITIONED TABLES
666+
--echo #
667+
668+
CREATE TABLE t1 (a int, PRIMARY KEY (a)) ENGINE=InnoDB
669+
PARTITION BY HASH (a) PARTITIONS 2;
670+
671+
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE
672+
CREATE_TIME IS NOT NULL AND TABLE_NAME='t1';
673+
674+
DROP TABLE t1;

storage/innobase/handler/ha_innodb.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8172,17 +8172,6 @@ ha_innobase::info_low(
81728172
prebuilt->trx->op_info = "returning various info to MySQL";
81738173
}
81748174

8175-
my_snprintf(path, sizeof(path), "%s/%s%s",
8176-
mysql_data_home, ib_table->name, reg_ext);
8177-
8178-
unpack_filename(path,path);
8179-
8180-
/* Note that we do not know the access time of the table,
8181-
nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
8182-
8183-
if (os_file_get_status(path,&stat_info)) {
8184-
stats.create_time = (ulong) stat_info.ctime;
8185-
}
81868175
}
81878176

81888177
if (flag & HA_STATUS_VARIABLE) {
@@ -8379,6 +8368,20 @@ ha_innobase::info_low(
83798368
}
83808369

83818370
dict_table_stats_unlock(ib_table, RW_S_LATCH);
8371+
8372+
my_snprintf(path, sizeof(path), "%s/%s%s",
8373+
mysql_data_home,
8374+
table->s->normalized_path.str,
8375+
reg_ext);
8376+
8377+
unpack_filename(path,path);
8378+
8379+
/* Note that we do not know the access time of the table,
8380+
nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
8381+
8382+
if (os_file_get_status(path,&stat_info)) {
8383+
stats.create_time = (ulong) stat_info.ctime;
8384+
}
83828385
}
83838386

83848387
if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {

0 commit comments

Comments
 (0)