From d67c88946f1624ba1af45b2728442c1fb5d96e24 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 22 Sep 2024 21:35:19 +0300 Subject: [PATCH] Debugging: add dbug_print_join_prefix() to use in best_access_path A call to dbug_print_join_prefix(join_positions, idx, s) returns a const char* ponter to string with current join prefix, including the table being added to it. --- sql/sql_select.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ea690422eac..b995beb53e3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7550,6 +7550,30 @@ double adjust_quick_cost(double quick_cost, ha_rows records) } +#ifndef DBUG_OFF + +char dbug_join_prefix_buf[256]; + +const char* dbug_print_join_prefix(const POSITION *join_positions, + uint idx, + JOIN_TAB *s) +{ + char *buf= dbug_join_prefix_buf; + String str(buf, sizeof(dbug_join_prefix_buf), &my_charset_bin); + str.length(0); + for (uint i=0; i!=idx; i++) + { + str.append(join_positions[i].table->table->alias); + str.append(','); + } + str.append(s->table->alias); + if (str.c_ptr_safe() == buf) + return buf; + else + return "Couldn't fit into buffer"; +} +#endif + /** Find the best access path for an extension of a partial execution plan and add this path to the plan. @@ -7573,6 +7597,14 @@ double adjust_quick_cost(double quick_cost, ha_rows records) @param pos OUT Table access plan @param loose_scan_pos OUT Table plan that uses loosescan, or set cost to DBL_MAX if not possible. + @detail + Use this to print the current join prefix: + + dbug_print_join_prefix(join_positions, idx, s) + + Use this as breakpoint condition to stop at join prefix "t1,t2,t3": + + $_streq(dbug_print_join_prefix(join_positions, idx, s), "t1,t2,t3") @return None