Skip to content

Commit c5fc3a9

Browse files
committed
MDEV-12004 InnoDB wrongly thinks that a column is indexed
after failed ADD UNIQUE INDEX check_col_exists_in_indexes(): Add the parameter only_committed. When considering committed indexes, evaluate index->is_committed(). Else, evaluate index->to_be_dropped. rollback_inplace_alter_table(): Invoke check_col_exists_in_indexes() with only_committed=true.
1 parent 2aa47d9 commit c5fc3a9

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

storage/innobase/handler/handler0alter.cc

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2013, 2016, MariaDB Corporation. All Rights Reserved.
4+
Copyright (c) 2013, 2017, MariaDB Corporation. All Rights Reserved.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -6569,9 +6569,10 @@ innobase_online_rebuild_log_free(
65696569
/** For each user column, which is part of an index which is not going to be
65706570
dropped, it checks if the column number of the column is same as col_no
65716571
argument passed.
6572-
@param[in] table table object
6573-
@param[in] col_no column number of the column which is to be checked
6574-
@param[in] is_v if this is a virtual column
6572+
@param[in] table table
6573+
@param[in] col_no column number
6574+
@param[in] is_v if this is a virtual column
6575+
@param[in] only_committed whether to consider only committed indexes
65756576
@retval true column exists
65766577
@retval false column does not exist, true if column is system column or
65776578
it is in the index. */
@@ -6580,17 +6581,21 @@ bool
65806581
check_col_exists_in_indexes(
65816582
const dict_table_t* table,
65826583
ulint col_no,
6583-
bool is_v)
6584+
bool is_v,
6585+
bool only_committed = false)
65846586
{
65856587
/* This function does not check system columns */
65866588
if (!is_v && dict_table_get_nth_col(table, col_no)->mtype == DATA_SYS) {
65876589
return(true);
65886590
}
65896591

6590-
for (dict_index_t* index = dict_table_get_first_index(table); index;
6592+
for (const dict_index_t* index = dict_table_get_first_index(table);
6593+
index;
65916594
index = dict_table_get_next_index(index)) {
65926595

6593-
if (index->to_be_dropped) {
6596+
if (only_committed
6597+
? !index->is_committed()
6598+
: index->to_be_dropped) {
65946599
continue;
65956600
}
65966601

@@ -6769,14 +6774,24 @@ rollback_inplace_alter_table(
67696774
we do this by checking every existing column, if any current
67706775
index would index them */
67716776
for (ulint i = 0; i < dict_table_get_n_cols(prebuilt->table); i++) {
6772-
if (!check_col_exists_in_indexes(prebuilt->table, i, false)) {
6773-
prebuilt->table->cols[i].ord_part = 0;
6777+
dict_col_t& col = prebuilt->table->cols[i];
6778+
if (!col.ord_part) {
6779+
continue;
6780+
}
6781+
if (!check_col_exists_in_indexes(prebuilt->table, i, false,
6782+
true)) {
6783+
col.ord_part = 0;
67746784
}
67756785
}
67766786

67776787
for (ulint i = 0; i < dict_table_get_n_v_cols(prebuilt->table); i++) {
6778-
if (!check_col_exists_in_indexes(prebuilt->table, i, true)) {
6779-
prebuilt->table->v_cols[i].m_col.ord_part = 0;
6788+
dict_col_t& col = prebuilt->table->v_cols[i].m_col;
6789+
if (!col.ord_part) {
6790+
continue;
6791+
}
6792+
if (!check_col_exists_in_indexes(prebuilt->table, i, true,
6793+
true)) {
6794+
col.ord_part = 0;
67806795
}
67816796
}
67826797

0 commit comments

Comments
 (0)