@@ -6514,6 +6514,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
65146514 Query_arena *arena, backup;
65156515 bool result= TRUE ;
65166516 bool first_outer_loop= TRUE ;
6517+ Field *field_1, *field_2;
65176518 /*
65186519 Leaf table references to which new natural join columns are added
65196520 if the leaves are != NULL.
@@ -6541,6 +6542,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
65416542 if (!(nj_col_1= it_1.get_or_create_column_ref (thd, leaf_1)))
65426543 goto err;
65436544
6545+ field_1= nj_col_1->field ();
65446546 if (nj_col_1->field () && nj_col_1->field ()->vers_sys_field ())
65456547 continue ;
65466548
@@ -6565,6 +6567,8 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
65656567 const LEX_CSTRING *cur_field_name_2;
65666568 if (!(cur_nj_col_2= it_2.get_or_create_column_ref (thd, leaf_2)))
65676569 goto err;
6570+
6571+ field_2= cur_nj_col_2->field ();
65686572 cur_field_name_2= cur_nj_col_2->name ();
65696573 DBUG_PRINT (" info" , (" cur_field_name_2=%s.%s" ,
65706574 cur_nj_col_2->safe_table_name (),
@@ -6585,14 +6589,17 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
65856589 cur_field_name_2))
65866590 {
65876591 DBUG_PRINT (" info" , (" match c1.is_common=%d" , nj_col_1->is_common ));
6588- if (cur_nj_col_2->is_common ||
6589- (found && (!using_fields || is_using_column_1)))
6592+ if (cur_nj_col_2->is_common || found)
65906593 {
65916594 my_error (ER_NON_UNIQ_ERROR, MYF (0 ), field_name_1->str , thd->where );
65926595 goto err;
65936596 }
6594- nj_col_2= cur_nj_col_2;
6595- found= TRUE ;
6597+ if (!using_fields || is_using_column_1)
6598+ {
6599+ DBUG_ASSERT (nj_col_2 == NULL );
6600+ nj_col_2= cur_nj_col_2;
6601+ found= TRUE ;
6602+ }
65966603 }
65976604 }
65986605 if (first_outer_loop && leaf_2)
@@ -6612,16 +6619,14 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
66126619 clause (if present), mark them as common fields, and add a new
66136620 equi-join condition to the ON clause.
66146621 */
6615- if (nj_col_2 && (!using_fields ||is_using_column_1) )
6622+ if (nj_col_2)
66166623 {
66176624 /*
66186625 Create non-fixed fully qualified field and let fix_fields to
66196626 resolve it.
66206627 */
66216628 Item *item_1= nj_col_1->create_item (thd);
66226629 Item *item_2= nj_col_2->create_item (thd);
6623- Field *field_1= nj_col_1->field ();
6624- Field *field_2= nj_col_2->field ();
66256630 Item_ident *item_ident_1, *item_ident_2;
66266631 Item_func_eq *eq_cond;
66276632
@@ -6661,11 +6666,6 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
66616666 if (!(eq_cond= new (thd->mem_root ) Item_func_eq (thd, item_ident_1, item_ident_2)))
66626667 goto err; /* Out of memory. */
66636668
6664- if (field_1 && field_1->vcol_info )
6665- field_1->table ->mark_virtual_col (field_1);
6666- if (field_2 && field_2->vcol_info )
6667- field_2->table ->mark_virtual_col (field_2);
6668-
66696669 /*
66706670 Add the new equi-join condition to the ON clause. Notice that
66716671 fix_fields() is applied to all ON conditions in setup_conds()
@@ -6683,19 +6683,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
66836683 nj_col_2->name ()->str ));
66846684
66856685 if (field_1)
6686- {
6687- TABLE *table_1= nj_col_1->table_ref ->table ;
6688- /* Mark field_1 used for table cache. */
6689- bitmap_set_bit (table_1->read_set , field_1->field_index );
6690- table_1->covering_keys .intersect (field_1->part_of_key );
6691- }
6686+ update_field_dependencies (thd, field_1, field_1->table );
66926687 if (field_2)
6693- {
6694- TABLE *table_2= nj_col_2->table_ref ->table ;
6695- /* Mark field_2 used for table cache. */
6696- bitmap_set_bit (table_2->read_set , field_2->field_index );
6697- table_2->covering_keys .intersect (field_2->part_of_key );
6698- }
6688+ update_field_dependencies (thd, field_2, field_2->table );
66996689
67006690 if (using_fields != NULL )
67016691 ++(*found_using_fields);
0 commit comments