@@ -3387,23 +3387,6 @@ dict_table_get_foreign_constraint(
33873387 return (NULL );
33883388}
33893389
3390- /* ********************************************************************/ /* *
3391- Frees a foreign key struct. */
3392-
3393- void
3394- dict_foreign_free (
3395- /* ==============*/
3396- dict_foreign_t * foreign) /* !< in, own: foreign key struct */
3397- {
3398- DBUG_ENTER (" dict_foreign_free" );
3399- DBUG_PRINT (" dict_foreign_free" , (" id: '%s', heap: %p" , foreign->id ,
3400- foreign->heap ));
3401-
3402- mem_heap_free (foreign->heap );
3403-
3404- DBUG_VOID_RETURN;
3405- }
3406-
34073390/* *********************************************************************/ /* *
34083391Removes a foreign constraint struct from the dictionary cache. */
34093392
@@ -4385,6 +4368,7 @@ dict_create_foreign_constraints_low(
43854368 const char * column_names[500 ];
43864369 const char * referenced_table_name;
43874370 dict_foreign_set local_fk_set;
4371+ dict_foreign_set_free local_fk_set_free (local_fk_set);
43884372
43894373 ut_ad (!srv_read_only_mode || handler);
43904374 ut_ad (mutex_own (&(dict_sys->mutex )) || handler);
@@ -4513,17 +4497,10 @@ dict_create_foreign_constraints_low(
45134497
45144498 table->foreign_set .insert (local_fk_set.begin (),
45154499 local_fk_set.end ());
4516-
4517- for (dict_foreign_set::iterator it
4518- = local_fk_set.begin ();
4519- it != local_fk_set.end ();
4520- ++it) {
4521-
4522- dict_table_t * ref = (*it)->referenced_table ;
4523- if (ref != NULL ) {
4524- ref->referenced_set .insert (*it);
4525- }
4526- }
4500+ std::for_each (local_fk_set.begin (),
4501+ local_fk_set.end (),
4502+ dict_foreign_add_to_referenced_table ());
4503+ local_fk_set.clear ();
45274504 }
45284505 return (error);
45294506 }
@@ -4655,6 +4632,21 @@ dict_create_foreign_constraints_low(
46554632 strcpy (foreign->id + db_len + 1 , constraint_name);
46564633 }
46574634
4635+ if (foreign->id == NULL ) {
4636+ error = dict_create_add_foreign_id (&number,
4637+ table->name , foreign);
4638+ if (error != DB_SUCCESS) {
4639+ dict_foreign_free (foreign);
4640+ return (error);
4641+ }
4642+ }
4643+
4644+ std::pair<dict_foreign_set::iterator, bool > ret
4645+ = local_fk_set.insert (foreign);
4646+
4647+ ut_a (ret.second ); /* second is true if the insertion
4648+ took place */
4649+
46584650 foreign->foreign_table = table;
46594651 foreign->foreign_table_name = mem_heap_strdup (
46604652 foreign->heap , table->name );
@@ -4680,8 +4672,6 @@ dict_create_foreign_constraints_low(
46804672 checking of foreign key constraints! */
46814673
46824674 if (!success || (!referenced_table && trx->check_foreigns )) {
4683- dict_foreign_free (foreign);
4684-
46854675 mutex_enter (&dict_foreign_err_mutex);
46864676 dict_foreign_error_report_low (ef, name);
46874677 fprintf (ef, " %s:\n Cannot resolve table name close to:\n "
@@ -4695,7 +4685,6 @@ dict_create_foreign_constraints_low(
46954685 ptr = dict_accept (cs, ptr, " (" , &success);
46964686
46974687 if (!success) {
4698- dict_foreign_free (foreign);
46994688 dict_foreign_report_syntax_err (name, start_of_latest_foreign,
47004689 ptr);
47014690 return (DB_CANNOT_ADD_CONSTRAINT);
@@ -4710,7 +4699,6 @@ dict_create_foreign_constraints_low(
47104699 i++;
47114700
47124701 if (!success) {
4713- dict_foreign_free (foreign);
47144702
47154703 mutex_enter (&dict_foreign_err_mutex);
47164704 dict_foreign_error_report_low (ef, name);
@@ -4731,7 +4719,6 @@ dict_create_foreign_constraints_low(
47314719 ptr = dict_accept (cs, ptr, " )" , &success);
47324720
47334721 if (!success || foreign->n_fields != i) {
4734- dict_foreign_free (foreign);
47354722
47364723 dict_foreign_report_syntax_err (name, start_of_latest_foreign,
47374724 ptr);
@@ -4757,7 +4744,6 @@ dict_create_foreign_constraints_low(
47574744 ptr = dict_accept (cs, ptr, " UPDATE" , &success);
47584745
47594746 if (!success) {
4760- dict_foreign_free (foreign);
47614747
47624748 dict_foreign_report_syntax_err (
47634749 name, start_of_latest_foreign, ptr);
@@ -4795,7 +4781,6 @@ dict_create_foreign_constraints_low(
47954781 ptr = dict_accept (cs, ptr, " ACTION" , &success);
47964782
47974783 if (!success) {
4798- dict_foreign_free (foreign);
47994784 dict_foreign_report_syntax_err (
48004785 name, start_of_latest_foreign, ptr);
48014786
@@ -4814,7 +4799,6 @@ dict_create_foreign_constraints_low(
48144799 ptr = dict_accept (cs, ptr, " SET" , &success);
48154800
48164801 if (!success) {
4817- dict_foreign_free (foreign);
48184802 dict_foreign_report_syntax_err (name, start_of_latest_foreign,
48194803 ptr);
48204804 return (DB_CANNOT_ADD_CONSTRAINT);
@@ -4823,7 +4807,6 @@ dict_create_foreign_constraints_low(
48234807 ptr = dict_accept (cs, ptr, " NULL" , &success);
48244808
48254809 if (!success) {
4826- dict_foreign_free (foreign);
48274810 dict_foreign_report_syntax_err (name, start_of_latest_foreign,
48284811 ptr);
48294812 return (DB_CANNOT_ADD_CONSTRAINT);
@@ -4836,8 +4819,6 @@ dict_create_foreign_constraints_low(
48364819 /* It is not sensible to define SET NULL
48374820 if the column is not allowed to be NULL! */
48384821
4839- dict_foreign_free (foreign);
4840-
48414822 mutex_enter (&dict_foreign_err_mutex);
48424823 dict_foreign_error_report_low (ef, name);
48434824 fprintf (ef, " %s:\n "
@@ -4863,8 +4844,6 @@ dict_create_foreign_constraints_low(
48634844 if (n_on_deletes > 1 || n_on_updates > 1 ) {
48644845 /* It is an error to define more than 1 action */
48654846
4866- dict_foreign_free (foreign);
4867-
48684847 mutex_enter (&dict_foreign_err_mutex);
48694848 dict_foreign_error_report_low (ef, name);
48704849 fprintf (ef, " %s:\n "
@@ -4886,7 +4865,6 @@ dict_create_foreign_constraints_low(
48864865 foreign->foreign_index ,
48874866 TRUE , FALSE );
48884867 if (!index) {
4889- dict_foreign_free (foreign);
48904868 mutex_enter (&dict_foreign_err_mutex);
48914869 dict_foreign_error_report_low (ef, name);
48924870 fprintf (ef, " %s:\n "
@@ -4928,21 +4906,6 @@ dict_create_foreign_constraints_low(
49284906 = mem_heap_strdup (foreign->heap , column_names[i]);
49294907 }
49304908
4931- /* We found an ok constraint definition: add to the set */
4932-
4933- if (foreign->id == NULL ) {
4934- error = dict_create_add_foreign_id (&number,
4935- table->name , foreign);
4936- if (error != DB_SUCCESS) {
4937- return (error);
4938- }
4939- }
4940-
4941- std::pair<dict_foreign_set::iterator, bool > ret
4942- = local_fk_set.insert (foreign);
4943-
4944- ut_a (ret.second ); /* second is true if the insertion
4945- took place */
49464909 goto loop;
49474910}
49484911/* *************************************************************************
0 commit comments