Commit 14471d92 authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Marko Mäkelä

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
parent e8275650
......@@ -905,47 +905,29 @@ dict_index_get_nth_col_or_prefix_pos(
return(ULINT_UNDEFINED);
}
/** Returns TRUE if the index contains a column or a prefix of that column.
@param[in] index index
/** Check if the index contains a column or a prefix of that column.
@param[in] n column number
@param[in] is_virtual whether it is a virtual col
@return TRUE if contains the column or its prefix */
bool
dict_index_contains_col_or_prefix(
const dict_index_t* index,
ulint n,
bool is_virtual)
@return whether the index contains the column or its prefix */
bool dict_index_t::contains_col_or_prefix(ulint n, bool is_virtual) const
{
const dict_field_t* field;
const dict_col_t* col;
ulint pos;
ulint n_fields;
ut_ad(index);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
ut_ad(magic_n == DICT_INDEX_MAGIC_N);
if (dict_index_is_clust(index)) {
if (is_primary()) {
return(!is_virtual);
}
if (is_virtual) {
col = &dict_table_get_nth_v_col(index->table, n)->m_col;
} else {
col = dict_table_get_nth_col(index->table, n);
}
n_fields = dict_index_get_n_fields(index);
for (pos = 0; pos < n_fields; pos++) {
field = dict_index_get_nth_field(index, pos);
const dict_col_t* col = is_virtual
? &dict_table_get_nth_v_col(table, n)->m_col
: dict_table_get_nth_col(table, n);
if (col == field->col) {
return(true);
for (ulint pos = 0; pos < n_fields; pos++) {
if (col == fields[pos].col) {
return true;
}
}
return(false);
return false;
}
/********************************************************************//**
......
......@@ -7256,19 +7256,19 @@ static
const Field*
build_template_needs_field(
/*=======================*/
ibool index_contains, /*!< in:
dict_index_contains_col_or_prefix(
index, i) */
ibool read_just_key, /*!< in: TRUE when MySQL calls
bool index_contains, /*!< in:
dict_index_t::contains_col_or_prefix(
i) */
bool read_just_key, /*!< in: TRUE when MySQL calls
ha_innobase::extra with the
argument HA_EXTRA_KEYREAD; it is enough
to read just columns defined in
the index (i.e., no read of the
clustered index record necessary) */
ibool fetch_all_in_key,
bool fetch_all_in_key,
/*!< in: true=fetch all fields in
the index */
ibool fetch_primary_key_cols,
bool fetch_primary_key_cols,
/*!< in: true=fetch the
primary key columns */
dict_index_t* index, /*!< in: InnoDB index to use */
......@@ -7329,11 +7329,11 @@ build_template_needs_field_in_icp(
bool is_virtual)
/*!< in: a virtual column or not */
{
ut_ad(contains == dict_index_contains_col_or_prefix(index, i, is_virtual));
ut_ad(contains == index->contains_col_or_prefix(i, is_virtual));
return(index == prebuilt->index
? contains
: dict_index_contains_col_or_prefix(prebuilt->index, i, is_virtual));
: prebuilt->index->contains_col_or_prefix(i, is_virtual));
}
/**************************************************************//**
......@@ -7609,9 +7609,8 @@ ha_innobase::build_template(
num_v++;
continue;
}
ibool index_contains
= dict_index_contains_col_or_prefix(
index, is_v ? num_v : i - num_v, is_v);
bool index_contains = index->contains_col_or_prefix(
is_v ? num_v : i - num_v, is_v);
if (is_v && index_contains) {
m_prebuilt->n_template = 0;
num_v = 0;
......@@ -7750,9 +7749,8 @@ ha_innobase::build_template(
continue;
}
ibool index_contains
= dict_index_contains_col_or_prefix(
index, is_v ? num_v : i - num_v, is_v);
bool index_contains = index->contains_col_or_prefix(
is_v ? num_v : i - num_v, is_v);
if (!build_template_needs_field_in_icp(
index, m_prebuilt, index_contains,
......@@ -7809,8 +7807,8 @@ ha_innobase::build_template(
cluster index. */
if (is_v
&& m_prebuilt->read_just_key
&& !dict_index_contains_col_or_prefix(
m_prebuilt->index, num_v, true))
&& !m_prebuilt->index->contains_col_or_prefix(
num_v, true))
{
/* Turn off ROW_MYSQL_WHOLE_ROW */
m_prebuilt->template_type =
......@@ -7819,20 +7817,14 @@ ha_innobase::build_template(
continue;
}
} else {
ibool contain;
if (!is_v) {
contain = dict_index_contains_col_or_prefix(
index, i - num_v,
false);
} else if (dict_index_is_clust(index)) {
if (is_v && index->is_primary()) {
num_v++;
continue;
} else {
contain = dict_index_contains_col_or_prefix(
index, num_v, true);
}
bool contain = index->contains_col_or_prefix(
is_v ? num_v: i - num_v, is_v);
field = build_template_needs_field(
contain,
m_prebuilt->read_just_key,
......
......@@ -1101,6 +1101,40 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
return instant_table;
}
/** Create an index table where indexes are ordered as follows:
IF a new primary key is defined for the table THEN
1) New primary key
2) The remaining keys in key_info
ELSE
1) All new indexes in the order they arrive from MySQL
ENDIF
@return key definitions */
MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
inline index_def_t*
create_key_defs(
const Alter_inplace_info* ha_alter_info,
/*!< in: alter operation */
const TABLE* altered_table,
/*!< in: MySQL table that is being altered */
ulint& n_fts_add,
/*!< out: number of FTS indexes to be created */
ulint& fts_doc_id_col,
/*!< in: The column number for Doc ID */
bool& add_fts_doc_id,
/*!< in: whether we need to add new DOC ID
column for FTS index */
bool& add_fts_doc_idx,
/*!< in: whether we need to add new DOC ID
index for FTS index */
const TABLE* table);
/*!< in: MySQL table that is being altered */
private:
// Disable copying
ha_innobase_inplace_ctx(const ha_innobase_inplace_ctx&);
......@@ -3603,8 +3637,7 @@ innobase_fts_check_doc_id_index_in_def(
return(FTS_NOT_EXIST_DOC_ID_INDEX);
}
/*******************************************************************//**
Create an index table where indexes are ordered as follows:
/** Create an index table where indexes are ordered as follows:
IF a new primary key is defined for the table THEN
......@@ -3618,23 +3651,15 @@ ELSE
ENDIF
@return key definitions */
static MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
index_def_t*
innobase_create_key_defs(
/*=====================*/
mem_heap_t* heap,
/*!< in/out: memory heap where space for key
definitions are allocated */
MY_ATTRIBUTE((nonnull, warn_unused_result, malloc))
inline index_def_t*
ha_innobase_inplace_ctx::create_key_defs(
const Alter_inplace_info* ha_alter_info,
/*!< in: alter operation */
const TABLE* altered_table,
/*!< in: MySQL table that is being altered */
ulint& n_add,
/*!< in/out: number of indexes to be created */
ulint& n_fts_add,
/*!< out: number of FTS indexes to be created */
bool got_default_clust,
/*!< in: whether the table lacks a primary key */
ulint& fts_doc_id_col,
/*!< in: The column number for Doc ID */
bool& add_fts_doc_id,
......@@ -3646,6 +3671,9 @@ innobase_create_key_defs(
const TABLE* table)
/*!< in: MySQL table that is being altered */
{
ulint& n_add = num_to_add_index;
const bool got_default_clust = new_table->indexes.start->is_gen_clust();
index_def_t* indexdef;
index_def_t* indexdefs;
bool new_primary;
......@@ -3654,7 +3682,7 @@ innobase_create_key_defs(
const KEY*const key_info
= ha_alter_info->key_info_buffer;
DBUG_ENTER("innobase_create_key_defs");
DBUG_ENTER("ha_innobase_inplace_ctx::create_key_defs");
DBUG_ASSERT(!add_fts_doc_id || add_fts_doc_idx);
DBUG_ASSERT(ha_alter_info->index_add_count == n_add);
......@@ -6004,11 +6032,9 @@ prepare_inplace_alter_table_dict(
const char* path = thd_innodb_tmpdir(
ctx->prebuilt->trx->mysql_thd);
index_defs = innobase_create_key_defs(
ctx->heap, ha_alter_info, altered_table, ctx->num_to_add_index,
index_defs = ctx->create_key_defs(
ha_alter_info, altered_table,
num_fts_index,
dict_index_is_auto_gen_clust(dict_table_get_first_index(
ctx->new_table)),
fts_doc_id_col, add_fts_doc_id, add_fts_doc_id_idx,
old_table);
......
......@@ -1155,21 +1155,6 @@ dict_index_get_nth_col_or_prefix_pos(
ulint* prefix_col_pos) /*!< out: col num if prefix
*/
__attribute__((warn_unused_result));
/********************************************************************//**
Returns TRUE if the index contains a column or a prefix of that column.
@param[in] index index
@param[in] n column number
@param[in] is_virtual whether it is a virtual col
@return TRUE if contains the column or its prefix */
bool
dict_index_contains_col_or_prefix(
/*==============================*/
const dict_index_t* index, /*!< in: index */
ulint n, /*!< in: column number */
bool is_virtual)
/*!< in: whether it is a virtual col */
MY_ATTRIBUTE((warn_unused_result));
/********************************************************************//**
Looks for a matching field in an index. The column has to be the same. The
column in index must be complete, or must contain a prefix longer than the
......
......@@ -1153,9 +1153,7 @@ dict_table_is_fts_column(
index = (dict_index_t*) ib_vector_getp(indexes, i);
if (dict_index_contains_col_or_prefix(
index, col_no, is_virtual)) {
if (index->contains_col_or_prefix(col_no, is_virtual)) {
return(i);
}
}
......
......@@ -1203,6 +1203,13 @@ struct dict_index_t {
/** Reconstruct the clustered index fields. */
inline void reconstruct_fields();
/** Check if the index contains a column or a prefix of that column.
@param[in] n column number
@param[in] is_virtual whether it is a virtual col
@return whether the index contains the column or its prefix */
bool contains_col_or_prefix(ulint n, bool is_virtual) const
MY_ATTRIBUTE((warn_unused_result));
};
/** Detach a column from an index.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment