1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-18 07:48:43 +03:00

Merge bk@192.168.21.1:mysql-5.1

into  mysql.com:/d2/hf/mrg/mysql-5.1-opt
This commit is contained in:
holyfoot/hf@hfmain.(none)
2007-05-18 20:04:01 +05:00
28 changed files with 788 additions and 243 deletions

View File

@@ -3558,7 +3558,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
prev_subselect_item->const_item_cache= 0;
set_field(*from_field);
if (!last_checked_context->select_lex->having_fix_field &&
select->group_list.elements)
select->group_list.elements &&
(place == SELECT_LIST || place == IN_HAVING))
{
Item_outer_ref *rf;
/*

View File

@@ -690,7 +690,13 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
if (cmp_type != CMP_DATE_DFLT)
{
if (cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item())
/*
Do not cache GET_USER_VAR() function as its const_item() may return TRUE
for the current thread but it still may change during the execution.
*/
if (cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item() &&
(str_arg->type() != Item::FUNC_ITEM ||
((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
{
THD *thd= current_thd;
ulonglong value;
@@ -718,7 +724,7 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
Item_result type)
{
enum enum_date_cmp_type cmp_type;
ulonglong const_value;
ulonglong const_value= (ulonglong)-1;
a= a1;
b= a2;
@@ -731,8 +737,7 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
a_cache= 0;
b_cache= 0;
if (cmp_type != CMP_DATE_WITH_DATE &&
((*b)->const_item() || (*a)->const_item()))
if (const_value != (ulonglong)-1)
{
Item_cache_int *cache= new Item_cache_int();
/* Mark the cache as non-const to prevent re-caching. */
@@ -838,7 +843,12 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
}
if (item->const_item() && cache_arg)
/*
Do not cache GET_USER_VAR() function as its const_item() may return TRUE
for the current thread but it still may change during the execution.
*/
if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
{
Item_cache_int *cache= new Item_cache_int();
/* Mark the cache as non-const to prevent re-caching. */

View File

@@ -3360,6 +3360,10 @@ String* Item_func_group_concat::val_str(String* str)
DBUG_ASSERT(fixed == 1);
if (null_value)
return 0;
if (!result.length() && tree)
/* Tree is used for sorting as in ORDER BY */
tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this,
left_root_right);
if (count_cut_values && !warning)
{
/*
@@ -3371,11 +3375,6 @@ String* Item_func_group_concat::val_str(String* str)
ER_CUT_VALUE_GROUP_CONCAT,
ER(ER_CUT_VALUE_GROUP_CONCAT));
}
if (result.length())
return &result;
if (tree)
tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this,
left_root_right);
return &result;
}

View File

@@ -249,12 +249,68 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
if (!ref.key_length)
error= table->file->index_first(table->record[0]);
else
error= table->file->index_read(table->record[0],key_buff,
make_prev_keypart_map(ref.key_parts),
range_fl & NEAR_MIN ?
HA_READ_AFTER_KEY :
HA_READ_KEY_OR_NEXT);
else
{
/*
Use index to replace MIN/MAX functions with their values
according to the following rules:
1) Insert the minimum non-null values where the WHERE clause still
matches, or
2) a NULL value if there are only NULL values for key_part_k.
3) Fail, producing a row of nulls
Implementation: Read the smallest value using the search key. If
the interval is open, read the next value after the search
key. If read fails, and we're looking for a MIN() value for a
nullable column, test if there is an exact match for the key.
*/
if (!(range_fl & NEAR_MIN))
/*
Closed interval: Either The MIN argument is non-nullable, or
we have a >= predicate for the MIN argument.
*/
error= table->file->index_read(table->record[0], ref.key_buff,
ref.key_length,
HA_READ_KEY_OR_NEXT);
else
{
/*
Open interval: There are two cases:
1) We have only MIN() and the argument column is nullable, or
2) there is a > predicate on it, nullability is irrelevant.
We need to scan the next bigger record first.
*/
error= table->file->index_read(table->record[0], ref.key_buff,
ref.key_length, HA_READ_AFTER_KEY);
/*
If the found record is outside the group formed by the search
prefix, or there is no such record at all, check if all
records in that group have NULL in the MIN argument
column. If that is the case return that NULL.
Check if case 1 from above holds. If it does, we should read
the skipped tuple.
*/
if (ref.key_buff[prefix_len] == 1 &&
/*
Last keypart (i.e. the argument to MIN) is set to NULL by
find_key_for_maxmin only if all other keyparts are bound
to constants in a conjunction of equalities. Hence, we
can detect this by checking only if the last keypart is
NULL.
*/
(error == HA_ERR_KEY_NOT_FOUND ||
key_cmp_if_same(table, ref.key_buff, ref.key, prefix_len)))
{
DBUG_ASSERT(item_field->field->real_maybe_null());
error= table->file->index_read(table->record[0], ref.key_buff,
ref.key_length,
HA_READ_KEY_EXACT);
}
}
}
/* Verify that the read tuple indeed matches the search key */
if (!error && reckey_in_range(0, &ref, item_field->field,
conds, range_fl, prefix_len))
error= HA_ERR_KEY_NOT_FOUND;
@@ -784,16 +840,26 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
if (!max_fl && key_part_used == key_part_to_use && part->null_bit)
{
/*
SELECT MIN(key_part2) FROM t1 WHERE key_part1=const
If key_part2 may be NULL, then we want to find the first row
that is not null
The query is on this form:
SELECT MIN(key_part_k)
FROM t1
WHERE key_part_1 = const and ... and key_part_k-1 = const
If key_part_k is nullable, we want to find the first matching row
where key_part_k is not null. The key buffer is now {const, ...,
NULL}. This will be passed to the handler along with a flag
indicating open interval. If a tuple is read that does not match
these search criteria, an attempt will be made to read an exact
match for the key buffer.
*/
/* Set the first byte of key_part_k to 1, that means NULL */
ref->key_buff[ref->key_length]= 1;
ref->key_length+= part->store_length;
ref->key_parts++;
DBUG_ASSERT(ref->key_parts == jdx+1);
*range_fl&= ~NO_MIN_RANGE;
*range_fl|= NEAR_MIN; // > NULL
*range_fl|= NEAR_MIN; // Open interval
}
/*
The following test is false when the key in the key tree is

View File

@@ -1784,7 +1784,7 @@ void Query_tables_list::destroy_query_tables_list()
st_lex::st_lex()
:result(0), yacc_yyss(0), yacc_yyvs(0),
sql_command(SQLCOM_END)
sql_command(SQLCOM_END), option_type(OPT_DEFAULT)
{
/* Check that plugins_static_buffer is declared immediately after plugins */
compile_time_assert((&plugins + 1) == (DYNAMIC_ARRAY*)plugins_static_buffer);

View File

@@ -988,6 +988,12 @@ JOIN::optimize()
}
}
if (conds &&!outer_join && const_table_map != found_const_table_map &&
(select_options & SELECT_DESCRIBE) &&
select_lex->master_unit() == &thd->lex->unit) // upper level SELECT
{
conds=new Item_int((longlong) 0,1); // Always false
}
if (make_join_select(this, select, conds))
{
zero_result_cause=
@@ -9133,8 +9139,7 @@ Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table)
if (item->field_type() == MYSQL_TYPE_VARCHAR)
{
Field *field;
if (item->max_length > MAX_FIELD_VARCHARLENGTH /
item->collation.collation->mbmaxlen)
if (item->max_length > MAX_FIELD_VARCHARLENGTH)
field= new Field_blob(item->max_length, item->maybe_null,
item->name, item->collation.collation);
else

View File

@@ -4516,9 +4516,19 @@ int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
int res= 0;
LEX *lex= thd->lex;
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
enum enum_schema_tables schema_table_idx=
get_schema_table_idx(tables->schema_table);
enum enum_var_type option_type= OPT_SESSION;
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
if (lex->option_type == OPT_GLOBAL ||
schema_table_idx == SCH_GLOBAL_VARIABLES)
option_type= OPT_GLOBAL;
rw_rdlock(&LOCK_system_variables_hash);
res= show_status_array(thd, wild, enumerate_sys_vars(thd, TRUE),
lex->option_type, 0, "", tables->table, 0);
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
option_type, NULL, "", tables->table, upper_case_names);
rw_unlock(&LOCK_system_variables_hash);
DBUG_RETURN(res);
}
@@ -4530,16 +4540,38 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
LEX *lex= thd->lex;
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
int res= 0;
STATUS_VAR tmp;
STATUS_VAR *tmp1, tmp;
enum enum_schema_tables schema_table_idx=
get_schema_table_idx(tables->schema_table);
enum enum_var_type option_type;
bool upper_case_names= (schema_table_idx != SCH_STATUS);
if (schema_table_idx == SCH_STATUS)
{
option_type= lex->option_type;
if (option_type == OPT_GLOBAL)
tmp1= &tmp;
else
tmp1= thd->initial_status_var;
}
else if (schema_table_idx == SCH_GLOBAL_STATUS)
{
option_type= OPT_GLOBAL;
tmp1= &tmp;
}
else
{
option_type= OPT_SESSION;
tmp1= &thd->status_var;
}
pthread_mutex_lock(&LOCK_status);
if (lex->option_type == OPT_GLOBAL)
if (option_type == OPT_GLOBAL)
calc_sum_of_all_status(&tmp);
res= show_status_array(thd, wild,
(SHOW_VAR *)all_status_vars.buffer,
OPT_GLOBAL,
(lex->option_type == OPT_GLOBAL ?
&tmp: thd->initial_status_var),
"", tables->table, 0);
option_type, tmp1, "", tables->table,
upper_case_names);
pthread_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
@@ -4782,12 +4814,10 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
/* Don't let unimplemented types pass through. Could be a grave error. */
DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
/* this should be changed when Item_empty_string is fixed(in 4.1) */
if (!(item= new Item_empty_string("", 0, cs)))
if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
{
DBUG_RETURN(0);
}
item->max_length= fields_info->field_length * cs->mbmaxlen;
item->set_name(fields_info->field_name,
strlen(fields_info->field_name), cs);
break;
@@ -5228,172 +5258,6 @@ int fill_schema_files(THD *thd, TABLE_LIST *tables, COND *cond)
DBUG_RETURN(0);
}
int fill_schema_status(THD *thd, SHOW_VAR *variables,
struct system_status_var *status_var,
const char *prefix, TABLE *table)
{
SHOW_VAR tmp, *var;
SHOW_TYPE show_type;
LEX_STRING null_lex_str;
char buff[SHOW_VAR_FUNC_BUFF_SIZE];
char name_buf[64], *name_pos;
int name_len;
DBUG_ENTER("fill_schema_status");
null_lex_str.str= 0;
null_lex_str.length= 0;
name_pos= strnmov(name_buf, prefix, sizeof(name_buf) - 1);
if (*prefix)
*name_pos++= '_';
name_len= name_buf + sizeof(name_buf) - name_pos;
for (; variables->name; variables++)
{
strnmov(name_pos, variables->name, name_len);
name_buf[sizeof(name_buf) - 1]= 0;
make_upper(name_buf);
for (var= variables; var->type == SHOW_FUNC; var= &tmp)
((mysql_show_var_func)(var->value))(thd, &tmp, buff);
show_type= var->type;
if (show_type == SHOW_ARRAY)
{
fill_schema_status(thd, (SHOW_VAR*) var->value,
status_var, name_buf, table);
}
else
{
char *value= var->value;
restore_record(table, s->default_values);
table->field[0]->store(name_buf, strlen(name_buf), system_charset_info);
if (show_type == SHOW_SYS)
{
show_type= ((sys_var*) value)->show_type();
value= (char*) ((sys_var*) value)->value_ptr(thd, OPT_GLOBAL,
&null_lex_str);
}
switch (show_type)
{
case SHOW_DOUBLE_STATUS:
value= (char*) status_var + (ulong) value;
table->field[1]->store(*(double*) value);
break;
case SHOW_LONG_STATUS:
value= (char*) status_var + (ulong) value;
/* fall through */
case SHOW_LONG:
case SHOW_LONG_NOFLUSH: /* the difference lies in refresh_status() */
table->field[1]->store((longlong) *(long*) value, false);
break;
case SHOW_LONGLONG:
table->field[1]->store(*(longlong*) value, false);
break;
case SHOW_HA_ROWS:
table->field[1]->store((longlong) *(ha_rows*) value, false);
break;
case SHOW_BOOL:
table->field[1]->store((longlong) *(bool*) value, false);
break;
case SHOW_MY_BOOL:
table->field[1]->store((longlong) *(my_bool*) value, false);
break;
case SHOW_INT:
table->field[1]->store((longlong) *(uint32*) value, false);
break;
case SHOW_HAVE: /* always displayed as 0 */
table->field[1]->store((longlong) 0, false);
break;
case SHOW_CHAR_PTR:
value= *(char**) value;
/* fall through */
case SHOW_CHAR: /* always displayed as 0 */
table->field[1]->store((longlong) 0, false);
break;
case SHOW_KEY_CACHE_LONG:
value= (char*) dflt_key_cache + (ulong) value;
table->field[1]->store((longlong) *(long*) value, false);
break;
case SHOW_KEY_CACHE_LONGLONG:
value= (char*) dflt_key_cache + (ulong) value;
table->field[1]->store(*(longlong*) value, false);
break;
case SHOW_UNDEF: /* always displayed as 0 */
table->field[1]->store((longlong) 0, false);
break;
case SHOW_SYS: /* cannot happen */
default:
DBUG_ASSERT(0);
break;
}
table->field[1]->set_notnull();
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
}
}
DBUG_RETURN(0);
}
int fill_schema_global_status(THD *thd, TABLE_LIST *tables, COND *cond)
{
STATUS_VAR tmp;
int res= 0;
DBUG_ENTER("fill_schema_global_status");
pthread_mutex_lock(&LOCK_status);
calc_sum_of_all_status(&tmp);
res= fill_schema_status(thd, (SHOW_VAR*) all_status_vars.buffer,
&tmp, "", tables->table);
pthread_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
int fill_schema_session_status(THD *thd, TABLE_LIST *tables, COND *cond)
{
int res= 0;
DBUG_ENTER("fill_schema_session_status");
pthread_mutex_lock(&LOCK_status);
res= fill_schema_status(thd, (SHOW_VAR*) all_status_vars.buffer,
&thd->status_var, "", tables->table);
pthread_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
int fill_schema_global_variables(THD *thd, TABLE_LIST *tables, COND *cond)
{
int res= 0;
DBUG_ENTER("fill_schema_global_variables");
rw_rdlock(&LOCK_system_variables_hash);
res= show_status_array(thd, "", enumerate_sys_vars(thd, FALSE), OPT_GLOBAL,
NULL, "", tables->table, 1);
rw_unlock(&LOCK_system_variables_hash);
DBUG_RETURN(res);
}
int fill_schema_session_variables(THD *thd, TABLE_LIST *tables, COND *cond)
{
int res= 0;
DBUG_ENTER("fill_schema_session_variables");
rw_rdlock(&LOCK_system_variables_hash);
res= show_status_array(thd, "", enumerate_sys_vars(thd, FALSE), OPT_SESSION,
NULL, "", tables->table, 1);
rw_unlock(&LOCK_system_variables_hash);
DBUG_RETURN(res);
}
ST_FIELD_INFO schema_fields_info[]=
{
@@ -5762,25 +5626,9 @@ ST_FIELD_INFO partitions_fields_info[]=
ST_FIELD_INFO variables_fields_info[]=
{
{"Variable_name", 80, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
{"Value", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, "Value"},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
};
ST_FIELD_INFO status_fields_info[]=
{
{"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
{"VARIABLE_VALUE", 2207, MYSQL_TYPE_DECIMAL, 0, 0, "Value"},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
};
ST_FIELD_INFO system_variables_fields_info[]=
{
{"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
{"VARIABLE_VALUE", 65535, MYSQL_TYPE_STRING, 0, 1, "Value"},
{"VARIABLE_VALUE", 20480, MYSQL_TYPE_STRING, 0, 1, "Value"},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
};
@@ -5920,10 +5768,10 @@ ST_SCHEMA_TABLE schema_tables[]=
Events::fill_schema_events, make_old_format, 0, -1, -1, 0},
{"FILES", files_fields_info, create_schema_table,
fill_schema_files, 0, 0, -1, -1, 0},
{"GLOBAL_STATUS", status_fields_info, create_schema_table,
fill_schema_global_status, make_old_format, 0, -1, -1, 0},
{"GLOBAL_VARIABLES", system_variables_fields_info, create_schema_table,
fill_schema_global_variables, make_old_format, 0, -1, -1, 0},
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
fill_status, make_old_format, 0, -1, -1, 0},
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
fill_variables, make_old_format, 0, -1, -1, 0},
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0},
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
@@ -5943,10 +5791,10 @@ ST_SCHEMA_TABLE schema_tables[]=
fill_schema_shemata, make_schemata_old_format, 0, 1, -1, 0},
{"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table,
fill_schema_schema_privileges, 0, 0, -1, -1, 0},
{"SESSION_STATUS", status_fields_info, create_schema_table,
fill_schema_session_status, make_old_format, 0, -1, -1, 0},
{"SESSION_VARIABLES", system_variables_fields_info, create_schema_table,
fill_schema_session_variables, make_old_format, 0, -1, -1, 0},
{"SESSION_STATUS", variables_fields_info, create_schema_table,
fill_status, make_old_format, 0, -1, -1, 0},
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
fill_variables, make_old_format, 0, -1, -1, 0},
{"STATISTICS", stat_fields_info, create_schema_table,
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0},
{"STATUS", variables_fields_info, create_schema_table, fill_status,

View File

@@ -147,8 +147,16 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg)
fake_select_lex->table_list.link_in_list((byte *)&result_table_list,
(byte **)
&result_table_list.next_local);
fake_select_lex->context.table_list= fake_select_lex->context.first_name_resolution_table=
fake_select_lex->context.table_list=
fake_select_lex->context.first_name_resolution_table=
fake_select_lex->get_table_list();
if (!fake_select_lex->first_execution)
{
for (ORDER *order= (ORDER *) global_parameters->order_list.first;
order;
order= order->next)
order->item= &order->item_ptr;
}
for (ORDER *order= (ORDER *)global_parameters->order_list.first;
order;
order=order->next)