From 47d11328c9e61a6667b6f333c02ebdd2bb152cea Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 25 Mar 2025 14:42:58 +0200 Subject: [PATCH] MDEV-36381: Comment "Procedure of keys generation ..." is in the wrong place Move it from the middle of table.cc to sql_select.cc:generate_derived_keys() --- sql/sql_select.cc | 30 ++++++++++++++++++++++++++++++ sql/table.cc | 31 ------------------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 13802a91591..3c4b7b3ec03 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14059,6 +14059,36 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys) } +/* + Procedure of keys generation for result tables of materialized derived + tables/views. + + A key is generated for each equi-join pair {derived_table, some_other_table}. + Each generated key consists of fields of derived table used in equi-join. + Example: + + SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN + t1 ON tt.f1=t1.f3 and tt.f2.=t1.f4; + In this case for the derived table tt one key will be generated. It will + consist of two parts f1 and f2. + Example: + + SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN + t1 ON tt.f1=t1.f3 JOIN + t2 ON tt.f2=t2.f4; + In this case for the derived table tt two keys will be generated. + One key over f1 field, and another key over f2 field. + Currently optimizer may choose to use only one such key, thus the second + one will be dropped after range optimizer is finished. + See also JOIN::drop_unused_derived_keys function. + Example: + + SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN + t1 ON tt.f1=a_function(t1.f3); + In this case for the derived table tt one key will be generated. It will + consist of one field - f1. +*/ + static bool generate_derived_keys(DYNAMIC_ARRAY *keyuse_array) { diff --git a/sql/table.cc b/sql/table.cc index ddc8aa2f432..1b2b70d8450 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -9956,37 +9956,6 @@ int TABLE_LIST::fetch_number_of_rows() return error; } -/* - Procedure of keys generation for result tables of materialized derived - tables/views. - - A key is generated for each equi-join pair derived table-another table. - Each generated key consists of fields of derived table used in equi-join. - Example: - - SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN - t1 ON tt.f1=t1.f3 and tt.f2.=t1.f4; - In this case for the derived table tt one key will be generated. It will - consist of two parts f1 and f2. - Example: - - SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN - t1 ON tt.f1=t1.f3 JOIN - t2 ON tt.f2=t2.f4; - In this case for the derived table tt two keys will be generated. - One key over f1 field, and another key over f2 field. - Currently optimizer may choose to use only one such key, thus the second - one will be dropped after range optimizer is finished. - See also JOIN::drop_unused_derived_keys function. - Example: - - SELECT * FROM (SELECT * FROM t1 GROUP BY 1) tt JOIN - t1 ON tt.f1=a_function(t1.f3); - In this case for the derived table tt one key will be generated. It will - consist of one field - f1. -*/ - - /* @brief