Closed midenok closed 5 years ago
#0 row_ins_check_foreign_constraint (check_ref=1, foreign=0x7fdb4402df88, table=0x7fdb4402b1e8, entry=0x7fdb440347a8, thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1930
#1 0x0000000000f67e0a in row_ins_check_foreign_constraints (table=0x7fdb4402b1e8, index=0x7fdb4402bb88, pk=false, entry=0x7fdb440347a8, thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:2039
#2 0x0000000000f680a7 in row_ins_sec_index_entry (index=0x7fdb4402bb88, entry=0x7fdb440347a8, thr=0x7fdb440321b0, dup_chk_only=false) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3304
#3 0x000000000102c448 in row_upd_sec_index_entry (node=0x7fdb44031e78, thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2536
#4 0x0000000001027163 in row_upd_sec_step (node=0x7fdb44031e78, thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2563
#5 0x00000000010223bb in row_upd (node=0x7fdb44031e78, thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3330
#6 0x0000000001021c2a in row_upd_step (thr=0x7fdb440321b0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3445
#7 0x0000000000f9c773 in row_update_for_mysql (prebuilt=0x7fdb44031348) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#8 0x0000000000dad25e in ha_innobase::update_row (this=0x7fdb44030ba0, old_row=0x7fdb4402adb0 "\375\001", new_row=0x7fdb4402ad98 "\375\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8850
#9 0x0000000000b24296 in handler::ha_update_row (this=0x7fdb44030ba0, old_data=0x7fdb4402adb0 "\375\001", new_data=0x7fdb4402ad98 "\375\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#10 0x0000000000d2709f in TABLE::delete_row (this=0x7fdb4402ffc8) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:257
#11 0x0000000000d236e1 in mysql_delete (thd=0x7fdb44000cf8, table_list=0x7fdb44013c98, conds=0x0, order_list=0x7fdb440055b0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:750
#12 0x000000000079c4cb in mysql_execute_command (thd=0x7fdb44000cf8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4653
#13 0x0000000000793770 in mysql_parse (thd=0x7fdb44000cf8, rawbuf=0x7fdb44013bd0 "delete from t2", length=14, parser_state=0x7fdb880f85c8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7829
1927 if (check_ref) {
1928 row_ins_foreign_report_add_err(
1929 trx, foreign, btr_pcur_get_rec(&pcur), entry);
1930 err = DB_NO_REFERENCED_ROW;
1931 } else {
row_upd_sec_step()
is not called.
3310 if (node->index == NULL
3311 || (!node->is_delete
3312 && (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE))) {
3313
3314 DBUG_RETURN(DB_SUCCESS);
3315 }
Original fix was for DELETE from child table but this broken DELETE from parent table, because now it checks history record for constraints.
Set check_ref
to false in case of versioned DELETE.
Caused by MDEV-16210 75ba5c815d0272b35a28225d495a4a03fe63d29f
--source include/have_innodb.inc
set foreign_key_checks= 0;
create or replace table t2 (b int, foreign key (b) references t1(a)) engine=innodb with system versioning;
insert into t2 values (1),(1);
set foreign_key_checks= 1;
delete from t2;
# cleanup
drop table t2;
DELETE doesn't fail.
create or replace table t1 (a int);
create or replace table t2 (s date, e date, period for app(s,e), key(s));
replace into t1 values (1), (2);
replace into t2 values ('2018-01-02','2027-06-22'),('2019-12-12','2020-12-12');
create view v as select * from t1 join t2;
update v set e = '2021-01-01' order by s limit 1;
# cleanup
drop view v;
drop table t1, t2;
Do row_ins_check_foreign_constraint() for foreign table (check_ref == false);
Don't do row_ins_check_foreign_constraint();
create or replace table t1 (x int primary key);
create or replace table t2 (x int, foreign key (x) references t1(x));
#0 row_ins_check_foreign_constraint (check_ref=0, foreign=0x7fff8403d9c8, table=0x7fff84046e78, entry=0x7fff8403b190, thr=0x7fff8408dfc8) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0ins.cc:1564
#1 0x000000000103cdba in row_upd_check_references_constraints (node=0x7fff8408dcf0, pcur=0x7fff84045470, table=0x7fff84046e78, index=0x7fff840483c8, offsets=0x7ffff47c3e20, thr=0x7fff8408dfc8, mtr=0x7ffff47c4150) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0upd.cc:296
#2 0x000000000103ac58 in row_upd_del_mark_clust_rec (node=0x7fff8408dcf0, index=0x7fff840483c8, offsets=0x7ffff47c3e20, thr=0x7fff8408dfc8, referenced=1, mtr=0x7ffff47c4150) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0upd.cc:2993
#3 0x000000000103a170 in row_upd_clust_step (node=0x7fff8408dcf0, thr=0x7fff8408dfc8) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0upd.cc:3163
#4 0x0000000001036c4a in row_upd (node=0x7fff8408dcf0, thr=0x7fff8408dfc8) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0upd.cc:3290
#5 0x00000000010367b5 in row_upd_step (thr=0x7fff8408dfc8) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0upd.cc:3434
#6 0x0000000000fd5a65 in row_update_for_mysql (prebuilt=0x7fff8408d258) at /home/midenok/src/mariadb/trunk/src/storage/innobase/row/row0mysql.cc:1885
#7 0x0000000000e15e37 in ha_innobase::delete_row (this=0x7fff8408caa0, record=0x7fff8404e298 "\377\001") at /home/midenok/src/mariadb/trunk/src/storage/innobase/handler/ha_innodb.cc:8981
#8 0x0000000000b964b2 in handler::ha_delete_row (this=0x7fff8408caa0, buf=0x7fff8404e298 "\377\001") at /home/midenok/src/mariadb/trunk/src/sql/handler.cc:6790
#9 0x0000000000d9193e in TABLE::delete_row (this=0x7fff8408bca8) at /home/midenok/src/mariadb/trunk/src/sql/sql_delete.cc:289
#10 0x0000000000d8da4c in mysql_delete (thd=0x7fff84000cf8, table_list=0x7fff84012fe8, conds=0x0, order_list=0x7fff840056b0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/trunk/src/sql/sql_delete.cc:804
#11 0x000000000081201c in mysql_execute_command (thd=0x7fff84000cf8) at /home/midenok/src/mariadb/trunk/src/sql/sql_parse.cc:4725
#12 0x0000000000808710 in mysql_parse (thd=0x7fff84000cf8, rawbuf=0x7fff84012f20 "delete from t1", length=14, parser_state=0x7ffff47c8640, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/trunk/src/sql/sql_parse.cc:7909
(gdb) p table->name
$4 = {
m_name = 0x7fff84057d30 "test/t1",
static part_suffix = "#P#"
}
271 if (foreign->referenced_index == index
272 && (node->is_delete
273 || row_upd_changes_first_fields_binary(
274 entry, index, node->update,
275 foreign->n_fields))) {
...
295
296 err = row_ins_check_foreign_constraint(
297 FALSE, foreign, table, entry, thr);
create or replace table t1 (x int primary key) with system versioning;
insert into t1 values (1);
create or replace table t2 (x int, foreign key (x) references t1(x));
insert into t2 values (1);
delete from t1;
#0 row_ins_check_foreign_constraint (check_ref=0, foreign=0x7fffc8023818, table=0x7fffc8022a78, entry=0x7fff8401adf0, thr=0x7fff84092e98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1568
#1 0x0000000000fe97e4 in row_upd_check_references_constraints (node=0x7fff84092b60, pcur=0x7fffc80228f0, table=0x7fffc8022a78, index=0x7fffc8024bb8, offsets=0x7fff8409acf8, thr=0x7fff84092e98, mtr=0x7ffff545e290) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:296
#2 0x0000000000fe8986 in row_upd_clust_rec_by_insert (node=0x7fff84092b60, index=0x7fffc8024bb8, thr=0x7fff84092e98, referenced=1, mtr=0x7ffff545e290) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2768
#3 0x0000000000fe6cdb in row_upd_clust_step (node=0x7fff84092b60, thr=0x7fff84092e98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3219
#4 0x0000000000fe2a12 in row_upd (node=0x7fff84092b60, thr=0x7fff84092e98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3298
#5 0x0000000000fe2525 in row_upd_step (thr=0x7fff84092e98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3442
#6 0x0000000000f65b51 in row_update_for_mysql (prebuilt=0x7fff84092008) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#7 0x0000000000d917ee in ha_innobase::update_row (this=0x7fff8408f740, old_row=0x7fff8401d190 "\377\001", new_row=0x7fff8401d178 "\377\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8850
#8 0x0000000000b12dbe in handler::ha_update_row (this=0x7fff8408f740, old_data=0x7fff8401d190 "\377\001", new_data=0x7fff8401d178 "\377\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#9 0x0000000000d0d51f in TABLE::delete_row (this=0x7fff84074b18) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:257
#10 0x0000000000d09bdf in mysql_delete (thd=0x7fff84000cf8, table_list=0x7fff84010ab8, conds=0x0, order_list=0x7fff840055b0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:750
#11 0x00000000007973a2 in mysql_execute_command (thd=0x7fff84000cf8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4653
#12 0x000000000078e930 in mysql_parse (thd=0x7fff84000cf8, rawbuf=0x7fff840109f0 "delete from t1", length=14, parser_state=0x7ffff5462648, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7829
drop tables t2, t1;
create or replace table t1 (f1 int, key(f1)) engine=innodb;
create or replace table t2 (f2 int, foreign key (f2) references t1 (f1)) engine=innodb with system versioning;
set foreign_key_checks= off;
insert ignore into t2 values (1);
set foreign_key_checks= on;
delete from t2;
drop tables b, a;
create or replace table a (
x int primary key
) with system versioning;
create or replace table b(
x int,
foreign key (x) references a (x)
);
insert into a(x) values (1);
insert into b(x) values (1);
delete from a;
MDEV-16210 failed because it was secondary key:
drop tables t2, t1;
create or replace table t1 (a int, key(a)) with system versioning;
create or replace table t2 (b int, foreign key (b) references t1(a));
insert into t1 values (1);
insert into t2 values (1);
delete from t1;
--- a/storage/innobase/row/row0upd.cc
+++ b/storage/innobase/row/row0upd.cc
@@ -2529,8 +2529,7 @@ row_upd_sec_index_entry(
ut_a(entry);
/* Insert new index entry */
- err = row_ins_sec_index_entry(index, entry, thr,
- node->is_delete != VERSIONED_DELETE);
+ err = row_ins_sec_index_entry(index, entry, thr, true);
func_exit:
mem_heap_free(heap);
@@ -3192,7 +3191,9 @@ row_upd_clust_step(
row_upd_eval_new_vals(node->update);
}
- if (!node->is_delete && node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) {
+ /* PLAIN_DELETE already exited */
+ ut_ad(node->is_delete != PLAIN_DELETE);
+ if (/*!node->is_delete && */node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) {
err = row_upd_clust_rec(
flags, node, index, offsets, &heap, thr, &mtr);
@@ -3238,8 +3239,8 @@ row_upd_clust_step(
}
ut_ad(node->is_delete != PLAIN_DELETE);
- node->state = node->is_delete ?
- UPD_NODE_UPDATE_ALL_SEC :
+ node->state = /*node->is_delete ?
+ UPD_NODE_UPDATE_ALL_SEC :*/
UPD_NODE_UPDATE_SOME_SEC;
}
--- a/storage/innobase/include/data0data.h
+++ b/storage/innobase/include/data0data.h
@@ -545,6 +545,20 @@ struct dtuple_t {
inserted or updated.
@param[in] index index possibly with instantly added columns */
void trim(const dict_index_t& index);
+
+ /** @return tuple contains sys_end and is from history row */
+ bool vers_history_row() const
+ {
+ for (int i = 0; i < n_fields; ++i)
+ {
+ dfield_t &f = fields[i];
+ if (f.type.vers_sys_end())
+ {
+ return f.vers_history_row();
+ }
+ }
+ return false;
+ }
};
inline ulint dtuple_get_n_fields(const dtuple_t* tuple)
diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc
index 64021b48ee2..5027b32465e 100644
--- a/storage/innobase/row/row0upd.cc
+++ b/storage/innobase/row/row0upd.cc
@@ -25,6 +25,7 @@ Created 12/27/1996 Heikki Tuuri
*******************************************************/
#include "row0upd.h"
+#include "data0data.h"
#include "dict0dict.h"
#include "dict0mem.h"
#include "trx0undo.h"
@@ -3238,9 +3239,10 @@ row_upd_clust_step(
}
ut_ad(node->is_delete != PLAIN_DELETE);
- node->state = node->is_delete ?
- UPD_NODE_UPDATE_ALL_SEC :
- UPD_NODE_UPDATE_SOME_SEC;
+ node->state = (node->is_delete
+ && !node->row->vers_history_row())
+ ? UPD_NODE_UPDATE_ALL_SEC
+ : UPD_NODE_UPDATE_SOME_SEC;
}
node->index = dict_table_get_next_index(index);
#0 row_ins_check_foreign_constraint (check_ref=0, foreign=0x7fffb4040e78, table=0x7fff7c033b48, entry=0x7fff7c039390, thr=0x7fff7c087438) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1568
#1 0x00000000010267f4 in row_upd_check_references_constraints (node=0x7fff7c087100, pcur=0x7fff7c027960, table=0x7fff7c033b48, index=0x7fffb4041638, offsets=0x7fff7c0a41e8, thr=0x7fff7c087438, mtr=0x7ffff47d4290) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:296
#2 0x0000000001025996 in row_upd_clust_rec_by_insert (node=0x7fff7c087100, index=0x7fffb4041638, thr=0x7fff7c087438, referenced=1, mtr=0x7ffff47d4290) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2768
#3 0x0000000001023ceb in row_upd_clust_step (node=0x7fff7c087100, thr=0x7fff7c087438) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3219
#4 0x000000000101fa22 in row_upd (node=0x7fff7c087100, thr=0x7fff7c087438) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3298
#5 0x000000000101f535 in row_upd_step (thr=0x7fff7c087438) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3442
#6 0x0000000000fa2901 in row_update_for_mysql (prebuilt=0x7fff7c0865a8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#7 0x0000000000dce66e in ha_innobase::update_row (this=0x7fff7c031f50, old_row=0x7fff7c039c90 "\377\001", new_row=0x7fff7c039c78 "\377\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8850
#8 0x0000000000b3d7de in handler::ha_update_row (this=0x7fff7c031f50, old_data=0x7fff7c039c90 "\377\001", new_data=0x7fff7c039c78 "\377\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#9 0x0000000000d37f3f in TABLE::delete_row (this=0x7fff7c085968) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:257
#10 0x0000000000d345ff in mysql_delete (thd=0x7fff7c000cf8, table_list=0x7fff7c010ab8, conds=0x0, order_list=0x7fff7c0055b0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:750
#11 0x00000000007c2042 in mysql_execute_command (thd=0x7fff7c000cf8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4653
#12 0x00000000007b95d0 in mysql_parse (thd=0x7fff7c000cf8, rawbuf=0x7fff7c0109f0 "delete from t1", length=14, parser_state=0x7ffff47d8648, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7829
#0 row_ins_check_foreign_constraint (check_ref=1, foreign=0x7fffa0011aa8, table=0x7fffa0010ce8, entry=0x7fff7809dc38, thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1568
#1 0x0000000000f7127f in row_ins_check_foreign_constraints (table=0x7fffa0010ce8, index=0x7fff78027478, pk=false, entry=0x7fff7809dc38, thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:2039
#2 0x0000000000f71516 in row_ins_sec_index_entry (index=0x7fff78027478, entry=0x7fff7809dc38, thr=0x7fff7808b0e0, check_foreign=false) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3284
#3 0x0000000001028df9 in row_upd_sec_index_entry (node=0x7fff7808ada8, thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2532
#4 0x000000000102412d in row_upd_sec_step (node=0x7fff7808ada8, thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2560
#5 0x000000000101fc87 in row_upd (node=0x7fff7808ada8, thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3327
#6 0x000000000101f535 in row_upd_step (thr=0x7fff7808b0e0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3442
#7 0x0000000000fa2901 in row_update_for_mysql (prebuilt=0x7fff7808a268) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#8 0x0000000000dce66e in ha_innobase::update_row (this=0x7fff78031fa0, old_row=0x7fff78033c30 "\375\001", new_row=0x7fff78033c18 "\375\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8850
#9 0x0000000000b3d7de in handler::ha_update_row (this=0x7fff78031fa0, old_data=0x7fff78033c30 "\375\001", new_data=0x7fff78033c18 "\375\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#10 0x0000000000d37f3f in TABLE::delete_row (this=0x7fff78089628) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:257
#11 0x0000000000d345ff in mysql_delete (thd=0x7fff78000cf8, table_list=0x7fff78010ab8, conds=0x0, order_list=0x7fff780055b0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:750
#12 0x00000000007c2042 in mysql_execute_command (thd=0x7fff78000cf8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4653
#13 0x00000000007b95d0 in mysql_parse (thd=0x7fff78000cf8, rawbuf=0x7fff780109f0 "delete from t2", length=14, parser_state=0x7ffff47d8648, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7829
Continuing https://github.com/tempesta-tech/mariadb/issues/495
Bug: wrong FK behavior
Reproduce
Result
Expected
No error.
TODO
Revert MDEV-18057 fix (0e1f7f5c4a7eb90f345f2c2da6b4d7ce0b4056c4).