Skip to content

Commit b2d7b76

Browse files
committed
Fixed a case when parent table does not have records,
Fk table tries to insert entries from previous table and gets an error Failed to add constraint during alter Now if parent table has 0 records, then fk table will also be empty
1 parent 6305c08 commit b2d7b76

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/random_test.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,6 @@ Table *Table::table_id(TABLE_TYPES type, int id) {
17391739
options->at(Option::EXACT_INITIAL_RECORDS)->getBool()
17401740
? options->at(Option::INITIAL_RECORDS_IN_TABLE)->getInt()
17411741
: rand_int(options->at(Option::INITIAL_RECORDS_IN_TABLE)->getInt());
1742-
17431742
static auto no_encryption = opt_bool(NO_ENCRYPTION);
17441743

17451744
/* temporary table on 8.0 can't have key block size */
@@ -2812,6 +2811,12 @@ void Table::UpdateRandomROW(Thd1 *thd) {
28122811
bool Table::InsertBulkRecord(Thd1 *thd) {
28132812
bool is_list_partition = false;
28142813

2814+
// if parent has no records, child can't have records
2815+
if (type == FK) {
2816+
if (static_cast<FK_table *>(this)->parent->number_of_initial_records == 0)
2817+
number_of_initial_records = 0;
2818+
}
2819+
28152820
if (number_of_initial_records == 0)
28162821
return true;
28172822

0 commit comments

Comments
 (0)