Skip to content

Commit 106c785

Browse files
committed
MDEV-26911: Unexpected ER_DUP_KEY, ASAN errors, double free detected in ...
When loading the histogram, use table->field[N], not table->s->field[N]. When we used the latter we would corrupt the fields's default value. One of the consequences of that would be that AUTO_INCREMENT fields would stop working correctly.
1 parent ac0194b commit 106c785

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

mysql-test/main/statistics_json.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7645,3 +7645,16 @@ a
76457645
foo
76467646
?
76477647
drop table t1;
7648+
#
7649+
# MDEV-26911: Unexpected ER_DUP_KEY, ASAN errors, double free detected in tcache with JSON_HB histogram
7650+
#
7651+
SET histogram_type= JSON_HB;
7652+
CREATE TABLE t1 (pk INT AUTO_INCREMENT, f VARCHAR(8), PRIMARY KEY (pk));
7653+
INSERT INTO t1 (f) VALUES ('foo');
7654+
ANALYZE TABLE t1 PERSISTENT FOR ALL;
7655+
Table Op Msg_type Msg_text
7656+
test.t1 analyze status Engine-independent statistics collected
7657+
test.t1 analyze status OK
7658+
ALTER TABLE t1 MODIFY f TEXT, ORDER BY pk;
7659+
INSERT INTO t1 (f) VALUES ('bar');
7660+
DROP TABLE t1;

mysql-test/main/statistics_json.test

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
let $histogram_type_override='JSON_HB';
66
--source statistics.test
77

8+
--source include/have_innodb.inc
89
--source include/have_stat_tables.inc
910
--source include/have_sequence.inc
1011
--source include/analyze-format.inc
@@ -325,5 +326,17 @@ insert into t1 values ('foo'),(unhex('9C'));
325326
analyze table t1 persistent for all;
326327

327328
select * from t1;
328-
329329
drop table t1;
330+
331+
--echo #
332+
--echo # MDEV-26911: Unexpected ER_DUP_KEY, ASAN errors, double free detected in tcache with JSON_HB histogram
333+
--echo #
334+
335+
SET histogram_type= JSON_HB;
336+
337+
CREATE TABLE t1 (pk INT AUTO_INCREMENT, f VARCHAR(8), PRIMARY KEY (pk));
338+
INSERT INTO t1 (f) VALUES ('foo');
339+
ANALYZE TABLE t1 PERSISTENT FOR ALL;
340+
ALTER TABLE t1 MODIFY f TEXT, ORDER BY pk;
341+
INSERT INTO t1 (f) VALUES ('bar');
342+
DROP TABLE t1;

sql/sql_statistics.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,8 @@ class Column_stat: public Stat_table
12321232
Histogram_base *hist;
12331233
if (!(hist= create_histogram(mem_root, hist_type, NULL)))
12341234
return NULL;
1235-
if (!hist->parse(mem_root, table_field, hist_type,
1235+
Field *field= table->field[table_field->field_index];
1236+
if (!hist->parse(mem_root, field, hist_type,
12361237
val.ptr(), val.length()))
12371238
{
12381239
table_field->read_stats->histogram= hist;
@@ -3178,6 +3179,14 @@ int read_histograms_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
31783179
if (stats_cb->start_histograms_load())
31793180
{
31803181
Column_stat column_stat(stat_tables[COLUMN_STAT].table, table);
3182+
3183+
/*
3184+
The process of histogram loading makes use of the field it is for. Mark
3185+
all fields as readable/writable in order to allow that.
3186+
*/
3187+
MY_BITMAP *old_sets[2];
3188+
dbug_tmp_use_all_columns(table, old_sets, &table->read_set, &table->write_set);
3189+
31813190
for (Field **field_ptr= table->s->field; *field_ptr; field_ptr++)
31823191
{
31833192
Field *table_field= *field_ptr;
@@ -3189,6 +3198,8 @@ int read_histograms_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
31893198
}
31903199
}
31913200
stats_cb->end_histograms_load();
3201+
3202+
dbug_tmp_restore_column_maps(&table->read_set, &table->write_set, old_sets);
31923203
}
31933204
table->histograms_are_read= true;
31943205
DBUG_RETURN(0);

0 commit comments

Comments
 (0)