1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Merged 5.1 with maria 5.1

This commit is contained in:
Michael Widenius
2008-10-10 18:28:41 +03:00
1924 changed files with 487105 additions and 167345 deletions

View File

@ -856,6 +856,7 @@ JOIN::optimize()
"Impossible HAVING" : "Impossible WHERE"));
zero_result_cause= having_value == Item::COND_FALSE ?
"Impossible HAVING" : "Impossible WHERE";
tables= 0;
error= 0;
DBUG_RETURN(0);
}
@ -897,6 +898,7 @@ JOIN::optimize()
{
DBUG_PRINT("info",("No matching min/max row"));
zero_result_cause= "No matching min/max row";
tables= 0;
error=0;
DBUG_RETURN(0);
}
@ -910,6 +912,7 @@ JOIN::optimize()
{
DBUG_PRINT("info",("No matching min/max row"));
zero_result_cause= "No matching min/max row";
tables= 0;
error=0;
DBUG_RETURN(0);
}
@ -1804,7 +1807,8 @@ JOIN::exec()
if (!items1)
{
items1= items0 + all_fields.elements;
if (sort_and_group || curr_tmp_table->group)
if (sort_and_group || curr_tmp_table->group ||
tmp_table_param.precomputed_group_by)
{
if (change_to_use_tmp_fields(thd, items1,
tmp_fields_list1, tmp_all_fields1,
@ -2210,11 +2214,12 @@ JOIN::exec()
/*
With EXPLAIN EXTENDED we have to restore original ref_array
for a derived table which is always materialized.
Otherwise we would not be able to print the query correctly.
We also need to do this when we have temp table(s).
Otherwise we would not be able to print the query correctly.
*/
if (items0 &&
(thd->lex->describe & DESCRIBE_EXTENDED) &&
select_lex->linkage == DERIVED_TABLE_TYPE)
if (items0 && (thd->lex->describe & DESCRIBE_EXTENDED) &&
(select_lex->linkage == DERIVED_TABLE_TYPE ||
exec_tmp_table1 || exec_tmp_table2))
set_items_ref_array(items0);
DBUG_VOID_RETURN;
@ -6528,13 +6533,16 @@ make_join_readinfo(JOIN *join, ulonglong options)
!(tab->select && tab->select->quick))
{ // Only read index tree
/*
See bug #26447: "Using the clustered index for a table scan
is always faster than using a secondary index".
*/
It has turned out that the below change, while speeding things
up for disk-bound loads, slows them down for cases when the data
is in disk cache (see BUG#35850):
// See bug #26447: "Using the clustered index for a table scan
// is always faster than using a secondary index".
if (table->s->primary_key != MAX_KEY &&
table->file->primary_key_is_clustered())
tab->index= table->s->primary_key;
else
*/
tab->index=find_shortest_key(table, & table->covering_keys);
tab->read_first_record= join_read_first;
tab->type=JT_NEXT; // Read with index_first / index_next
@ -6770,6 +6778,12 @@ void JOIN::cleanup(bool full)
if (tmp_join)
tmp_table_param.copy_field= 0;
group_fields.delete_elements();
/*
Ensure that the above delete_elements() would not be called
twice for the same list.
*/
if (tmp_join && tmp_join != this)
tmp_join->group_fields= group_fields;
/*
We can't call delete_elements() on copy_funcs as this will cause
problems in free_elements() as some of the elements are then deleted.
@ -9638,6 +9652,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
ENGINE_COLUMNDEF *recinfo;
uint total_uneven_bit_length= 0;
bool force_copy_fields= param->force_copy_fields;
/* Treat sum functions as normal ones when loose index scan is used. */
save_sum_fields|= param->precomputed_group_by;
DBUG_ENTER("create_tmp_table");
DBUG_PRINT("enter",
("distinct: %d save_sum_fields: %d rows_limit: %lu group: %d",
@ -11895,7 +11911,7 @@ join_init_read_record(JOIN_TAB *tab)
if (tab->select && tab->select->quick && tab->select->quick->reset())
return 1;
init_read_record(&tab->read_record, tab->join->thd, tab->table,
tab->select,1,1);
tab->select,1,1, FALSE);
return (*tab->read_record.read_record)(&tab->read_record);
}
@ -12690,6 +12706,9 @@ part_of_refkey(TABLE *table,Field *field)
@note
used_key_parts is set to correct key parts used if return value != 0
(On other cases, used_key_part may be changed)
Note that the value may actually be greater than the number of index
key parts. This can happen for storage engines that have the primary
key parts as a suffix for every secondary key.
@retval
1 key is ok.
@ -12762,11 +12781,27 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
reverse=flag; // Remember if reverse
key_part++;
}
*used_key_parts= on_primary_key ? table->key_info[idx].key_parts :
(uint) (key_part - table->key_info[idx].key_part);
if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) &
HA_READ_PREV))
reverse= 0; // Index can't be used
if (on_primary_key)
{
uint used_key_parts_secondary= table->key_info[idx].key_parts;
uint used_key_parts_pk=
(uint) (key_part - table->key_info[table->s->primary_key].key_part);
*used_key_parts= used_key_parts_pk + used_key_parts_secondary;
if (reverse == -1 &&
(!(table->file->index_flags(idx, used_key_parts_secondary - 1, 1) &
HA_READ_PREV) ||
!(table->file->index_flags(table->s->primary_key,
used_key_parts_pk - 1, 1) & HA_READ_PREV)))
reverse= 0; // Index can't be used
}
else
{
*used_key_parts= (uint) (key_part - table->key_info[idx].key_part);
if (reverse == -1 &&
!(table->file->index_flags(idx, *used_key_parts-1, 1) & HA_READ_PREV))
reverse= 0; // Index can't be used
}
DBUG_RETURN(reverse);
}
@ -13155,6 +13190,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
uint tablenr= tab - join->join_tab;
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);
@ -13188,6 +13224,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
else
keys= usable_keys;
if (ref_key >= 0 && table->covering_keys.is_set(ref_key))
ref_key_quick_rows= table->quick_rows[ref_key];
read_time= join->best_positions[tablenr].read_time;
for (uint i= tablenr+1; i < join->tables; i++)
fanout*= join->best_positions[i].records_read; // fanout is always >= 1
@ -13282,7 +13321,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
index_scan_time < read_time)
{
ha_rows quick_records= table_records;
if (is_best_covering && !is_covering)
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];
@ -13334,6 +13374,16 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
table->key_read=1;
table->file->extra(HA_EXTRA_KEYREAD);
}
else if (table->key_read)
{
/*
Clear the covering key read flags that might have been
previously set for some key other than the current best_key.
*/
table->key_read= 0;
table->file->extra(HA_EXTRA_NO_KEYREAD);
}
table->file->ha_index_or_rnd_end();
if (join->select_options & SELECT_DESCRIBE)
{
@ -13356,6 +13406,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
tab->ref.key= -1;
tab->ref.key_parts=0; // Don't use ref key.
tab->read_first_record= join_init_read_record;
if (tab->is_using_loose_index_scan())
join->tmp_table_param.precomputed_group_by= TRUE;
/*
TODO: update the number of records in join->best_positions[tablenr]
*/