1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MariaDB 5.2 -> MariaDB 5.3 merge

This commit is contained in:
Sergey Petrunya
2010-06-26 14:05:41 +04:00
2077 changed files with 1016246 additions and 14858 deletions

View File

@ -762,8 +762,7 @@ TRP_ROR_INTERSECT *get_best_covering_ror_intersect(PARAM *param,
static
TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
double read_time);
static
TRP_GROUP_MIN_MAX *get_best_group_min_max(PARAM *param, SEL_TREE *tree);
static TRP_GROUP_MIN_MAX *get_best_group_min_max(PARAM *param, SEL_TREE *tree);
#ifndef DBUG_OFF
static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map,
@ -1156,7 +1155,10 @@ QUICK_SELECT_I::QUICK_SELECT_I()
QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr,
bool no_alloc, MEM_ROOT *parent_alloc,
bool *create_error)
:free_file(0),cur_range(NULL),last_range(0),dont_free(0)
:dont_free(0),doing_key_read(0),/*error(0),*/free_file(0),/*in_range(0),*/cur_range(NULL),last_range(0)
//psergey3-merge: check whether we need doing_key_read and last_range
// was:
// :free_file(0),cur_range(NULL),last_range(0),dont_free(0)
{
my_bitmap_map *bitmap;
DBUG_ENTER("QUICK_RANGE_SELECT::QUICK_RANGE_SELECT");
@ -1237,11 +1239,8 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
if (file)
{
range_end();
if (head->key_read)
{
head->key_read= 0;
if (doing_key_read)
file->extra(HA_EXTRA_NO_KEYREAD);
}
if (free_file)
{
DBUG_PRINT("info", ("Freeing separate handler 0x%lx (free: %d)", (long) file,
@ -1380,6 +1379,7 @@ int QUICK_ROR_INTERSECT_SELECT::init()
int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler)
{
handler *save_file= file, *org_file;
my_bool org_key_read;
THD *thd;
DBUG_ENTER("QUICK_RANGE_SELECT::init_ror_merged_scan");
@ -1439,15 +1439,17 @@ end:
The now bitmap is stored in 'column_bitmap' which is used in ::get_next()
*/
org_file= head->file;
org_key_read= head->key_read;
head->file= file;
/* We don't have to set 'head->keyread' here as the 'file' is unique */
head->key_read= 0;
if (!head->no_keyread)
{
head->key_read= 1;
doing_key_read= 1;
head->mark_columns_used_by_index(index);
}
head->prepare_for_position();
head->file= org_file;
head->key_read= org_key_read;
bitmap_copy(&column_bitmap, head->read_set);
head->column_bitmaps_set(&column_bitmap, &column_bitmap);
@ -2384,10 +2386,9 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if (!head->covering_keys.is_clear_all())
{
int key_for_use= find_shortest_key(head, &head->covering_keys);
double key_read_time=
param.table->file->index_only_read_time(key_for_use,
rows2double(records)) +
(double) records / TIME_FOR_COMPARE;
double key_read_time= param.table->file->keyread_read_time(key_for_use,
1, records) +
(double) records / TIME_FOR_COMPARE;
DBUG_PRINT("info", ("'all'+'using index' scan will be using key %d, "
"read time %g", key_for_use, key_read_time));
if (key_read_time < read_time)
@ -4086,7 +4087,7 @@ ROR_SCAN_INFO *make_ror_scan(const PARAM *param, int idx, SEL_ARG *sel_arg)
}
double rows= rows2double(param->table->quick_rows[ror_scan->keynr]);
ror_scan->index_read_cost=
param->table->file->index_only_read_time(ror_scan->keynr, rows);
param->table->file->keyread_read_time(ror_scan->keynr, 1, rows);
DBUG_RETURN(ror_scan);
}
@ -4916,6 +4917,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
}
if (found_records != HA_POS_ERROR &&
read_time > (found_read_time= cost.total_cost()))
{
read_time= found_read_time;
best_records= found_records;
@ -8039,12 +8041,15 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
List_iterator_fast<QUICK_RANGE_SELECT> cur_quick_it(quick_selects);
QUICK_RANGE_SELECT* cur_quick;
int result;
Unique *unique;
Unique *unique= 0;
handler *file= head->file;
DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge");
/* We're going to just read rowids. */
file->extra(HA_EXTRA_KEYREAD);
if (!head->key_read)
{
head->enable_keyread();
}
head->prepare_for_position();
cur_quick_it.rewind();
@ -8056,13 +8061,13 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
reset here.
*/
if (cur_quick->init() || cur_quick->reset())
DBUG_RETURN(1);
goto err;
unique= new Unique(refpos_order_cmp, (void *)file,
file->ref_length,
thd->variables.sortbuff_size);
if (!unique)
DBUG_RETURN(1);
goto err;
for (;;)
{
while ((result= cur_quick->get_next()) == HA_ERR_END_OF_FILE)
@ -8075,10 +8080,7 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
if (cur_quick->file->inited != handler::NONE)
cur_quick->file->ha_index_end();
if (cur_quick->init() || cur_quick->reset())
{
delete unique;
DBUG_RETURN(1);
}
goto err;
}
if (result)
@ -8086,29 +8088,21 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
if (result != HA_ERR_END_OF_FILE)
{
cur_quick->range_end();
delete unique;
DBUG_RETURN(result);
goto err;
}
break;
}
if (thd->killed)
{
delete unique;
DBUG_RETURN(1);
}
goto err;
/* skip row if it will be retrieved by clustered PK scan */
if (pk_quick_select && pk_quick_select->row_in_ranges())
continue;
cur_quick->file->position(cur_quick->record);
result= unique->unique_add((char*)cur_quick->file->ref);
if (result)
{
delete unique;
DBUG_RETURN(1);
}
if (unique->unique_add((char*)cur_quick->file->ref))
goto err;
}
/*
@ -8119,10 +8113,17 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_and_merge()
result= unique->get(head);
delete unique;
doing_pk_scan= FALSE;
/* index_merge currently doesn't support "using index" at all */
file->extra(HA_EXTRA_NO_KEYREAD);
/*
index_merge currently doesn't support "using index" at all
*/
head->disable_keyread();
init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1 , 1, TRUE);
DBUG_RETURN(result);
err:
delete unique;
head->disable_keyread();
DBUG_RETURN(1);
}
@ -10115,7 +10116,7 @@ QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join_arg, bool have_min_arg,
:join(join_arg), index_info(index_info_arg),
group_prefix_len(group_prefix_len_arg),
group_key_parts(group_key_parts_arg), have_min(have_min_arg),
have_max(have_max_arg), seen_first_key(FALSE),
have_max(have_max_arg), seen_first_key(FALSE), doing_key_read(FALSE),
min_max_arg_part(min_max_arg_part_arg), key_infix(key_infix_arg),
key_infix_len(key_infix_len_arg), min_functions_it(NULL),
max_functions_it(NULL)
@ -10246,7 +10247,12 @@ QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT()
{
DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT");
if (file->inited != handler::NONE)
{
DBUG_ASSERT(file == head->file);
if (doing_key_read)
head->disable_keyread();
file->ha_index_end();
}
if (min_max_arg_part)
delete_dynamic(&min_max_ranges);
free_root(&alloc,MYF(0));
@ -10429,7 +10435,11 @@ int QUICK_GROUP_MIN_MAX_SELECT::reset(void)
int result;
DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::reset");
file->extra(HA_EXTRA_KEYREAD); /* We need only the key attributes */
if (!head->key_read)
{
doing_key_read= 1;
head->enable_keyread(); /* We need only the key attributes */
}
if ((result= file->ha_index_init(index,1)))
DBUG_RETURN(result);
if (quick_prefix_select && quick_prefix_select->reset())