@@ -5324,6 +5324,7 @@ bool Query_block::resolve_table_value_constructor_values(THD *thd) {
53245324 }
53255325
53265326 size_t item_index = 0 ;
5327+ auto field_it = fields.begin ();
53275328 for (auto it = values_row->begin (); it != values_row->end (); ++it) {
53285329 Item *item = *it;
53295330 if ((!item->fixed && item->fix_fields (thd, &*it)) ||
@@ -5356,7 +5357,9 @@ bool Query_block::resolve_table_value_constructor_values(THD *thd) {
53565357 // Make sure to also replace the reference in item_list. In the case
53575358 // where fix_fields transforms an item, it.ref() will only update the
53585359 // reference of values_row.
5359- if (first_execution) fields[item_index] = item;
5360+ if (first_execution) {
5361+ *field_it = item;
5362+ }
53605363 } else {
53615364 Item_values_column *column = down_cast<Item_values_column *>(
53625365 GetNthVisibleField (fields, item_index));
@@ -5365,6 +5368,7 @@ bool Query_block::resolve_table_value_constructor_values(THD *thd) {
53655368 column->fixed = true ; // Does not have regular fix_fields()
53665369 }
53675370
5371+ field_it++;
53685372 ++item_index;
53695373 }
53705374
@@ -5561,8 +5565,12 @@ bool Query_block::transform_table_subquery_to_join_with_derived(
55615565
55625566 // Append inner expressions of decorrelated equalities to the SELECT
55635567 // list. Correct context info of outer expressions.
5564- auto it_outer = sj_outer_exprs.begin () + initial_sj_inner_exprs_count;
5565- auto it_inner = sj_inner_exprs.begin () + initial_sj_inner_exprs_count;
5568+ auto it_outer = sj_outer_exprs.begin ();
5569+ auto it_inner = sj_inner_exprs.begin ();
5570+ for (int i = 0 ; i < initial_sj_inner_exprs_count; i++) {
5571+ it_outer++;
5572+ it_inner++;
5573+ }
55665574 for (int i = 0 ; it_outer != sj_outer_exprs.end ();
55675575 ++it_outer, ++it_inner, ++i) {
55685576 Item *inner = *it_inner;
@@ -6738,12 +6746,13 @@ bool Query_block::nest_derived(THD *thd, Item *join_cond,
67386746 return tl->join_cond () == join_cond;
67396747 });
67406748 assert (it != copy_list.end ()); // assert that we found it
6741- const size_t idx = it - copy_list.begin ();
6742-
6743- // Insert back all outer tables to the inner containing the condition.
6744- // Normally only one.
6745- for (size_t i = 0 ; i < idx; i++) {
6746- jlist.push_front (copy_list[i]);
6749+ size_t idx = 0 ;
6750+ for (auto tmp = copy_list.begin (); tmp != copy_list.end (); ++tmp) {
6751+ if (it == tmp) {
6752+ break ;
6753+ }
6754+ jlist.push_front (*tmp);
6755+ idx++;
67476756 }
67486757
67496758 // Insert the derived table and nest it with the outer(s)
@@ -6854,11 +6863,6 @@ bool Query_block::decorrelate_derived_scalar_subquery_pre(
68546863 if (selected_field == nullptr || f->field != selected_field->field ) {
68556864 m_added_non_hidden_fields++;
68566865
6857- // If f->hidden, f should be among the hidden fields in 'fields'.
6858- assert (std::any_of (fields.cbegin (), fields.cbegin () + first_non_hidden,
6859- [&f](const Item *item) { return f == item; }) ==
6860- f->hidden );
6861-
68626866 Item_field *inner_field;
68636867
68646868 if (f->hidden ) {
0 commit comments