Skip to content

Commit

Permalink
MDEV-29069 follow-up: allow deterministic DEFAULTs
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarrior authored and vuvova committed Aug 15, 2023
1 parent 2be4c83 commit bac728a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions mysql-test/main/alter_table_online_debug.result
Expand Up @@ -1073,8 +1073,8 @@ update t set a = a + 1 where a = 10;
set debug_sync= 'now signal goforit';
connection default;
Warnings:
Note 1105 Key chosen: -1
Note 1105 Key chosen: -1
Note 1105 Key chosen: 0
Note 1105 Key chosen: 0
select a from t;
a
11
Expand All @@ -1093,8 +1093,8 @@ update t set a = a + 1 where a = 10;
set debug_sync= 'now signal goforit';
connection default;
Warnings:
Note 1105 Key chosen: -1
Note 1105 Key chosen: -1
Note 1105 Key chosen: 0
Note 1105 Key chosen: 0
#
# Add key for old row
#
Expand Down
16 changes: 13 additions & 3 deletions sql/log_event_server.cc
Expand Up @@ -7107,11 +7107,12 @@ static bool record_compare(TABLE *table, bool vers_from_plain= false)
bool Rows_log_event::is_key_usable(const KEY *key) const
{
RPL_TABLE_LIST *tl= (RPL_TABLE_LIST*)m_table->pos_in_table_list;
const bool online_alter= tl->m_online_alter_copy_fields;

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

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

for (uint p= 0; p < key->user_defined_key_parts; p++)
{
uint field_idx= key->key_part[p].fieldnr - 1;
if (!bitmap_is_set(&m_table->has_value_set, field_idx))
Field *f= key->key_part[p].field;
/*
in the online alter case (but not in replication) we don't have
to reject an index if it includes new columns, as long as
their values are deterministic.
*/
bool non_deterministic_default= f->default_value &&
f->default_value->flags & VCOL_NOT_STRICTLY_DETERMINISTIC;
bool next_number_field= f == f->table->next_number_field;
if (!bitmap_is_set(&m_table->has_value_set, f->field_index) &&
(!online_alter || non_deterministic_default || next_number_field))
return false;
}
return true;
Expand Down

0 comments on commit bac728a

Please sign in to comment.