Skip to content

Commit 14471d9

Browse files
midenokdr-m
authored andcommitted
Minor InnoDB refactoring
ha_innobase_inplace_ctx::create_key_defs(): Replaces innobase_create_key_defs(). dict_index_t::contains_col_or_prefix(): Replaces dict_index_contains_col_or_prefix(). Closes #988
1 parent e827565 commit 14471d9

File tree

6 files changed

+82
-92
lines changed

6 files changed

+82
-92
lines changed

storage/innobase/dict/dict0dict.cc

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -905,47 +905,29 @@ dict_index_get_nth_col_or_prefix_pos(
905905
return(ULINT_UNDEFINED);
906906
}
907907

908-
/** Returns TRUE if the index contains a column or a prefix of that column.
909-
@param[in] index index
908+
/** Check if the index contains a column or a prefix of that column.
910909
@param[in] n column number
911910
@param[in] is_virtual whether it is a virtual col
912-
@return TRUE if contains the column or its prefix */
913-
bool
914-
dict_index_contains_col_or_prefix(
915-
const dict_index_t* index,
916-
ulint n,
917-
bool is_virtual)
911+
@return whether the index contains the column or its prefix */
912+
bool dict_index_t::contains_col_or_prefix(ulint n, bool is_virtual) const
918913
{
919-
const dict_field_t* field;
920-
const dict_col_t* col;
921-
ulint pos;
922-
ulint n_fields;
923-
924-
ut_ad(index);
925-
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
914+
ut_ad(magic_n == DICT_INDEX_MAGIC_N);
926915

927-
if (dict_index_is_clust(index)) {
916+
if (is_primary()) {
928917
return(!is_virtual);
929918
}
930919

931-
if (is_virtual) {
932-
col = &dict_table_get_nth_v_col(index->table, n)->m_col;
933-
} else {
934-
col = dict_table_get_nth_col(index->table, n);
935-
}
936-
937-
n_fields = dict_index_get_n_fields(index);
938-
939-
for (pos = 0; pos < n_fields; pos++) {
940-
field = dict_index_get_nth_field(index, pos);
941-
942-
if (col == field->col) {
920+
const dict_col_t* col = is_virtual
921+
? &dict_table_get_nth_v_col(table, n)->m_col
922+
: dict_table_get_nth_col(table, n);
943923

944-
return(true);
924+
for (ulint pos = 0; pos < n_fields; pos++) {
925+
if (col == fields[pos].col) {
926+
return true;
945927
}
946928
}
947929

948-
return(false);
930+
return false;
949931
}
950932

951933
/********************************************************************//**

storage/innobase/handler/ha_innodb.cc

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7256,19 +7256,19 @@ static
72567256
const Field*
72577257
build_template_needs_field(
72587258
/*=======================*/
7259-
ibool index_contains, /*!< in:
7260-
dict_index_contains_col_or_prefix(
7261-
index, i) */
7262-
ibool read_just_key, /*!< in: TRUE when MySQL calls
7259+
bool index_contains, /*!< in:
7260+
dict_index_t::contains_col_or_prefix(
7261+
i) */
7262+
bool read_just_key, /*!< in: TRUE when MySQL calls
72637263
ha_innobase::extra with the
72647264
argument HA_EXTRA_KEYREAD; it is enough
72657265
to read just columns defined in
72667266
the index (i.e., no read of the
72677267
clustered index record necessary) */
7268-
ibool fetch_all_in_key,
7268+
bool fetch_all_in_key,
72697269
/*!< in: true=fetch all fields in
72707270
the index */
7271-
ibool fetch_primary_key_cols,
7271+
bool fetch_primary_key_cols,
72727272
/*!< in: true=fetch the
72737273
primary key columns */
72747274
dict_index_t* index, /*!< in: InnoDB index to use */
@@ -7329,11 +7329,11 @@ build_template_needs_field_in_icp(
73297329
bool is_virtual)
73307330
/*!< in: a virtual column or not */
73317331
{
7332-
ut_ad(contains == dict_index_contains_col_or_prefix(index, i, is_virtual));
7332+
ut_ad(contains == index->contains_col_or_prefix(i, is_virtual));
73337333

73347334
return(index == prebuilt->index
73357335
? contains
7336-
: dict_index_contains_col_or_prefix(prebuilt->index, i, is_virtual));
7336+
: prebuilt->index->contains_col_or_prefix(i, is_virtual));
73377337
}
73387338

73397339
/**************************************************************//**
@@ -7609,9 +7609,8 @@ ha_innobase::build_template(
76097609
num_v++;
76107610
continue;
76117611
}
7612-
ibool index_contains
7613-
= dict_index_contains_col_or_prefix(
7614-
index, is_v ? num_v : i - num_v, is_v);
7612+
bool index_contains = index->contains_col_or_prefix(
7613+
is_v ? num_v : i - num_v, is_v);
76157614
if (is_v && index_contains) {
76167615
m_prebuilt->n_template = 0;
76177616
num_v = 0;
@@ -7750,9 +7749,8 @@ ha_innobase::build_template(
77507749
continue;
77517750
}
77527751

7753-
ibool index_contains
7754-
= dict_index_contains_col_or_prefix(
7755-
index, is_v ? num_v : i - num_v, is_v);
7752+
bool index_contains = index->contains_col_or_prefix(
7753+
is_v ? num_v : i - num_v, is_v);
77567754

77577755
if (!build_template_needs_field_in_icp(
77587756
index, m_prebuilt, index_contains,
@@ -7809,8 +7807,8 @@ ha_innobase::build_template(
78097807
cluster index. */
78107808
if (is_v
78117809
&& m_prebuilt->read_just_key
7812-
&& !dict_index_contains_col_or_prefix(
7813-
m_prebuilt->index, num_v, true))
7810+
&& !m_prebuilt->index->contains_col_or_prefix(
7811+
num_v, true))
78147812
{
78157813
/* Turn off ROW_MYSQL_WHOLE_ROW */
78167814
m_prebuilt->template_type =
@@ -7819,20 +7817,14 @@ ha_innobase::build_template(
78197817
continue;
78207818
}
78217819
} else {
7822-
ibool contain;
7823-
7824-
if (!is_v) {
7825-
contain = dict_index_contains_col_or_prefix(
7826-
index, i - num_v,
7827-
false);
7828-
} else if (dict_index_is_clust(index)) {
7820+
if (is_v && index->is_primary()) {
78297821
num_v++;
78307822
continue;
7831-
} else {
7832-
contain = dict_index_contains_col_or_prefix(
7833-
index, num_v, true);
78347823
}
78357824

7825+
bool contain = index->contains_col_or_prefix(
7826+
is_v ? num_v: i - num_v, is_v);
7827+
78367828
field = build_template_needs_field(
78377829
contain,
78387830
m_prebuilt->read_just_key,

storage/innobase/handler/handler0alter.cc

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,40 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
11011101
return instant_table;
11021102
}
11031103

1104+
/** Create an index table where indexes are ordered as follows:
1105+
1106+
IF a new primary key is defined for the table THEN
1107+
1108+
1) New primary key
1109+
2) The remaining keys in key_info
1110+
1111+
ELSE
1112+
1113+
1) All new indexes in the order they arrive from MySQL
1114+
1115+
ENDIF
1116+
1117+
@return key definitions */
1118+
MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
1119+
inline index_def_t*
1120+
create_key_defs(
1121+
const Alter_inplace_info* ha_alter_info,
1122+
/*!< in: alter operation */
1123+
const TABLE* altered_table,
1124+
/*!< in: MySQL table that is being altered */
1125+
ulint& n_fts_add,
1126+
/*!< out: number of FTS indexes to be created */
1127+
ulint& fts_doc_id_col,
1128+
/*!< in: The column number for Doc ID */
1129+
bool& add_fts_doc_id,
1130+
/*!< in: whether we need to add new DOC ID
1131+
column for FTS index */
1132+
bool& add_fts_doc_idx,
1133+
/*!< in: whether we need to add new DOC ID
1134+
index for FTS index */
1135+
const TABLE* table);
1136+
/*!< in: MySQL table that is being altered */
1137+
11041138
private:
11051139
// Disable copying
11061140
ha_innobase_inplace_ctx(const ha_innobase_inplace_ctx&);
@@ -3603,8 +3637,7 @@ innobase_fts_check_doc_id_index_in_def(
36033637
return(FTS_NOT_EXIST_DOC_ID_INDEX);
36043638
}
36053639

3606-
/*******************************************************************//**
3607-
Create an index table where indexes are ordered as follows:
3640+
/** Create an index table where indexes are ordered as follows:
36083641
36093642
IF a new primary key is defined for the table THEN
36103643
@@ -3618,23 +3651,15 @@ ELSE
36183651
ENDIF
36193652
36203653
@return key definitions */
3621-
static MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
3622-
index_def_t*
3623-
innobase_create_key_defs(
3624-
/*=====================*/
3625-
mem_heap_t* heap,
3626-
/*!< in/out: memory heap where space for key
3627-
definitions are allocated */
3654+
MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
3655+
inline index_def_t*
3656+
ha_innobase_inplace_ctx::create_key_defs(
36283657
const Alter_inplace_info* ha_alter_info,
36293658
/*!< in: alter operation */
36303659
const TABLE* altered_table,
36313660
/*!< in: MySQL table that is being altered */
3632-
ulint& n_add,
3633-
/*!< in/out: number of indexes to be created */
36343661
ulint& n_fts_add,
36353662
/*!< out: number of FTS indexes to be created */
3636-
bool got_default_clust,
3637-
/*!< in: whether the table lacks a primary key */
36383663
ulint& fts_doc_id_col,
36393664
/*!< in: The column number for Doc ID */
36403665
bool& add_fts_doc_id,
@@ -3646,6 +3671,9 @@ innobase_create_key_defs(
36463671
const TABLE* table)
36473672
/*!< in: MySQL table that is being altered */
36483673
{
3674+
ulint& n_add = num_to_add_index;
3675+
const bool got_default_clust = new_table->indexes.start->is_gen_clust();
3676+
36493677
index_def_t* indexdef;
36503678
index_def_t* indexdefs;
36513679
bool new_primary;
@@ -3654,7 +3682,7 @@ innobase_create_key_defs(
36543682
const KEY*const key_info
36553683
= ha_alter_info->key_info_buffer;
36563684

3657-
DBUG_ENTER("innobase_create_key_defs");
3685+
DBUG_ENTER("ha_innobase_inplace_ctx::create_key_defs");
36583686
DBUG_ASSERT(!add_fts_doc_id || add_fts_doc_idx);
36593687
DBUG_ASSERT(ha_alter_info->index_add_count == n_add);
36603688

@@ -6004,11 +6032,9 @@ prepare_inplace_alter_table_dict(
60046032
const char* path = thd_innodb_tmpdir(
60056033
ctx->prebuilt->trx->mysql_thd);
60066034

6007-
index_defs = innobase_create_key_defs(
6008-
ctx->heap, ha_alter_info, altered_table, ctx->num_to_add_index,
6035+
index_defs = ctx->create_key_defs(
6036+
ha_alter_info, altered_table,
60096037
num_fts_index,
6010-
dict_index_is_auto_gen_clust(dict_table_get_first_index(
6011-
ctx->new_table)),
60126038
fts_doc_id_col, add_fts_doc_id, add_fts_doc_id_idx,
60136039
old_table);
60146040

storage/innobase/include/dict0dict.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,21 +1155,6 @@ dict_index_get_nth_col_or_prefix_pos(
11551155
ulint* prefix_col_pos) /*!< out: col num if prefix
11561156
*/
11571157
__attribute__((warn_unused_result));
1158-
1159-
/********************************************************************//**
1160-
Returns TRUE if the index contains a column or a prefix of that column.
1161-
@param[in] index index
1162-
@param[in] n column number
1163-
@param[in] is_virtual whether it is a virtual col
1164-
@return TRUE if contains the column or its prefix */
1165-
bool
1166-
dict_index_contains_col_or_prefix(
1167-
/*==============================*/
1168-
const dict_index_t* index, /*!< in: index */
1169-
ulint n, /*!< in: column number */
1170-
bool is_virtual)
1171-
/*!< in: whether it is a virtual col */
1172-
MY_ATTRIBUTE((warn_unused_result));
11731158
/********************************************************************//**
11741159
Looks for a matching field in an index. The column has to be the same. The
11751160
column in index must be complete, or must contain a prefix longer than the

storage/innobase/include/dict0dict.ic

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,7 @@ dict_table_is_fts_column(
11531153

11541154
index = (dict_index_t*) ib_vector_getp(indexes, i);
11551155

1156-
if (dict_index_contains_col_or_prefix(
1157-
index, col_no, is_virtual)) {
1158-
1156+
if (index->contains_col_or_prefix(col_no, is_virtual)) {
11591157
return(i);
11601158
}
11611159
}

storage/innobase/include/dict0mem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,13 @@ struct dict_index_t {
12031203

12041204
/** Reconstruct the clustered index fields. */
12051205
inline void reconstruct_fields();
1206+
1207+
/** Check if the index contains a column or a prefix of that column.
1208+
@param[in] n column number
1209+
@param[in] is_virtual whether it is a virtual col
1210+
@return whether the index contains the column or its prefix */
1211+
bool contains_col_or_prefix(ulint n, bool is_virtual) const
1212+
MY_ATTRIBUTE((warn_unused_result));
12061213
};
12071214

12081215
/** Detach a column from an index.

0 commit comments

Comments
 (0)