#At file:///export/home/jl208045/mysql/wl4800/mysql-next-mr-opt-backporting-wl4800/ based on revid:guilhem.bichot@stripped
3279 Jorgen Loland 2011-03-17
Review comment by Guilhem:
Pass Opt_trace_array pointer to sel_arg_range_seq_next(), which
no longer needs to call get_current_struct() to get the optimizer
trace array. With this, get_current_struct() is no longer used
outside the trace classes and can be made private or removed.
modified:
sql/handler.cc
sql/handler.h
sql/opt_range.cc
sql/opt_range.h
sql/sql_join_cache.cc
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc 2011-02-16 13:52:44 +0000
+++ b/sql/handler.cc 2011-03-17 12:03:30 +0000
@@ -4439,7 +4439,7 @@ handler::multi_range_read_info_const(uin
seq_it= seq->init(seq_init_param, n_ranges, *flags);
Opt_trace_array ota(thd->opt_trace, "ranges");
- while (!seq->next(seq_it, &range))
+ while (!seq->next(seq_it, &range, &ota))
{
if (unlikely(thd->killed != 0))
return HA_POS_ERROR;
@@ -4639,7 +4639,7 @@ int handler::multi_range_read_next(char
start:
/* Try the next range(s) until one matches a record. */
- while (!(range_res= mrr_funcs.next(mrr_iter, &mrr_cur_range)))
+ while (!(range_res= mrr_funcs.next(mrr_iter, &mrr_cur_range, NULL)))
{
scan_it_again:
result= read_range_first(mrr_cur_range.start_key.keypart_map ?
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2011-02-16 13:52:44 +0000
+++ b/sql/handler.h 2011-03-17 12:03:30 +0000
@@ -28,6 +28,7 @@
#include "thr_lock.h" /* thr_lock_type, THR_LOCK_DATA */
#include "sql_cache.h"
#include "structs.h" /* SHOW_COMP_OPTION */
+#include "opt_trace.h" // For Opt_trace_array
#include <my_global.h>
#include <my_handler.h>
@@ -1144,14 +1145,17 @@ typedef struct st_range_seq_if
SYNOPSIS
next()
- seq The value returned by RANGE_SEQ_IF::init()
- range OUT Information about the next range
+ seq The value returned by RANGE_SEQ_IF::init()
+ range OUT Information about the next range
+ trace_array Optimizer trace-related information is appended to this if
+ tracing is enabled. If NULL, no optimizer tracing is done
RETURN
0 - Ok, the range structure filled with info about the next range
1 - No more ranges
*/
- uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
+ uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *trace_array);
/*
Check whether range_info orders to skip the next record
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc 2011-02-16 15:06:06 +0000
+++ b/sql/opt_range.cc 2011-03-17 12:03:30 +0000
@@ -7969,13 +7969,17 @@ range_seq_t sel_arg_range_seq_init(void
return init_param;
}
-
-static void step_down_to(String *s, SEL_ARG_RANGE_SEQ *arg, SEL_ARG *key_tree)
+/**
+ @param trace_string Append range information for this part of the range
+ condition to this String if not NULL. Used by optimizer
+ trace
+*/
+static void step_down_to(String *trace_string,
+ SEL_ARG_RANGE_SEQ *arg, SEL_ARG *key_tree)
{
#ifdef OPTIMIZER_TRACE
- if (unlikely(arg->param->thd->opt_trace != NULL) &&
- arg->param->thd->opt_trace->is_started())
+ if (trace_string != NULL)
{
/*
Stepping down will append the range for the current keypart (in
@@ -7985,7 +7989,7 @@ static void step_down_to(String *s, SEL_
const KEY_PART_INFO *key_part=
arg->param->table->key_info[arg->real_keyno].key_part + key_tree->part;
- append_range(s, key_part,
+ append_range(trace_string, key_part,
key_tree->min_value, key_tree->max_value,
key_tree->min_flag | key_tree->max_flag);
}
@@ -8027,6 +8031,9 @@ static void step_down_to(String *s, SEL_
sel_arg_range_seq_next()
rseq Value returned from sel_arg_range_seq_init
range OUT Store information about the range here
+ trace_array Optimizer trace information about range boundaries are
+ appended to this if tracing is enabled. If NULL, no
+ optimizer tracing is done
DESCRIPTION
This is "get_next" function for Range sequence interface implementation
@@ -8044,12 +8051,24 @@ static void step_down_to(String *s, SEL_
*/
//psergey-merge-todo: support check_quick_keys:max_keypart
-uint sel_arg_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint sel_arg_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *trace_array)
{
SEL_ARG *key_tree;
SEL_ARG_RANGE_SEQ *seq= (SEL_ARG_RANGE_SEQ*)rseq;
String key_range_trace;
- key_range_trace.set_charset(system_charset_info);
+ //points to key_range_trace if doing tracing, NULL otherwise
+ String *active_trace_ptr= NULL;
+
+#ifdef OPTIMIZER_TRACE
+ if (unlikely(trace_array) &&
+ unlikely(seq->param->thd->opt_trace != NULL) &&
+ seq->param->thd->opt_trace->is_started())
+ {
+ key_range_trace.set_charset(system_charset_info);
+ active_trace_ptr= &key_range_trace;
+ }
+#endif
if (seq->at_start)
{
@@ -8066,7 +8085,7 @@ uint sel_arg_range_seq_next(range_seq_t
{
//step down; (update the tuple, we'll step right and stay there)
seq->i--;
- step_down_to(&key_range_trace, seq, key_tree->next);
+ step_down_to(active_trace_ptr, seq, key_tree->next);
key_tree= key_tree->next;
seq->param->is_ror_scan= FALSE;
goto walk_right_n_up;
@@ -8087,7 +8106,7 @@ uint sel_arg_range_seq_next(range_seq_t
{
// Step down; update the tuple
seq->i--;
- step_down_to(&key_range_trace, seq, key_tree->next);
+ step_down_to(active_trace_ptr, seq, key_tree->next);
key_tree= key_tree->next;
seq->param->is_ror_scan= FALSE;
break;
@@ -8128,15 +8147,14 @@ walk_right_n_up:
MAX_KEY);
#ifdef OPTIMIZER_TRACE
- if (unlikely(seq->param->thd->opt_trace != NULL) &&
- seq->param->thd->opt_trace->is_started())
+ if (unlikely(active_trace_ptr != NULL))
{
// Trace the range we just stored
KEY_PART_INFO *kpi=
seq->param->table->key_info[seq->real_keyno].key_part +
store_key_part->part;
- append_range(&key_range_trace, kpi,
+ append_range(active_trace_ptr, kpi,
store_key_part->min_value, store_key_part->max_value,
store_key_part->min_flag | store_key_part->max_flag);
}
@@ -8157,7 +8175,7 @@ walk_up_n_right:
/* Step up */
key_tree= key_tree->prev;
}
- step_down_to(&key_range_trace, seq, key_tree);
+ step_down_to(active_trace_ptr, seq, key_tree);
}
/* Ok got a tuple */
@@ -8219,22 +8237,8 @@ walk_up_n_right:
seq->param->range_count++;
seq->param->max_key_part=max(seq->param->max_key_part,key_tree->part);
-#ifdef OPTIMIZER_TRACE
- if (key_range_trace.length())
- {
- DBUG_ASSERT(seq->param->thd->opt_trace);
- DBUG_ASSERT(seq->param->thd->opt_trace->is_started());
- /*
- Should be Opt_trace_array, but don't cast because if it is
- Opt_trace_object a cast will crash the server while just
- add()'ing to Opt_trace_struct will cause a JSON syntax error
- for the optimizer trace (less severe)
- */
- Opt_trace_struct *trace_range=
- seq->param->thd->opt_trace->get_current_struct();
- trace_range->add_utf8(key_range_trace.ptr(), key_range_trace.length());
- }
-#endif
+ if (unlikely(active_trace_ptr != NULL) && active_trace_ptr->length())
+ trace_array->add_utf8(active_trace_ptr->ptr(), active_trace_ptr->length());
return 0;
}
@@ -9258,7 +9262,8 @@ range_seq_t quick_range_seq_init(void *i
1 No more ranges in the sequence
*/
-uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *unused)
{
QUICK_RANGE_SEQ_CTX *ctx= (QUICK_RANGE_SEQ_CTX*)rseq;
=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h 2011-02-16 13:52:44 +0000
+++ b/sql/opt_range.h 2011-03-17 12:03:30 +0000
@@ -394,7 +394,8 @@ typedef struct st_quick_range_seq_ctx
} QUICK_RANGE_SEQ_CTX;
range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags);
-uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
+uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *unused);
/*
=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc 2010-09-02 07:34:10 +0000
+++ b/sql/sql_join_cache.cc 2011-03-17 12:03:30 +0000
@@ -2169,7 +2169,8 @@ range_seq_t bka_range_seq_init(void *ini
*/
static
-uint bka_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint bka_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *unused)
{
DBUG_ENTER("bka_range_seq_next");
JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq;
@@ -2993,7 +2994,8 @@ range_seq_t bka_unique_range_seq_init(vo
*/
static
-uint bka_unique_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint bka_unique_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+ Opt_trace_array *unused)
{
DBUG_ENTER("bka_unique_range_seq_next");
JOIN_CACHE_BKA_UNIQUE *cache= (JOIN_CACHE_BKA_UNIQUE *) rseq;
Attachment: [text/bzr-bundle] bzr/jorgen.loland@oracle.com-20110317120330-m40fjnqjehz83mek.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (jorgen.loland:3279) | Jorgen Loland | 17 Mar |