[Commits] 97ba043: MDEV-8297: information_schema.innodb_sys_tablestats.modified_counter doesn't change on UPDATE

Jan Lindström jan.lindstrom at mariadb.com
Tue Dec 15 11:28:02 EET 2015


revision-id: 97ba0434fb5605deb3aeaa64cfa2dddfacf1048e (mariadb-10.0.22-62-g97ba043)
parent(s): b63bf7368b4881789bef931f90d4719b358cf507
committer: Jan Lindström
timestamp: 2015-12-15 11:27:08 +0200
message:

MDEV-8297: information_schema.innodb_sys_tablestats.modified_counter doesn't change on UPDATE

Update modified-counter also if update effects non-indexed columns.

---
 .../innodb/r/innodb-stats-modified-counter.result  | 20 ++++++++++++++++
 .../innodb/t/innodb-stats-modified-counter.opt     |  1 +
 .../innodb/t/innodb-stats-modified-counter.test    | 28 ++++++++++++++++++++++
 storage/innobase/row/row0mysql.cc                  |  6 +++++
 storage/xtradb/row/row0mysql.cc                    |  6 +++++
 5 files changed, 61 insertions(+)

diff --git a/mysql-test/suite/innodb/r/innodb-stats-modified-counter.result b/mysql-test/suite/innodb/r/innodb-stats-modified-counter.result
new file mode 100644
index 0000000..db56c6b
--- /dev/null
+++ b/mysql-test/suite/innodb/r/innodb-stats-modified-counter.result
@@ -0,0 +1,20 @@
+set global innodb_stats_auto_recalc=off;
+CREATE TABLE t1 (i int) ENGINE=InnoDB;
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+NAME	STATS_INITIALIZED	NUM_ROWS	MODIFIED_COUNTER
+test/t1	Initialized	0	0
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+NAME	STATS_INITIALIZED	NUM_ROWS	MODIFIED_COUNTER
+test/t1	Initialized	2	2
+DELETE FROM t1 WHERE i = 1;
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+NAME	STATS_INITIALIZED	NUM_ROWS	MODIFIED_COUNTER
+test/t1	Initialized	1	3
+UPDATE t1 SET i = 4 WHERE i = 2;
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+NAME	STATS_INITIALIZED	NUM_ROWS	MODIFIED_COUNTER
+test/t1	Initialized	1	4
+DROP TABLE t1;
+set global innodb_stats_auto_recalc=default;
diff --git a/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt
new file mode 100644
index 0000000..3e5b41c
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.opt
@@ -0,0 +1 @@
+--loose-innodb-sys-tablestats
diff --git a/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test
new file mode 100644
index 0000000..b3e4500
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb-stats-modified-counter.test
@@ -0,0 +1,28 @@
+-- source include/have_innodb.inc
+
+#
+# MDEV-8297: information_schema.innodb_sys_tablestats.modified_counter doesn't change on UPDATE
+#
+
+set global innodb_stats_auto_recalc=off;
+
+CREATE TABLE t1 (i int) ENGINE=InnoDB;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+DELETE FROM t1 WHERE i = 1;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+UPDATE t1 SET i = 4 WHERE i = 2;
+
+SELECT NAME, STATS_INITIALIZED, NUM_ROWS, MODIFIED_COUNTER FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1';
+
+DROP TABLE t1;
+
+set global innodb_stats_auto_recalc=default;
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index 6184bcd..db82973 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -1861,6 +1861,12 @@ row_update_for_mysql(
 	columns would not affect statistics. */
 	if (node->is_delete || !(node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
 		row_update_statistics_if_needed(prebuilt->table);
+	} else {
+		/* Update the table modification counter even when
+		non-indexed columns change if statistics is initialized. */
+		if (prebuilt->table->stat_initialized) {
+			prebuilt->table->stat_modified_counter++;
+		}
 	}
 
 	trx->op_info = "";
diff --git a/storage/xtradb/row/row0mysql.cc b/storage/xtradb/row/row0mysql.cc
index e7d1e91..6bb5a61 100644
--- a/storage/xtradb/row/row0mysql.cc
+++ b/storage/xtradb/row/row0mysql.cc
@@ -1870,6 +1870,12 @@ row_update_for_mysql(
 	columns would not affect statistics. */
 	if (node->is_delete || !(node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
 		row_update_statistics_if_needed(prebuilt->table);
+	} else {
+		/* Update the table modification counter even when
+		non-indexed columns change if statistics is initialized. */
+		if (prebuilt->table->stat_initialized) {
+			prebuilt->table->stat_modified_counter++;
+		}
 	}
 
 	trx->op_info = "";


More information about the commits mailing list