From: Date: November 24 2005 10:54am Subject: bk commit into 5.0 tree (sergefp:1.1999) BUG#14940 List-Archive: http://lists.mysql.com/internals/32652 X-Bug: 14940 Message-Id: <20051124095453.DC88537B89@newbox.mylan> Below is the list of changes that have just been committed into a local 5.0 repository of psergey. When psergey does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.1999 05/11/24 12:54:46 sergefp@stripped +2 -0 BUG#14940 part1: When evaluating cost of using one of indexes in union-index_merge, don't save the received #records estimate as full cost of accessing the entire table. sql/table.h 1.120 05/11/24 12:54:40 sergefp@stripped +7 -1 Added comments. sql/opt_range.cc 1.199 05/11/24 12:54:40 sergefp@stripped +22 -10 BUG#14940 part1: When evaluating cost of using one of indexes in union-index_merge, don't save the received #records estimate as full cost of accessing the entire table. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: sergefp # Host: newbox.mylan # Root: /home/psergey/mysql-5.0-csc4856-r4 --- 1.198/sql/opt_range.cc 2005-11-20 21:47:00 +03:00 +++ 1.199/sql/opt_range.cc 2005-11-24 12:54:40 +03:00 @@ -369,7 +369,8 @@ static SEL_TREE *get_mm_tree(PARAM *param,COND *cond); static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts); -static ha_rows check_quick_select(PARAM *param,uint index,SEL_ARG *key_tree); +static ha_rows check_quick_select(PARAM *param,uint index,SEL_ARG *key_tree, + bool update_tbl_stats); static ha_rows check_quick_keys(PARAM *param,uint index,SEL_ARG *key_tree, char *min_key,uint min_key_flag, char *max_key, uint max_key_flag); @@ -3231,7 +3232,8 @@ bool read_index_only= index_read_must_be_used ? TRUE : (bool) param->table->used_keys.is_set(keynr); - found_records= check_quick_select(param, idx, *key); + found_records= check_quick_select(param, idx, *key, + !index_read_must_be_used); if (param->is_ror_scan) { tree->n_ror_scans++; @@ -5150,10 +5152,13 @@ scan on given index using given SEL_ARG intervals tree. SYNOPSIS check_quick_select - param Parameter from test_quick_select - idx Number of index to use in PARAM::key SEL_TREE::key - tree Transformed selection condition, tree->key[idx] holds intervals - tree to be used for scanning. + param Parameter from test_quick_select + idx Number of index to use in tree->keys + tree Transformed selection condition, tree->keys[idx] + holds the range tree to be used for scanning. + update_tbl_stats If true, update table->quick_keys with information + about range scan we've evaluated. + NOTES param->is_ror_scan is set to reflect if the key scan is a ROR (see is_key_scan_ror function for more info) @@ -5167,7 +5172,7 @@ */ static ha_rows -check_quick_select(PARAM *param,uint idx,SEL_ARG *tree) +check_quick_select(PARAM *param,uint idx,SEL_ARG *tree, bool update_tbl_stats) { ha_rows records; bool cpk_scan; @@ -5207,9 +5212,16 @@ records=check_quick_keys(param,idx,tree,param->min_key,0,param->max_key,0); if (records != HA_POS_ERROR) { - param->table->quick_keys.set_bit(key); + if (update_tbl_stats) + { + param->table->quick_keys.set_bit(key); + param->table->quick_key_parts[key]=param->max_key_part+1; + } + /* + Need to save quick_rows in any case as it is used when calculating + cost of ROR intersection: + */ param->table->quick_rows[key]=records; - param->table->quick_key_parts[key]=param->max_key_part+1; if (cpk_scan) param->is_ror_scan= TRUE; @@ -7301,7 +7313,7 @@ &cur_param_idx); /* Check if this range tree can be used for prefix retrieval. */ cur_quick_prefix_records= check_quick_select(param, cur_param_idx, - cur_index_tree); + cur_index_tree, TRUE); } cost_group_min_max(table, cur_index_info, used_key_parts, cur_group_key_parts, tree, cur_index_tree, --- 1.119/sql/table.h 2005-11-03 16:21:19 +03:00 +++ 1.120/sql/table.h 2005-11-24 12:54:40 +03:00 @@ -216,9 +216,15 @@ uchar *null_flags; query_id_t query_id; + /* + For each key that has quick_keys.is_set(key) == TRUE: estimate of #records + and max #key parts that range access would use. + */ ha_rows quick_rows[MAX_KEY]; - key_part_map const_key_parts[MAX_KEY]; uint quick_key_parts[MAX_KEY]; + + /* Bitmaps of key parts that =const for the entire join. */ + key_part_map const_key_parts[MAX_KEY]; /* If this table has TIMESTAMP field with auto-set property (pointed by