Skip to content

Commit bac728a

Browse files
FooBarriorvuvova
authored andcommitted
MDEV-29069 follow-up: allow deterministic DEFAULTs
1 parent 2be4c83 commit bac728a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

mysql-test/main/alter_table_online_debug.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ update t set a = a + 1 where a = 10;
10731073
set debug_sync= 'now signal goforit';
10741074
connection default;
10751075
Warnings:
1076-
Note 1105 Key chosen: -1
1077-
Note 1105 Key chosen: -1
1076+
Note 1105 Key chosen: 0
1077+
Note 1105 Key chosen: 0
10781078
select a from t;
10791079
a
10801080
11
@@ -1093,8 +1093,8 @@ update t set a = a + 1 where a = 10;
10931093
set debug_sync= 'now signal goforit';
10941094
connection default;
10951095
Warnings:
1096-
Note 1105 Key chosen: -1
1097-
Note 1105 Key chosen: -1
1096+
Note 1105 Key chosen: 0
1097+
Note 1105 Key chosen: 0
10981098
#
10991099
# Add key for old row
11001100
#

sql/log_event_server.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7107,11 +7107,12 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false)
71077107
bool Rows_log_event::is_key_usable(const KEY *key) const
71087108
{
71097109
RPL_TABLE_LIST *tl= (RPL_TABLE_LIST*)m_table->pos_in_table_list;
7110+
const bool online_alter= tl->m_online_alter_copy_fields;
71107111

71117112
if (!m_table->s->keys_in_use.is_set(uint(key - m_table->key_info)))
71127113
return false;
71137114

7114-
if (!tl->m_online_alter_copy_fields)
7115+
if (!online_alter)
71157116
{
71167117
if (m_cols.n_bits >= m_table->s->fields)
71177118
return true;
@@ -7126,8 +7127,17 @@ bool Rows_log_event::is_key_usable(const KEY *key) const
71267127

71277128
for (uint p= 0; p < key->user_defined_key_parts; p++)
71287129
{
7129-
uint field_idx= key->key_part[p].fieldnr - 1;
7130-
if (!bitmap_is_set(&m_table->has_value_set, field_idx))
7130+
Field *f= key->key_part[p].field;
7131+
/*
7132+
in the online alter case (but not in replication) we don't have
7133+
to reject an index if it includes new columns, as long as
7134+
their values are deterministic.
7135+
*/
7136+
bool non_deterministic_default= f->default_value &&
7137+
f->default_value->flags & VCOL_NOT_STRICTLY_DETERMINISTIC;
7138+
bool next_number_field= f == f->table->next_number_field;
7139+
if (!bitmap_is_set(&m_table->has_value_set, f->field_index) &&
7140+
(!online_alter || non_deterministic_default || next_number_field))
71317141
return false;
71327142
}
71337143
return true;

0 commit comments

Comments
 (0)