From 5758ef9c7c695abf758638723ff5328e024127d2 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 14:21:27 +0300 Subject: [PATCH 01/10] Remove JOIN::filesort_found_rows Last use was removed by: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 12:35:59 2016 -0800 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". --- sql/sql_select.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sql/sql_select.h b/sql/sql_select.h index 404692404a613..a569b3f81cfb6 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1825,12 +1825,6 @@ class JOIN :public Sql_alloc */ bool no_rows_in_result_called; - /** - This is set if SQL_CALC_ROWS was calculated by filesort() - and should be taken from the appropriate JOIN_TAB - */ - bool filesort_found_rows; - bool subq_exit_fl; ROLLUP rollup; ///< Used with rollup From bf98d56dd5733d50b8ce3a6580d3c57ab9efe93c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 14:41:10 +0300 Subject: [PATCH 02/10] Remove JOIN::no_field_update, sum_funcs2, sum_funcs_end2 JOIN::no_field_update was added in the initial import (2000) and has never been used. JOIN::sum_funcs2 and JOIN::sum_funcs_end2 were last used before: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 2016 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". Since then sum_funcs2 was only zeroed in JOIN::init() and sum_funcs_end2 was not referenced at all. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 2 +- sql/sql_select.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bf4e799347eaf..433b6202ec2f4 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -516,7 +516,7 @@ void JOIN::init(THD *thd_arg, List &fields_arg, found_records= accepted_rows= 0; fetch_limit= HA_POS_ERROR; thd= thd_arg; - sum_funcs= sum_funcs2= 0; + sum_funcs= 0; procedure= 0; having= tmp_having= having_history= 0; having_is_correlated= false; diff --git a/sql/sql_select.h b/sql/sql_select.h index a569b3f81cfb6..3ddfd670e750d 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1633,7 +1633,7 @@ class JOIN :public Sql_alloc setup_end_select_func */ bool sort_and_group; - bool first_record,full_join, no_field_update; + bool first_record,full_join; bool hash_join; bool do_send_rows; table_map const_table_map; @@ -1785,8 +1785,6 @@ class JOIN :public Sql_alloc List group_fields, group_fields_cache; THD *thd; Item_sum **sum_funcs, ***sum_funcs_end; - /** second copy of sumfuncs (for queries with 2 temporary tables */ - Item_sum **sum_funcs2, ***sum_funcs_end2; Procedure *procedure; Item *having; Item *tmp_having; ///< To store having when processed temporary table From 1e3d5ea61fd98025d7b07c4bf2a3ece89dfeda18 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 14:48:26 +0300 Subject: [PATCH 03/10] Remove JOIN::original_join_tab, original_table_count These were added by cf50e13fbd1 (MDEV-6080: Allowing storage engine to shortcut group by queries) to remember the join_tab array and table_count before the group_by_handler replaced them. The last assignment of non-NULL values to them was removed by: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 2016 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". Since then original_join_tab was only set to 0, so the block in JOIN::cleanup() that restored join_tab and table_count from them never ran. Remove the block and both members. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 9 --------- sql/sql_select.h | 2 -- 2 files changed, 11 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 433b6202ec2f4..cef88c9514201 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -559,7 +559,6 @@ void JOIN::init(THD *thd_arg, List &fields_arg, no_rows_in_result_called= 0; positions= best_positions= 0; pushdown_query= 0; - original_join_tab= 0; explain= NULL; tmp_table_keep_current_rowid= 0; allowed_top_level_tables= 0; @@ -17586,14 +17585,6 @@ void JOIN::cleanup(bool full) if (full) have_query_plan= QEP_DELETED; - if (original_join_tab) - { - /* Free the original optimized join created for the group_by_handler */ - join_tab= original_join_tab; - original_join_tab= 0; - table_count= original_table_count; - } - if (join_tab) { JOIN_TAB *tab; diff --git a/sql/sql_select.h b/sql/sql_select.h index 3ddfd670e750d..6542bb0239289 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1711,8 +1711,6 @@ class JOIN :public Sql_alloc POSITION *next_sort_position; /* Next free space in sort_positions */ Pushdown_query *pushdown_query; - JOIN_TAB *original_join_tab; - uint original_table_count; uint sort_space; /******* Join optimization state members start *******/ From 291c71dc8a0fc95aef4235eefb24586f907cf5fb Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 18:13:50 +0300 Subject: [PATCH 04/10] Remove JOIN_TAB::related_tables The member was added by: commit 1d82e5daf71 Author: Monty Date: Mon Jun 13 2022 Move join->emb_smj_nest setting to choose_plan() and has never been used, neither read nor assigned. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sql/sql_select.h b/sql/sql_select.h index 6542bb0239289..805026967a0f9 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -623,11 +623,6 @@ typedef struct st_join_table { It is only used to prune searches in best_extension_by_limited_search() */ table_map key_dependent; - /* - Tables that have expression in their attached condition clause that depends - on this table. - */ - table_map related_tables; /* Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra' From b0cb207dfe71ee51f2460cb1e9f07f23d2a35532 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 18:14:03 +0300 Subject: [PATCH 05/10] Remove JOIN::need_distinct The member was assigned in JOIN::init(), JOIN::optimize_inner() and JOIN::optimize_stage2(), but never read. Its last reads, the arguments of prepare_sum_aggregators() calls, were removed by: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 2016 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". Since then the callers compute the value themselves from is_using_agg_loose_index_scan(). JOIN::prepare_sum_aggregators() has a parameter of the same name, which is unrelated and is kept. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 3 --- sql/sql_select.h | 1 - 2 files changed, 4 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cef88c9514201..a50a5b5e10a8a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -530,7 +530,6 @@ void JOIN::init(THD *thd_arg, List &fields_arg, simple_order= 0; simple_group= 0; ordered_index_usage= ordered_index_void; - need_distinct= 0; skip_sort_order= 0; with_two_phase_optimization= 0; save_qep= 0; @@ -2247,7 +2246,6 @@ JOIN::optimize_inner() do_send_rows = (unit->lim.get_select_limit()) ? 1 : 0; set_allowed_join_cache_types(); - need_distinct= TRUE; Json_writer_object trace_wrapper(thd); Json_writer_object trace_prepare(thd, "join_optimization"); @@ -3589,7 +3587,6 @@ int JOIN::optimize_stage2() tmp_table_param.precomputed_group_by= TRUE; if (join_tab->is_using_agg_loose_index_scan()) { - need_distinct= FALSE; tmp_table_param.precomputed_group_by= FALSE; } } diff --git a/sql/sql_select.h b/sql/sql_select.h index 805026967a0f9..3f42496d6b4f3 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1609,7 +1609,6 @@ class JOIN :public Sql_alloc group_list) */ bool group; - bool need_distinct; /** Indicates that grouping will be performed on the result set during From 4b1f3b290cc01b4bb1ed8c29fee9c51e8ac7515b Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 18:14:08 +0300 Subject: [PATCH 06/10] Remove JOIN::union_part The member is assigned in JOIN::prepare() but never read. Its last reads (in the EXPLAIN code) were removed by: commit 46a22a5be75 Author: bell@sanja.is.com.ua Date: Thu Sep 26 2002 new EXPLAIN fixed bug in mysql-test/create-test-result fixed bug in union-subselect engine Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 1 - sql/sql_select.h | 1 - 2 files changed, 2 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a50a5b5e10a8a..6b8f03de91be1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1460,7 +1460,6 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, select_lex, select_lex->select_number, this)); select_lex->join= this; join_list= &select_lex->top_join_list; - union_part= unit_arg->is_unit_op(); Json_writer_object trace_wrapper(thd); Json_writer_object trace_prepare(thd, "join_preparation"); diff --git a/sql/sql_select.h b/sql/sql_select.h index 3f42496d6b4f3..53ea0b6baf924 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1938,7 +1938,6 @@ class JOIN :public Sql_alloc const char *zero_result_cause; ///< not 0 if exec must return zero result - bool union_part; ///< this subselect is part of union enum join_optimization_state { NOT_OPTIMIZED=0, OPTIMIZATION_IN_PROGRESS=1, From 25a366f10fc41d2f939431155d56b15e55ccaca5 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 18:14:21 +0300 Subject: [PATCH 07/10] Remove JOIN::select_list_used_tables, eval_select_list_used_tables() JOIN::select_list_used_tables is computed by JOIN::eval_select_list_used_tables(), but never read. Its last reads (in the code that optimizes DISTINCT on a subset of the tables, and in JOIN_TAB::save_explain_data()) were removed by: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 2016 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". Remove the member and the function that computes it. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 25 ------------------------- sql/sql_select.h | 3 --- 2 files changed, 28 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6b8f03de91be1..af52c96426dad 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2312,8 +2312,6 @@ JOIN::optimize_inner() select_lex->update_used_tables(); } - eval_select_list_used_tables(); - table_count= select_lex->leaf_tables.elements; if (select_lex->options & OPTION_SCHEMA_TABLE && @@ -15678,29 +15676,6 @@ void JOIN::drop_unused_derived_keys() } -/* - Evaluate the bitmap of used tables for items from the select list -*/ - -inline void JOIN::eval_select_list_used_tables() -{ - select_list_used_tables= 0; - Item *item; - List_iterator_fast it(fields_list); - while ((item= it++)) - { - select_list_used_tables|= item->used_tables(); - } - Item_outer_ref *ref; - List_iterator_fast ref_it(select_lex->inner_refs_list); - while ((ref= ref_it++)) - { - item= ref->outer_ref; - select_list_used_tables|= item->used_tables(); - } -} - - /* Determine {after which table we'll produce ordered set} diff --git a/sql/sql_select.h b/sql/sql_select.h index 53ea0b6baf924..07b14cd4b91d4 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1661,8 +1661,6 @@ class JOIN :public Sql_alloc make_join_statistics) */ table_map outer_join; - /* Bitmap of tables used in the select list items */ - table_map select_list_used_tables; /* Tables that has HA_NON_COMPARABLE_ROWID (does not support rowid) set */ table_map not_usable_rowid_map; /* Tables that have a possiblity to use EQ_ref */ @@ -2117,7 +2115,6 @@ class JOIN :public Sql_alloc void drop_unused_derived_keys(); bool get_best_combination(); bool add_sorting_to_table(JOIN_TAB *tab, ORDER *order); - inline void eval_select_list_used_tables(); /* Return the table for which an index scan can be used to satisfy the sort order needed by the ORDER BY/(implicit) GROUP BY clause From 6065c3f1505a3f0863a3e6d7860f6da8719d2f7f Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 23 Oct 2026 18:33:07 +0300 Subject: [PATCH 08/10] Remove JOIN_TAB::all_fields JOIN_TAB::all_fields is only assigned (in JOIN::make_aggr_tables_info()) and is never read. It was added, together with JOIN_TAB::fields, by: commit 2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 Author: Igor Babaev Date: Tue Feb 9 2016 This is the consolidated patch for mdev-8646: "Re-factor the code for post-join operations". That commit never read it, and no later commit has either, so there was no last use to remove. JOIN_TAB::fields is read (by end_send() and end_send_group()) and is kept. Update its comment, which also described all_fields. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_select.cc | 5 ----- sql/sql_select.h | 11 ++++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index af52c96426dad..5c1dbec56bc93 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3806,7 +3806,6 @@ bool JOIN::make_aggr_tables_info() if (join_tab && top_join_tab_count && tables_list) { join_tab[top_join_tab_count - 1].fields= &fields_list; - join_tab[top_join_tab_count - 1].all_fields= &all_fields; } /* @@ -3925,7 +3924,6 @@ bool JOIN::make_aggr_tables_info() //todo: new: curr_tab->ref_array= &items1; - curr_tab->all_fields= &tmp_all_fields1; curr_tab->fields= &tmp_fields_list1; DBUG_RETURN(thd->is_error()); @@ -4013,7 +4011,6 @@ bool JOIN::make_aggr_tables_info() // Need to set them now for correct group_fields setup, reset at the end. set_items_ref_array(items1); curr_tab->ref_array= &items1; - curr_tab->all_fields= &tmp_all_fields1; curr_tab->fields= &tmp_fields_list1; set_postjoin_aggr_write_func(curr_tab); @@ -4155,7 +4152,6 @@ bool JOIN::make_aggr_tables_info() curr_all_fields= &tmp_all_fields2; set_items_ref_array(items2); curr_tab->ref_array= &items2; - curr_tab->all_fields= &tmp_all_fields2; curr_tab->fields= &tmp_fields_list2; set_postjoin_aggr_write_func(curr_tab); @@ -4240,7 +4236,6 @@ bool JOIN::make_aggr_tables_info() JOIN_TAB *last_tab= join_tab + top_join_tab_count + aggr_tables - 1; // Set grouped fields on the last table last_tab->ref_array= &items3; - last_tab->all_fields= &tmp_all_fields3; last_tab->fields= &tmp_fields_list3; } if (make_sum_func_list(*curr_all_fields, *curr_fields_list, true)) diff --git a/sql/sql_select.h b/sql/sql_select.h index 07b14cd4b91d4..6afb47fb0ef2b 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -769,16 +769,13 @@ typedef struct st_join_table { /** List of topmost expressions in the select list. The *next* JOIN_TAB - in the plan should use it to obtain correct values. Same applicable to - all_fields. These lists are needed because after tmp tables functions - will be turned to fields. These variables are pointing to - tmp_fields_list[123]. Valid only for tmp tables and the last non-tmp - table in the query plan. + in the plan should use it to obtain correct values. This list is needed + because after tmp tables functions will be turned to fields. This + variable is pointing to tmp_fields_list[123]. Valid only for tmp tables + and the last non-tmp table in the query plan. @see JOIN::make_aggr_tables_info() */ List *fields; - /** List of all expressions in the select list */ - List *all_fields; /* Pointer to the ref array slice which to switch to before sending records. Valid only for tmp tables. From 7b4600fe4146ba90989544bb2099f4fd86323e63 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 24 Oct 2026 10:01:26 +0300 Subject: [PATCH 09/10] Remove st_select_lex::udf_list The member is declared but never used. Its last uses (the parser's udf call stack and the udf_list.empty() initializers) were removed by the fix for Bug#24736 (88ba7676c1a, also applied as 1f695dbf7d0). Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_lex.h | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 8973145e441db..5d077d72fe5a5 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1290,7 +1290,6 @@ class st_select_lex: public st_select_lex_node /* Structure to store fields that are used in the GROUP BY of this select */ List grouping_tmp_fields; - List udf_list; /* udf function calls stack */ List *index_hints; /* list of USE/FORCE/IGNORE INDEX */ /* This list is used to restore the names of items From eda8c077c5281bc1e0681b4c31f3744f618a8e2c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 24 Oct 2026 10:01:26 +0300 Subject: [PATCH 10/10] Remove st_select_lex::table_join_options, get_table_join_options() The member is only zeroed in init_select(), and the accessor is declared but has no definition. The last reader and writers in the grammar were removed by bc04ded2353 ("Follow-up post JSON_TABLE merge, table_join_options is not used"). d624464b50b had earlier removed the member and accessor, but they came back with the JSON_TABLE merge. Co-Authored-By: Claude Sonnet 5.5 --- sql/sql_lex.cc | 1 - sql/sql_lex.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index f37c0966c938e..6fc2121fd2028 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3235,7 +3235,6 @@ void st_select_lex::init_select() type= 0; db= null_clex_str; having= 0; - table_join_options= 0; select_lock= select_lock_type::NONE; in_sum_expr= with_wild= with_wild_returning= 0; options= 0; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 5d077d72fe5a5..4f578fea58ebf 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1353,7 +1353,6 @@ class st_select_lex: public st_select_lex_node /// Array of pointers to top elements of all_fields list Ref_ptr_array ref_pointer_array; - ulong table_join_options; /* number of items in select_list and HAVING clause used to get number @@ -1541,7 +1540,6 @@ class st_select_lex: public st_select_lex_node bool save_item_list_names(THD *thd); void restore_item_list_names(); bool set_item_list_names( List *overwrite ); - ulong get_table_join_options(); void set_lock_for_tables(thr_lock_type lock_type, bool for_update, bool skip_locks); /*