summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2022-07-19 00:29:42 +0300
committerNikita Malyavin <nikitamalyavin@gmail.com>2022-08-23 16:36:27 +0300
commit33b7002d8dfce17b632a6424ea8b59cbfbe345ea (patch)
treea96a31e51750558e172f37e5409862b0e426c693
parentfeb9e0fa8cb40cd27ed86f07e3cb5fab0ec7f94b (diff)
downloadmariadb-git-33b7002d8dfce17b632a6424ea8b59cbfbe345ea.tar.gz
MDEV-29069 follow-up: allow deterministic DEFAULTs
-rw-r--r--mysql-test/main/alter_table_online_debug.result9
-rw-r--r--mysql-test/main/alter_table_online_debug.test2
-rw-r--r--sql/log_event_server.cc13
3 files changed, 15 insertions, 9 deletions
diff --git a/mysql-test/main/alter_table_online_debug.result b/mysql-test/main/alter_table_online_debug.result
index e9fcebcf635..d356246fd66 100644
--- a/mysql-test/main/alter_table_online_debug.result
+++ b/mysql-test/main/alter_table_online_debug.result
@@ -1004,7 +1004,7 @@ a
create or replace table t (a int);
insert into t values (10),(20),(30);
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for goforit';
-alter table t add b int default (a+1), add primary key(b, a),
+alter table t add b int default (1), add primary key(b, a),
algorithm=copy, lock=none;
connection con2;
set debug_sync= 'now wait_for downgraded';
@@ -1013,8 +1013,7 @@ 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
select a from t;
a
11
@@ -1033,8 +1032,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
#
diff --git a/mysql-test/main/alter_table_online_debug.test b/mysql-test/main/alter_table_online_debug.test
index 31e49f205cb..4fef70a7224 100644
--- a/mysql-test/main/alter_table_online_debug.test
+++ b/mysql-test/main/alter_table_online_debug.test
@@ -1171,7 +1171,7 @@ insert into t values (10),(20),(30);
set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for goforit';
--send
-alter table t add b int default (a+1), add primary key(b, a),
+alter table t add b int default (1), add primary key(b, a),
algorithm=copy, lock=none;
--connection con2
set debug_sync= 'now wait_for downgraded';
diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc
index ba0f8553dfa..c2b144e2780 100644
--- a/sql/log_event_server.cc
+++ b/sql/log_event_server.cc
@@ -8068,9 +8068,16 @@ bool Rows_log_event::key_suits_event(const KEY *key) const
uint master_columns= m_online_alter ? 0 : m_cols.n_bits;
for (uint p= 0; p < key->ext_key_parts; p++)
{
- uint field_idx= key->key_part[p].fieldnr - 1;
- if (field_idx >= master_columns
- && !bitmap_is_set(&m_table->has_value_set, field_idx))
+ Field *f= key->key_part[p].field;
+ uint non_deterministic_default= f->default_value &&
+ f->default_value->flags | VCOL_NOT_STRICTLY_DETERMINISTIC;
+
+ int next_number_field= f->table->next_number_field ?
+ f->table->next_number_field->field_index : -1;
+
+ if (f->field_index >= master_columns
+ && !bitmap_is_set(&m_table->has_value_set, f->field_index)
+ && (non_deterministic_default || next_number_field == f->field_index))
return false;
}
return true;