Skip to content

Commit c1cf914

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 c1cf914

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/random_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,11 @@ 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+
// if parent has no records, child can't have records
1743+
if (table->type == FK) {
1744+
if (static_cast<FK_table *>(table)->parent->number_of_initial_records == 0)
1745+
table->number_of_initial_records = 0;
1746+
}
17421747

17431748
static auto no_encryption = opt_bool(NO_ENCRYPTION);
17441749

0 commit comments

Comments
 (0)