Skip to content

Commit 6968637

Browse files
committed
MDEV-34782 SIGSEGV in handler::update_global_table_stats in close_thread_table()
Handler statistics did not take into account that it could not be fully initialized in the table.
1 parent 875d8c9 commit 6968637

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

mysql-test/main/userstat.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,17 @@ test t1 a 8 1
287287
drop table t1;
288288
set global userstat=@save_userstat;
289289
# End of 11.5 tests
290+
#
291+
# MDEV-34782 SIGSEGV in handler::update_global_table_stats in
292+
# close_thread_table()
293+
#
294+
CREATE TABLE t1 (a CHAR(1));
295+
HANDLER t1 OPEN;
296+
INSERT INTO t1 VALUES (1);
297+
HANDLER t1 READ NEXT;
298+
a
299+
1
300+
SET GLOBAL userstat=1;
301+
HANDLER t1 close;
302+
drop table t1;
303+
SET GLOBAL userstat=@save_userstat;

mysql-test/main/userstat.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,17 @@ drop table t1;
162162
set global userstat=@save_userstat;
163163

164164
--echo # End of 11.5 tests
165+
166+
--echo #
167+
--echo # MDEV-34782 SIGSEGV in handler::update_global_table_stats in
168+
--echo # close_thread_table()
169+
--echo #
170+
171+
CREATE TABLE t1 (a CHAR(1));
172+
HANDLER t1 OPEN;
173+
INSERT INTO t1 VALUES (1);
174+
HANDLER t1 READ NEXT;
175+
SET GLOBAL userstat=1;
176+
HANDLER t1 close;
177+
drop table t1;
178+
SET GLOBAL userstat=@save_userstat;

sql/handler.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6106,8 +6106,11 @@ void handler::update_global_table_stats()
61066106
table_stats->rows_stats.deleted+= rows_stats.deleted;
61076107
table_stats->rows_stats.key_read_hit+= rows_stats.key_read_hit;
61086108
table_stats->rows_stats.key_read_miss+= rows_stats.key_read_miss;
6109-
table_stats->rows_stats.pages_accessed+= handler_stats->pages_accessed;
6110-
table_stats->rows_stats.pages_read_count+= handler_stats->pages_read_count;
6109+
if (handler_stats)
6110+
{
6111+
table_stats->rows_stats.pages_accessed+= handler_stats->pages_accessed;
6112+
table_stats->rows_stats.pages_read_count+= handler_stats->pages_read_count;
6113+
}
61116114
changed= rows_stats.updated + rows_stats.inserted + rows_stats.deleted;
61126115
table_stats->rows_changed_x_indexes+= (changed *
61136116
(table->s->keys ? table->s->keys :

0 commit comments

Comments
 (0)