#At file:///export/home/jl208045/mysql/wl4800/mysql-next-mr-opt-backporting-wl4800-patchcleanup/ based on revid:jorgen.loland@stripped
3235 Jorgen Loland 2010-11-22
WL#5594 - Add optimizer traces to the range optimizer
Minor changes as requested by reviewer.
@ sql/opt_range.cc
* print_key2 renamed to print_key_value. Function will now only print the range for a single key part, and length parameter is no longer needed.
* Create new scope for trace object and move object creation outside if() in get_best_ror_intersect()
modified:
sql/opt_range.cc
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc 2010-11-22 09:59:17 +0000
+++ b/sql/opt_range.cc 2010-11-22 13:22:03 +0000
@@ -809,8 +809,7 @@ static void print_quick(QUICK_SELECT_I *
#endif
static void append_range(String *out,
const KEY_PART_INFO *key_parts,
- const uchar *min_key, const uint16 min_length,
- const uchar *max_key, const uint16 max_length,
+ const uchar *min_key, const uchar *max_key,
const uint flag);
#endif
@@ -1977,10 +1976,8 @@ public:
@param[in] used_length Key tuple length
*/
static void
-print_key2(String *out, const KEY_PART_INFO *key_part, const uchar *key,
- uint used_length)
+print_key_value(String *out, const KEY_PART_INFO *key_part, const uchar *key)
{
- const uchar *key_end= key + used_length;
String tmp;
uint store_length;
TABLE *table= key_part->field->table;
@@ -1988,35 +1985,32 @@ print_key2(String *out, const KEY_PART_I
dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
- for (; key < key_end; key+= store_length, key_part++)
- {
- Field *field= key_part->field;
- store_length= key_part->store_length;
+ Field *field= key_part->field;
+ store_length= key_part->store_length;
- if (field->real_maybe_null())
+ if (field->real_maybe_null())
+ {
+ /*
+ Byte 0 of key is the null-byte. If set, key is NULL.
+ Otherwise, print the key value starting immediately after the
+ null-byte
+ */
+ if (*key)
{
- /*
- Byte 0 of key is the null-byte. If set, key is NULL.
- Otherwise, print the key value starting immediately after the
- null-byte
- */
- if (*key)
- {
- out->append(STRING_WITH_LEN("NULL"));
- continue;
- }
- key++; // Skip null byte
- store_length--;
+ out->append(STRING_WITH_LEN("NULL"));
+ goto restore_col_map;
}
- field->set_key_image(key, key_part->length);
- if (field->type() == MYSQL_TYPE_BIT)
- (void) field->val_int_as_str(&tmp, 1); // may change tmp's charset
- else
- field->val_str(&tmp); // may change tmp's charset
- out->append(tmp.ptr(), tmp.length(), tmp.charset());
- if (key + store_length < key_end)
- out->append('\'');
+ key++; // Skip null byte
+ store_length--;
}
+ field->set_key_image(key, key_part->length);
+ if (field->type() == MYSQL_TYPE_BIT)
+ (void) field->val_int_as_str(&tmp, 1); // may change tmp's charset
+ else
+ field->val_str(&tmp); // may change tmp's charset
+ out->append(tmp.ptr(), tmp.length(), tmp.charset());
+
+restore_col_map:
dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
}
@@ -2081,8 +2075,7 @@ public:
{
const KEY_PART_INFO *cur_key_part= key_part + part->part;
append_range(&range_info, cur_key_part,
- part->min_value, cur_key_part->length,
- part->max_value, cur_key_part->length,
+ part->min_value, part->max_value,
part->min_flag | part->max_flag);
}
trace_range.add_str(range_info.ptr(), range_info.length());
@@ -2168,8 +2161,7 @@ public:
{
const KEY_PART_INFO *cur_key_part= key_part + part->part;
append_range(&range_info, cur_key_part,
- part->min_value, cur_key_part->length,
- part->max_value, cur_key_part->length,
+ part->min_value, part->max_value,
part->min_flag | part->max_flag);
}
trace_range.add_str(range_info.ptr(), range_info.length());
@@ -2324,8 +2316,7 @@ public:
{
const KEY_PART_INFO *cur_key_part= key_part + part->part;
append_range(&range_info, cur_key_part,
- part->min_value, cur_key_part->length,
- part->max_value, cur_key_part->length,
+ part->min_value, part->max_value,
part->min_flag | part->max_flag);
}
trace_range.add_str(range_info.ptr(), range_info.length());
@@ -5084,29 +5075,29 @@ TRP_ROR_INTERSECT *get_best_ror_intersec
Check if we should add a CPK scan. If the obtained ROR-intersection is
covering, it doesn't make sense to add CPK scan.
*/
- if (cpk_scan && !intersect->is_covering)
- {
- if (ror_intersect_add(intersect, cpk_scan, TRUE) &&
- (intersect->total_cost < min_cost))
+ { // Scope for trace object
+ Opt_trace_object trace_cpk(param->thd->opt_trace, "clustered_pk");
+ if (cpk_scan && !intersect->is_covering)
{
- Opt_trace_object (param->thd->opt_trace, "clustered_pk").
- add("clustered_pk_scan_added_to_intersect", true).
- add("cumulated_cost", intersect->total_cost);
- cpk_scan_used= TRUE;
- intersect_best= intersect; //just set pointer here
+ if (ror_intersect_add(intersect, cpk_scan, TRUE) &&
+ (intersect->total_cost < min_cost))
+ {
+ trace_cpk.add("clustered_pk_scan_added_to_intersect", true).
+ add("cumulated_cost", intersect->total_cost);
+ cpk_scan_used= TRUE;
+ intersect_best= intersect; //just set pointer here
+ }
+ else
+ trace_cpk.add("clustered_pk_added_to_intersect", false).
+ add_str("cause", "cost");
}
else
- Opt_trace_object (param->thd->opt_trace, "clustered_pk").
- add("clustered_pk_added_to_intersect", false).add_str("cause", "cost");
- }
- else
- {
- Opt_trace_object trace_cpk(param->thd->opt_trace, "clustered_pk");
- trace_cpk.add("clustered_pk_added_to_intersect", false).
- add_str("cause", cpk_scan ?
- "roworder_is_covering" : "no_clustered_pk_index");
+ {
+ trace_cpk.add("clustered_pk_added_to_intersect", false).
+ add_str("cause", cpk_scan ?
+ "roworder_is_covering" : "no_clustered_pk_index");
+ }
}
-
/* Ok, return ROR-intersect plan if we have found one */
TRP_ROR_INTERSECT *trp= NULL;
if (min_cost < read_time && (cpk_scan_used || best_num > 1))
@@ -8031,10 +8022,8 @@ 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;
- uint16 length= key_part->length;
append_range(s, key_part,
- key_tree->min_value, length,
- key_tree->max_value, length,
+ key_tree->min_value, key_tree->max_value,
key_tree->min_flag | key_tree->max_flag);
}
#endif
@@ -8184,10 +8173,8 @@ walk_right_n_up:
seq->param->table->key_info[seq->real_keyno].key_part +
store_key_part->part;
- uint16 length= kpi->length;
append_range(&key_range_trace, kpi,
- store_key_part->min_value, length,
- store_key_part->max_value, length,
+ store_key_part->min_value, store_key_part->max_value,
store_key_part->min_flag | store_key_part->max_flag);
}
#endif
@@ -12340,21 +12327,18 @@ static void print_ror_scans_arr(TABLE *t
#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
/**
- Append range info to a string
+ Append range info for a key part to a string
@param[in,out] out String the range info is appended to
- @param[in] key_parts Index components description
+ @param[in] key_part Indexed column used in a range select
@param[in] min_key Key tuple describing lower bound of range
- @param[in] min_length Length of min_key
@param[in] max_key Key tuple describing upper bound of range
- @param[in] max_length Length of max_key
@param[in] flag Key range flags defining what min_key
and max_key represent @see my_base.h
*/
static void append_range(String *out,
- const KEY_PART_INFO *key_parts,
- const uchar *min_key, const uint16 min_length,
- const uchar *max_key, const uint16 max_length,
+ const KEY_PART_INFO *key_part,
+ const uchar *min_key, const uchar *max_key,
const uint flag)
{
if (out->length() > 0)
@@ -12362,14 +12346,14 @@ static void append_range(String *out,
if (!(flag & NO_MIN_RANGE))
{
- print_key2(out, key_parts, min_key, min_length);
+ print_key_value(out, key_part, min_key);
if (flag & NEAR_MIN)
out->append(STRING_WITH_LEN(" < "));
else
out->append(STRING_WITH_LEN(" <= "));
}
- out->append(key_parts->field->field_name);
+ out->append(key_part->field->field_name);
if (!(flag & NO_MAX_RANGE))
{
@@ -12377,7 +12361,7 @@ static void append_range(String *out,
out->append(STRING_WITH_LEN(" < "));
else
out->append(STRING_WITH_LEN(" <= "));
- print_key2(out, key_parts, max_key, max_length);
+ print_key_value(out, key_part, max_key);
}
}
@@ -12429,9 +12413,8 @@ void QUICK_RANGE_SELECT::dbug_dump(int i
range_info.set_charset(system_charset_info);
range= *pr;
append_range(&range_info, head->key_info[index].key_part,
- range->min_key, range->min_length,
- range->max_key, range->max_length,
- range->flag);
+ range->min_key, range->max_key,
+ range->flag);
trace_range.add_str(range_info.ptr(), range_info.length());
}
}
Attachment: [text/bzr-bundle] bzr/jorgen.loland@oracle.com-20101122132203-qvrxzu56p4qtczhd.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3235) WL#5594 | Jorgen Loland | 22 Nov |