mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge from 5.0-bugteam
This commit is contained in:
@ -1350,7 +1350,7 @@ JOIN::optimize()
|
||||
join_tab[const_tables].type != JT_ALL &&
|
||||
join_tab[const_tables].type != JT_FT &&
|
||||
join_tab[const_tables].type != JT_REF_OR_NULL &&
|
||||
(order && simple_order || group_list && simple_group))
|
||||
((order && simple_order) || (group_list && simple_group)))
|
||||
{
|
||||
if (add_ref_to_table_cond(thd,&join_tab[const_tables])) {
|
||||
DBUG_RETURN(1);
|
||||
@ -1868,9 +1868,9 @@ JOIN::exec()
|
||||
like SEC_TO_TIME(SUM(...)).
|
||||
*/
|
||||
|
||||
if (curr_join->group_list && (!test_if_subpart(curr_join->group_list,
|
||||
if ((curr_join->group_list && (!test_if_subpart(curr_join->group_list,
|
||||
curr_join->order) ||
|
||||
curr_join->select_distinct) ||
|
||||
curr_join->select_distinct)) ||
|
||||
(curr_join->select_distinct &&
|
||||
curr_join->tmp_table_param.using_indirect_summary_function))
|
||||
{ /* Must copy to another table */
|
||||
@ -2344,9 +2344,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (err= join->prepare(rref_pointer_array, tables, wild_num,
|
||||
conds, og_num, order, group, having, proc_param,
|
||||
select_lex, unit))
|
||||
err= join->prepare(rref_pointer_array, tables, wild_num,
|
||||
conds, og_num, order, group, having, proc_param,
|
||||
select_lex, unit);
|
||||
if (err)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
@ -2361,9 +2362,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
|
||||
DBUG_RETURN(TRUE);
|
||||
thd_proc_info(thd, "init");
|
||||
thd->used_tables=0; // Updated by setup_fields
|
||||
if (err= join->prepare(rref_pointer_array, tables, wild_num,
|
||||
conds, og_num, order, group, having, proc_param,
|
||||
select_lex, unit))
|
||||
err= join->prepare(rref_pointer_array, tables, wild_num,
|
||||
conds, og_num, order, group, having, proc_param,
|
||||
select_lex, unit);
|
||||
if (err)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
@ -3841,7 +3843,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
|
||||
if (use->key == prev->key && use->table == prev->table)
|
||||
{
|
||||
if (prev->keypart+1 < use->keypart ||
|
||||
prev->keypart == use->keypart && found_eq_constant)
|
||||
(prev->keypart == use->keypart && found_eq_constant))
|
||||
continue; /* remove */
|
||||
}
|
||||
else if (use->keypart != 0) // First found must be 0
|
||||
@ -5146,8 +5148,8 @@ best_extension_by_limited_search(JOIN *join,
|
||||
{
|
||||
if (best_record_count > current_record_count ||
|
||||
best_read_time > current_read_time ||
|
||||
idx == join->const_tables && // 's' is the first table in the QEP
|
||||
s->table == join->sort_by_table)
|
||||
(idx == join->const_tables && // 's' is the first table in the QEP
|
||||
s->table == join->sort_by_table))
|
||||
{
|
||||
if (best_record_count >= current_record_count &&
|
||||
best_read_time >= current_read_time &&
|
||||
@ -5273,7 +5275,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
|
||||
double current_read_time=read_time+best;
|
||||
if (best_record_count > current_record_count ||
|
||||
best_read_time > current_read_time ||
|
||||
idx == join->const_tables && s->table == join->sort_by_table)
|
||||
(idx == join->const_tables && s->table == join->sort_by_table))
|
||||
{
|
||||
if (best_record_count >= current_record_count &&
|
||||
best_read_time >= current_read_time &&
|
||||
@ -6220,8 +6222,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
|
||||
the index if we are using limit and this is the first table
|
||||
*/
|
||||
|
||||
if (cond &&
|
||||
(!tab->keys.is_subset(tab->const_keys) && i > 0) ||
|
||||
if ((cond &&
|
||||
!tab->keys.is_subset(tab->const_keys) && i > 0) ||
|
||||
(!tab->const_keys.is_clear_all() && i == join->const_tables &&
|
||||
join->unit->select_limit_cnt <
|
||||
join->best_positions[i].records_read &&
|
||||
@ -7354,7 +7356,7 @@ static bool check_simple_equality(Item *left_item, Item *right_item,
|
||||
left_item_equal->merge(right_item_equal);
|
||||
/* Remove the merged multiple equality from the list */
|
||||
List_iterator<Item_equal> li(cond_equal->current_level);
|
||||
while ((li++) != right_item_equal);
|
||||
while ((li++) != right_item_equal) ;
|
||||
li.remove();
|
||||
}
|
||||
}
|
||||
@ -10032,9 +10034,9 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
||||
reclength=1; // Dummy select
|
||||
/* Use packed rows if there is blobs or a lot of space to gain */
|
||||
if (blob_count ||
|
||||
string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS &&
|
||||
(string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS &&
|
||||
(reclength / string_total_length <= RATIO_TO_PACK_ROWS ||
|
||||
string_total_length / string_count >= AVG_STRING_LENGTH_TO_PACK_ROWS))
|
||||
string_total_length / string_count >= AVG_STRING_LENGTH_TO_PACK_ROWS)))
|
||||
use_packed_rows= 1;
|
||||
|
||||
share->reclength= reclength;
|
||||
@ -10835,9 +10837,8 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
|
||||
{
|
||||
int rc= 0;
|
||||
enum_nested_loop_state error= NESTED_LOOP_OK;
|
||||
JOIN_TAB *join_tab;
|
||||
JOIN_TAB *join_tab= NULL;
|
||||
DBUG_ENTER("do_select");
|
||||
LINT_INIT(join_tab);
|
||||
|
||||
join->procedure=procedure;
|
||||
join->tmp_table= table; /* Save for easy recursion */
|
||||
@ -13076,9 +13077,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
|
||||
*/
|
||||
uint nr;
|
||||
key_map keys;
|
||||
uint best_key_parts;
|
||||
int best_key_direction;
|
||||
ha_rows best_records;
|
||||
uint best_key_parts= 0;
|
||||
int best_key_direction= 0;
|
||||
ha_rows best_records= 0;
|
||||
double read_time;
|
||||
int best_key= -1;
|
||||
bool is_best_covering= FALSE;
|
||||
@ -13088,9 +13089,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
|
||||
ha_rows table_records= table->file->stats.records;
|
||||
bool group= join->group && order == join->group_list;
|
||||
ha_rows ref_key_quick_rows= HA_POS_ERROR;
|
||||
LINT_INIT(best_key_parts);
|
||||
LINT_INIT(best_key_direction);
|
||||
LINT_INIT(best_records);
|
||||
|
||||
/*
|
||||
If not used with LIMIT, only use keys if the whole query can be
|
||||
@ -13135,8 +13133,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
|
||||
(direction= test_if_order_by_key(order, table, nr, &used_key_parts)))
|
||||
{
|
||||
bool is_covering= table->covering_keys.is_set(nr) ||
|
||||
nr == table->s->primary_key &&
|
||||
table->file->primary_key_is_clustered();
|
||||
(nr == table->s->primary_key &&
|
||||
table->file->primary_key_is_clustered());
|
||||
|
||||
/*
|
||||
Don't use an index scan with ORDER BY without limit.
|
||||
@ -13149,7 +13147,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
|
||||
*/
|
||||
if (is_covering ||
|
||||
select_limit != HA_POS_ERROR ||
|
||||
ref_key < 0 && (group || table->force_index))
|
||||
(ref_key < 0 && (group || table->force_index)))
|
||||
{
|
||||
double rec_per_key;
|
||||
double index_scan_time;
|
||||
@ -13215,12 +13213,12 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
|
||||
index_scan_time= select_limit/rec_per_key *
|
||||
min(rec_per_key, table->file->scan_time());
|
||||
if (is_covering ||
|
||||
ref_key < 0 && (group || table->force_index) ||
|
||||
(ref_key < 0 && (group || table->force_index)) ||
|
||||
index_scan_time < read_time)
|
||||
{
|
||||
ha_rows quick_records= table_records;
|
||||
if (is_best_covering && !is_covering ||
|
||||
is_covering && ref_key_quick_rows < select_limit)
|
||||
if ((is_best_covering && !is_covering) ||
|
||||
(is_covering && ref_key_quick_rows < select_limit))
|
||||
continue;
|
||||
if (table->quick_keys.is_set(nr))
|
||||
quick_records= table->quick_rows[nr];
|
||||
@ -13428,8 +13426,8 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
|
||||
*/
|
||||
if ((order != join->group_list ||
|
||||
!(join->select_options & SELECT_BIG_RESULT) ||
|
||||
select && select->quick &&
|
||||
select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX) &&
|
||||
(select && select->quick &&
|
||||
select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)) &&
|
||||
test_if_skip_sort_order(tab,order,select_limit,0,
|
||||
is_order_by ? &table->keys_in_use_for_order_by :
|
||||
&table->keys_in_use_for_group_by))
|
||||
@ -14270,8 +14268,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
|
||||
/* Lookup the current GROUP field in the FROM clause. */
|
||||
order_item_type= order_item->type();
|
||||
from_field= (Field*) not_found_field;
|
||||
if (is_group_field &&
|
||||
order_item_type == Item::FIELD_ITEM ||
|
||||
if ((is_group_field &&
|
||||
order_item_type == Item::FIELD_ITEM) ||
|
||||
order_item_type == Item::REF_ITEM)
|
||||
{
|
||||
from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables,
|
||||
@ -14706,7 +14704,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables)
|
||||
if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
|
||||
DBUG_RETURN(0);
|
||||
|
||||
for (; !(map & tables->table->map); tables= tables->next_leaf);
|
||||
for (; !(map & tables->table->map); tables= tables->next_leaf) ;
|
||||
if (map != tables->table->map)
|
||||
DBUG_RETURN(0); // More than one table
|
||||
DBUG_PRINT("exit",("sort by table: %d",tables->table->tablenr));
|
||||
|
Reference in New Issue
Block a user