Skip to content

Commit 2b6f804

Browse files
committed
Merge 10.2 into 10.3
2 parents a8de8f2 + cc5f442 commit 2b6f804

24 files changed

+293
-283
lines changed

mysql-test/suite/innodb/r/instant_alter_crash.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ALTER TABLE t2 ADD COLUMN (c4 TEXT NOT NULL DEFAULT ' et malorum');
3838
connection default;
3939
SET DEBUG_SYNC='now WAIT_FOR ddl';
4040
SET GLOBAL innodb_flush_log_at_trx_commit=1;
41+
SET debug_dbug='+d,dict_sys_mutex_avoid';
4142
DELETE FROM t1;
4243
# Kill the server
4344
disconnect ddl;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# MDEV-23991 dict_table_stats_lock() has unnecessarily long scope
3+
#
4+
CREATE TABLE t1(a INT) ENGINE=INNODB STATS_PERSISTENT=1;
5+
SET DEBUG_SYNC='dict_stats_update_persistent SIGNAL stop WAIT_FOR go';
6+
ANALYZE TABLE t1;
7+
connect con1, localhost, root;
8+
SET DEBUG_SYNC='now WAIT_FOR stop';
9+
SELECT ENGINE,SUM(DATA_LENGTH+INDEX_LENGTH),COUNT(ENGINE),SUM(DATA_LENGTH),SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE ENGINE='InnoDB';
10+
ENGINE SUM(DATA_LENGTH+INDEX_LENGTH) COUNT(ENGINE) SUM(DATA_LENGTH) SUM(INDEX_LENGTH)
11+
InnoDB 114688 4 65536 49152
12+
SET DEBUG_SYNC='now SIGNAL go';
13+
disconnect con1;
14+
connection default;
15+
Table Op Msg_type Msg_text
16+
test.t1 analyze status OK
17+
SET DEBUG_SYNC= 'RESET';
18+
DROP TABLE t1;

mysql-test/suite/innodb/t/instant_alter_crash.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ALTER TABLE t2 ADD COLUMN (c4 TEXT NOT NULL DEFAULT ' et malorum');
5454
connection default;
5555
SET DEBUG_SYNC='now WAIT_FOR ddl';
5656
SET GLOBAL innodb_flush_log_at_trx_commit=1;
57+
SET debug_dbug='+d,dict_sys_mutex_avoid';
5758
DELETE FROM t1;
5859

5960
--source include/kill_mysqld.inc
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--source include/have_innodb.inc
2+
--source include/have_debug.inc
3+
--source include/have_debug_sync.inc
4+
--source include/count_sessions.inc
5+
6+
--echo #
7+
--echo # MDEV-23991 dict_table_stats_lock() has unnecessarily long scope
8+
--echo #
9+
CREATE TABLE t1(a INT) ENGINE=INNODB STATS_PERSISTENT=1;
10+
11+
SET DEBUG_SYNC='dict_stats_update_persistent SIGNAL stop WAIT_FOR go';
12+
--send ANALYZE TABLE t1
13+
14+
--connect(con1, localhost, root)
15+
SET DEBUG_SYNC='now WAIT_FOR stop';
16+
17+
SELECT ENGINE,SUM(DATA_LENGTH+INDEX_LENGTH),COUNT(ENGINE),SUM(DATA_LENGTH),SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE ENGINE='InnoDB';
18+
19+
SET DEBUG_SYNC='now SIGNAL go';
20+
--disconnect con1
21+
22+
--connection default
23+
--reap
24+
SET DEBUG_SYNC= 'RESET';
25+
DROP TABLE t1;
26+
27+
--source include/wait_until_count_sessions.inc

storage/innobase/btr/btr0btr.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ the index.
284284
ulint
285285
btr_height_get(
286286
/*===========*/
287-
dict_index_t* index, /*!< in: index tree */
287+
const dict_index_t* index, /*!< in: index tree */
288288
mtr_t* mtr) /*!< in/out: mini-transaction */
289289
{
290290
ulint height=0;
@@ -591,7 +591,7 @@ Gets the number of pages in a B-tree.
591591
ulint
592592
btr_get_size(
593593
/*=========*/
594-
dict_index_t* index, /*!< in: index */
594+
const dict_index_t* index, /*!< in: index */
595595
ulint flag, /*!< in: BTR_N_LEAF_PAGES or BTR_TOTAL_SIZE */
596596
mtr_t* mtr) /*!< in/out: mini-transaction where index
597597
is s-latched */

storage/innobase/btr/btr0cur.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6558,21 +6558,19 @@ btr_record_not_null_field_in_rec(
65586558
}
65596559
}
65606560

6561-
/*******************************************************************//**
6562-
Estimates the number of different key values in a given index, for
6561+
/** Estimates the number of different key values in a given index, for
65636562
each n-column prefix of the index where 1 <= n <= dict_index_get_n_unique(index).
65646563
The estimates are stored in the array index->stat_n_diff_key_vals[] (indexed
65656564
0..n_uniq-1) and the number of pages that were sampled is saved in
6566-
index->stat_n_sample_sizes[].
6565+
result.n_sample_sizes[].
65676566
If innodb_stats_method is nulls_ignored, we also record the number of
65686567
non-null values for each prefix and stored the estimates in
6569-
array index->stat_n_non_null_key_vals.
6570-
@return true if the index is available and we get the estimated numbers,
6571-
false if the index is unavailable. */
6572-
bool
6573-
btr_estimate_number_of_different_key_vals(
6574-
/*======================================*/
6575-
dict_index_t* index) /*!< in: index */
6568+
array result.n_non_null_key_vals.
6569+
@param[in] index index
6570+
@return vector with statistics information
6571+
empty vector if the index is unavailable. */
6572+
std::vector<index_field_stats_t>
6573+
btr_estimate_number_of_different_key_vals(dict_index_t* index)
65766574
{
65776575
btr_cur_t cursor;
65786576
page_t* page;
@@ -6592,11 +6590,11 @@ btr_estimate_number_of_different_key_vals(
65926590
rec_offs* offsets_rec = NULL;
65936591
rec_offs* offsets_next_rec = NULL;
65946592

6593+
std::vector<index_field_stats_t> result;
6594+
65956595
/* For spatial index, there is no such stats can be
65966596
fetched. */
6597-
if (dict_index_is_spatial(index)) {
6598-
return(false);
6599-
}
6597+
ut_ad(!dict_index_is_spatial(index));
66006598

66016599
n_cols = dict_index_get_n_unique(index);
66026600

@@ -6705,7 +6703,7 @@ btr_estimate_number_of_different_key_vals(
67056703
mtr_commit(&mtr);
67066704
mem_heap_free(heap);
67076705

6708-
return(false);
6706+
return result;
67096707
}
67106708

67116709
/* Count the number of different key values for each prefix of
@@ -6811,8 +6809,12 @@ btr_estimate_number_of_different_key_vals(
68116809
also the pages used for external storage of fields (those pages are
68126810
included in index->stat_n_leaf_pages) */
68136811

6812+
result.reserve(n_cols);
6813+
68146814
for (j = 0; j < n_cols; j++) {
6815-
index->stat_n_diff_key_vals[j]
6815+
index_field_stats_t stat;
6816+
6817+
stat.n_diff_key_vals
68166818
= BTR_TABLE_STATS_FROM_SAMPLE(
68176819
n_diff[j], index, n_sample_pages,
68186820
total_external_size, not_empty_flag);
@@ -6833,25 +6835,23 @@ btr_estimate_number_of_different_key_vals(
68336835
add_on = n_sample_pages;
68346836
}
68356837

6836-
index->stat_n_diff_key_vals[j] += add_on;
6838+
stat.n_diff_key_vals += add_on;
68376839

6838-
index->stat_n_sample_sizes[j] = n_sample_pages;
6840+
stat.n_sample_sizes = n_sample_pages;
68396841

6840-
/* Update the stat_n_non_null_key_vals[] with our
6841-
sampled result. stat_n_non_null_key_vals[] is created
6842-
and initialized to zero in dict_index_add_to_cache(),
6843-
along with stat_n_diff_key_vals[] array */
68446842
if (n_not_null != NULL) {
6845-
index->stat_n_non_null_key_vals[j] =
6843+
stat.n_non_null_key_vals =
68466844
BTR_TABLE_STATS_FROM_SAMPLE(
68476845
n_not_null[j], index, n_sample_pages,
68486846
total_external_size, not_empty_flag);
68496847
}
6848+
6849+
result.push_back(stat);
68506850
}
68516851

68526852
mem_heap_free(heap);
68536853

6854-
return(true);
6854+
return result;
68556855
}
68566856

68576857
/*================== EXTERNAL STORAGE OF BIG FIELDS ===================*/

storage/innobase/dict/dict0dict.cc

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -262,56 +262,6 @@ dict_mutex_exit_for_mysql(void)
262262
mutex_exit(&dict_sys->mutex);
263263
}
264264

265-
/** Lock the appropriate latch to protect a given table's statistics.
266-
@param[in] table table whose stats to lock
267-
@param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
268-
void
269-
dict_table_stats_lock(
270-
dict_table_t* table,
271-
ulint latch_mode)
272-
{
273-
ut_ad(table != NULL);
274-
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
275-
276-
switch (latch_mode) {
277-
case RW_S_LATCH:
278-
rw_lock_s_lock(&table->stats_latch);
279-
break;
280-
case RW_X_LATCH:
281-
rw_lock_x_lock(&table->stats_latch);
282-
break;
283-
case RW_NO_LATCH:
284-
/* fall through */
285-
default:
286-
ut_error;
287-
}
288-
}
289-
290-
/** Unlock the latch that has been locked by dict_table_stats_lock().
291-
@param[in] table table whose stats to unlock
292-
@param[in] latch_mode RW_S_LATCH or RW_X_LATCH */
293-
void
294-
dict_table_stats_unlock(
295-
dict_table_t* table,
296-
ulint latch_mode)
297-
{
298-
ut_ad(table != NULL);
299-
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
300-
301-
switch (latch_mode) {
302-
case RW_S_LATCH:
303-
rw_lock_s_unlock(&table->stats_latch);
304-
break;
305-
case RW_X_LATCH:
306-
rw_lock_x_unlock(&table->stats_latch);
307-
break;
308-
case RW_NO_LATCH:
309-
/* fall through */
310-
default:
311-
ut_error;
312-
}
313-
}
314-
315265
/**********************************************************************//**
316266
Try to drop any indexes after an aborted index creation.
317267
This can also be after a server kill during DROP INDEX. */

storage/innobase/dict/dict0mem.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ operator<<(
122122
@param n_v_cols number of virtual columns
123123
@param flags table flags
124124
@param flags2 table flags2
125-
@param init_stats_latch whether to init the stats latch
126125
@return own: table object */
127126
dict_table_t*
128127
dict_mem_table_create(
@@ -131,8 +130,7 @@ dict_mem_table_create(
131130
ulint n_cols,
132131
ulint n_v_cols,
133132
ulint flags,
134-
ulint flags2,
135-
bool init_stats_latch)
133+
ulint flags2)
136134
{
137135
dict_table_t* table;
138136
mem_heap_t* heap;
@@ -193,12 +191,6 @@ dict_mem_table_create(
193191
new(&table->foreign_set) dict_foreign_set();
194192
new(&table->referenced_set) dict_foreign_set();
195193

196-
if (init_stats_latch) {
197-
rw_lock_create(dict_table_stats_key, &table->stats_latch,
198-
SYNC_INDEX_TREE);
199-
table->stats_latch_inited = true;
200-
}
201-
202194
return(table);
203195
}
204196

@@ -248,10 +240,6 @@ dict_mem_table_free(
248240
UT_DELETE(table->s_cols);
249241
}
250242

251-
if (table->stats_latch_inited) {
252-
rw_lock_free(&table->stats_latch);
253-
}
254-
255243
mem_heap_free(table->heap);
256244
}
257245

0 commit comments

Comments
 (0)