Skip to content

Commit 4bec40d

Browse files
author
Aditya A
committed
Bug #25080442 PARTITIONED TABLES USE MORE MEMORY IN 5.7 THAN 5.6
Merge branch 'mysql-5.7' into mysql-trunk
2 parents 924deba + 906f7fa commit 4bec40d

File tree

9 files changed

+76
-42
lines changed

9 files changed

+76
-42
lines changed

storage/innobase/handler/ha_innodb.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9078,7 +9078,9 @@ ha_innobase::index_end(void)
90789078
{
90799079
DBUG_ENTER("index_end");
90809080

9081-
m_prebuilt->index->last_sel_cur->release();
9081+
if(m_prebuilt->index->last_sel_cur) {
9082+
m_prebuilt->index->last_sel_cur->release();
9083+
}
90829084

90839085
active_index = MAX_KEY;
90849086

@@ -13423,8 +13425,11 @@ ha_innobase::delete_table(
1342313425

1342413426
if (handler != NULL) {
1342513427
for (dict_index_t* index = UT_LIST_GET_FIRST(handler->indexes);
13426-
index != NULL;
13428+
index != NULL && index->last_ins_cur;
1342713429
index = UT_LIST_GET_NEXT(indexes, index)) {
13430+
/* last_ins_cur and last_sel_cur are allocated
13431+
together,therfore only checking last_ins_cur
13432+
before releasing mtr */
1342813433
index->last_ins_cur->release();
1342913434
index->last_sel_cur->release();
1343013435
}

storage/innobase/include/dict0dict.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2012, Facebook Inc.
55
66
This program is free software; you can redistribute it and/or modify it under
@@ -1966,6 +1966,12 @@ uint32_t
19661966
dict_sdi_get_copy_num(
19671967
table_id_t table_id);
19681968

1969+
/** Allocate memory for intrinsic cache elements in the index
1970+
* @param[in] index index object */
1971+
UNIV_INLINE
1972+
void
1973+
dict_allocate_mem_intrinsic_cache(
1974+
dict_index_t* index);
19691975
#endif /* !UNIV_HOTBACKUP */
19701976

19711977
#include "dict0dict.ic"

storage/innobase/include/dict0dict.ic

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22

3-
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44

55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -1534,6 +1534,26 @@ dict_table_have_virtual_index(
15341534

15351535
return(false);
15361536
}
1537+
/** Allocate memory for intrinsic cache elements in the index
1538+
@param[in] index index object */
1539+
UNIV_INLINE
1540+
void
1541+
dict_allocate_mem_intrinsic_cache(
1542+
dict_index_t* index)
1543+
{
1544+
1545+
index->last_ins_cur =
1546+
static_cast<last_ops_cur_t*>(mem_heap_alloc(
1547+
index->heap, sizeof(last_ops_cur_t)));
1548+
1549+
new (index->last_ins_cur) last_ops_cur_t();
1550+
1551+
index->last_sel_cur =
1552+
static_cast<last_ops_cur_t*>(mem_heap_alloc(
1553+
index->heap, sizeof(last_ops_cur_t)));
1554+
1555+
new (index->last_sel_cur) last_ops_cur_t();
1556+
}
15371557

15381558
/** Generate a table_id from space id for SDI Index.
15391559
@param[in] space_id InnoDB tablespace id

storage/innobase/include/dict0mem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,6 @@ class last_ops_cur_t
919919
system clustered index when there is no primary key. */
920920
const char innobase_index_reserve_name[] = "GEN_CLUST_INDEX";
921921

922-
/* Estimated number of offsets in records (based on columns)
923-
to start with. */
924-
#define OFFS_IN_REC_NORMAL_SIZE 100
925-
926922
/** Data structure for an index. Most fields will be
927923
initialized to 0, NULL or FALSE in dict_mem_index_create(). */
928924
struct dict_index_t{

storage/innobase/include/dict0mem.ic

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22

3-
Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44

55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -72,33 +72,10 @@ dict_mem_fill_index_struct(
7272
index->allow_duplicates = false;
7373
index->nulls_equal = false;
7474
index->disable_ahi = false;
75-
75+
index->last_ins_cur = nullptr;
76+
index->last_sel_cur = nullptr;
7677
new (&index->rec_cache) rec_cache_t();
7778

78-
if (heap != NULL) {
79-
index->last_ins_cur =
80-
static_cast<last_ops_cur_t*>(mem_heap_alloc(
81-
heap, sizeof(last_ops_cur_t)));
82-
83-
new (index->last_ins_cur) last_ops_cur_t();
84-
85-
index->last_sel_cur =
86-
static_cast<last_ops_cur_t*>(mem_heap_alloc(
87-
heap, sizeof(last_ops_cur_t)));
88-
89-
new (index->last_sel_cur) last_ops_cur_t();
90-
91-
index->rec_cache.offsets =
92-
static_cast<ulint*>(mem_heap_alloc(
93-
heap, sizeof(ulint) * OFFS_IN_REC_NORMAL_SIZE));
94-
95-
index->rec_cache.sz_of_offsets = OFFS_IN_REC_NORMAL_SIZE;
96-
} else {
97-
index->last_ins_cur = NULL;
98-
index->last_sel_cur = NULL;
99-
index->rec_cache.offsets = NULL;
100-
}
101-
10279
#ifdef UNIV_DEBUG
10380
index->magic_n = DICT_INDEX_MAGIC_N;
10481
#endif /* UNIV_DEBUG */

storage/innobase/rem/rec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ significant bit denotes that the tail of a field is stored off-page. */
150150

151151
/* Number of elements that should be initially allocated for the
152152
offsets[] array, first passed to rec_get_offsets() */
153-
#define REC_OFFS_NORMAL_SIZE OFFS_IN_REC_NORMAL_SIZE
153+
#define REC_OFFS_NORMAL_SIZE 100
154154
#define REC_OFFS_SMALL_SIZE 10
155155

156156
/* Get the base address of offsets. The extra_size is stored at

storage/innobase/row/row0ins.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,9 @@ row_ins_clust_index_entry_low(
27492749
doesn't fit the provided slot then existing record is added
27502750
to free list and new record is inserted. This also means
27512751
cursor that we have cached for SELECT is now invalid. */
2752-
index->last_sel_cur->invalid = true;
2752+
if(index->last_sel_cur) {
2753+
index->last_sel_cur->invalid = true;
2754+
}
27532755

27542756
ut_ad(thr != NULL);
27552757
err = row_ins_clust_index_entry_by_modify(
@@ -3315,7 +3317,9 @@ row_ins_sec_index_entry_low(
33153317
is doesn't fit the provided slot then existing record is added
33163318
to free list and new record is inserted. This also means
33173319
cursor that we have cached for SELECT is now invalid. */
3318-
index->last_sel_cur->invalid = true;
3320+
if(index->last_sel_cur) {
3321+
index->last_sel_cur->invalid = true;
3322+
}
33193323

33203324
/* There is already an index entry with a long enough common
33213325
prefix, we must convert the insert into a modify of an
@@ -3448,6 +3452,10 @@ row_ins_clust_index_entry(
34483452

34493453
if (index->table->is_intrinsic()
34503454
&& dict_index_is_auto_gen_clust(index)) {
3455+
/* Check if the memory allocated for intrinsic cache*/
3456+
if(!index->last_ins_cur) {
3457+
dict_allocate_mem_intrinsic_cache(index);
3458+
}
34513459
err = row_ins_sorted_clust_index_entry(
34523460
BTR_MODIFY_LEAF, index, entry, n_ext, thr);
34533461
} else {
@@ -3468,6 +3476,9 @@ row_ins_clust_index_entry(
34683476
/* Try then pessimistic descent to the B-tree */
34693477
if (!index->table->is_intrinsic()) {
34703478
log_free_check();
3479+
} else if(!index->last_sel_cur) {
3480+
dict_allocate_mem_intrinsic_cache(index);
3481+
index->last_sel_cur->invalid = true;
34713482
} else {
34723483
index->last_sel_cur->invalid = true;
34733484
}
@@ -3555,6 +3566,9 @@ row_ins_sec_index_entry(
35553566

35563567
if (!index->table->is_intrinsic()) {
35573568
log_free_check();
3569+
} else if(!index->last_sel_cur) {
3570+
dict_allocate_mem_intrinsic_cache(index);
3571+
index->last_sel_cur->invalid = true;
35583572
} else {
35593573
index->last_sel_cur->invalid = true;
35603574
}

storage/innobase/row/row0mysql.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,9 @@ row_update_for_mysql_using_cursor(
22762276
node->upd_ext ? node->upd_ext->n_ext : 0,
22772277
false);
22782278
/* Commit the open mtr as we are processing UPDATE. */
2279-
index->last_ins_cur->release();
2279+
if (index->last_ins_cur) {
2280+
index->last_ins_cur->release();
2281+
}
22802282
} else {
22812283
err = row_ins_sec_index_entry(index, entry, thr, false);
22822284
}
@@ -2320,7 +2322,10 @@ row_del_upd_for_mysql_using_cursor(
23202322
to change. */
23212323
thr = que_fork_get_first_thr(prebuilt->upd_graph);
23222324
clust_index = prebuilt->table->first_index();
2323-
clust_index->last_ins_cur->release();
2325+
2326+
if(clust_index->last_ins_cur) {
2327+
clust_index->last_ins_cur->release();
2328+
}
23242329

23252330
/* Step-1: Select the appropriate cursor that will help build
23262331
the original row and updated row. */
@@ -2721,9 +2726,14 @@ row_delete_all_rows(
27212726
dict_table_t* table)
27222727
{
27232728
ut_ad(table->is_temporary());
2729+
dict_index_t* index;
2730+
2731+
index = table->first_index();
27242732
/* Step-0: If there is cached insert position along with mtr
27252733
commit it before starting delete/update action. */
2726-
table->first_index()->last_ins_cur->release();
2734+
if (index->last_ins_cur) {
2735+
index->last_ins_cur->release();
2736+
}
27272737

27282738
bool found;
27292739
const page_size_t page_size(
@@ -2733,7 +2743,7 @@ row_delete_all_rows(
27332743
/* Step-1: Now truncate all the indexes and re-create them.
27342744
Note: This is ddl action even though delete all rows is
27352745
DML action. Any error during this action is ir-reversible. */
2736-
for (dict_index_t* index = UT_LIST_GET_FIRST(table->indexes);
2746+
for (index = UT_LIST_GET_FIRST(table->indexes);
27372747
index != NULL;
27382748
index = UT_LIST_GET_NEXT(indexes, index)) {
27392749

storage/innobase/row/row0sel.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4238,9 +4238,15 @@ row_search_no_mvcc(
42384238
ut_ad(index && pcur && search_tuple);
42394239

42404240
/* Step-0: Re-use the cached mtr. */
4241-
mtr_t* mtr = &index->last_sel_cur->mtr;
4241+
mtr_t* mtr;
42424242
dict_index_t* clust_index = index->table->first_index();
42434243

4244+
if(!index->last_sel_cur) {
4245+
dict_allocate_mem_intrinsic_cache(index);
4246+
}
4247+
4248+
mtr = &index->last_sel_cur->mtr;
4249+
42444250
/* Step-1: Build the select graph. */
42454251
if (direction == 0 && prebuilt->sel_graph == NULL) {
42464252
row_prebuild_sel_graph(prebuilt);

0 commit comments

Comments
 (0)