Commit 7cd836b6 authored by unknown's avatar unknown

Merge gshchepa@bk-internal.mysql.com:/home/bk/mysql-5.1-target-5.1.22

into  gleb.loc:/home/uchum/work/bk/target-5.1.22/mysql-5.1-target-5.1.22

parents e81734ce d55f22fe
...@@ -3980,4 +3980,61 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -3980,4 +3980,61 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index 1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index 1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (
c1 int(11) NOT NULL AUTO_INCREMENT,
c2 varchar(1000) DEFAULT NULL,
c3 bigint(20) DEFAULT NULL,
c4 bigint(20) DEFAULT NULL,
PRIMARY KEY (c1)
);
EXPLAIN EXTENDED
SELECT join_2.c1
FROM
t1 AS join_0,
t1 AS join_1,
t1 AS join_2,
t1 AS join_3,
t1 AS join_4,
t1 AS join_5,
t1 AS join_6,
t1 AS join_7
WHERE
join_0.c1=join_1.c1 AND
join_1.c1=join_2.c1 AND
join_2.c1=join_3.c1 AND
join_3.c1=join_4.c1 AND
join_4.c1=join_5.c1 AND
join_5.c1=join_6.c1 AND
join_6.c1=join_7.c1
OR
join_0.c2 < '?' AND
join_1.c2 < '?' AND
join_2.c2 > '?' AND
join_2.c2 < '!' AND
join_3.c2 > '?' AND
join_4.c2 = '?' AND
join_5.c2 <> '?' AND
join_6.c2 <> '?' AND
join_7.c2 >= '?' AND
join_0.c1=join_1.c1 AND
join_1.c1=join_2.c1 AND
join_2.c1=join_3.c1 AND
join_3.c1=join_4.c1 AND
join_4.c1=join_5.c1 AND
join_5.c1=join_6.c1 AND
join_6.c1=join_7.c1
GROUP BY
join_3.c1,
join_2.c1,
join_7.c1,
join_1.c1,
join_0.c1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select '0' AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by '0','0','0','0','0'
SHOW WARNINGS;
Level Code Message
Note 1003 select '0' AS `c1` from `test`.`t1` `join_0` join `test`.`t1` `join_1` join `test`.`t1` `join_2` join `test`.`t1` `join_3` join `test`.`t1` `join_4` join `test`.`t1` `join_5` join `test`.`t1` `join_6` join `test`.`t1` `join_7` where 0 group by '0','0','0','0','0'
DROP TABLE t1;
End of 5.0 tests End of 5.0 tests
...@@ -3359,4 +3359,64 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2 ...@@ -3359,4 +3359,64 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111); WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
DROP TABLE t1; DROP TABLE t1;
#
# Bug #30396: crash for a join with equalities and sargable predicates
# in disjunctive parts of the WHERE condition
#
CREATE TABLE t1 (
c1 int(11) NOT NULL AUTO_INCREMENT,
c2 varchar(1000) DEFAULT NULL,
c3 bigint(20) DEFAULT NULL,
c4 bigint(20) DEFAULT NULL,
PRIMARY KEY (c1)
);
EXPLAIN EXTENDED
SELECT join_2.c1
FROM
t1 AS join_0,
t1 AS join_1,
t1 AS join_2,
t1 AS join_3,
t1 AS join_4,
t1 AS join_5,
t1 AS join_6,
t1 AS join_7
WHERE
join_0.c1=join_1.c1 AND
join_1.c1=join_2.c1 AND
join_2.c1=join_3.c1 AND
join_3.c1=join_4.c1 AND
join_4.c1=join_5.c1 AND
join_5.c1=join_6.c1 AND
join_6.c1=join_7.c1
OR
join_0.c2 < '?' AND
join_1.c2 < '?' AND
join_2.c2 > '?' AND
join_2.c2 < '!' AND
join_3.c2 > '?' AND
join_4.c2 = '?' AND
join_5.c2 <> '?' AND
join_6.c2 <> '?' AND
join_7.c2 >= '?' AND
join_0.c1=join_1.c1 AND
join_1.c1=join_2.c1 AND
join_2.c1=join_3.c1 AND
join_3.c1=join_4.c1 AND
join_4.c1=join_5.c1 AND
join_5.c1=join_6.c1 AND
join_6.c1=join_7.c1
GROUP BY
join_3.c1,
join_2.c1,
join_7.c1,
join_1.c1,
join_0.c1;
SHOW WARNINGS;
DROP TABLE t1;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -1801,6 +1801,8 @@ void Item_field::set_field(Field *field_par) ...@@ -1801,6 +1801,8 @@ void Item_field::set_field(Field *field_par)
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG); unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
collation.set(field_par->charset(), field_par->derivation()); collation.set(field_par->charset(), field_par->derivation());
fixed= 1; fixed= 1;
if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
any_privileges= 0;
} }
......
...@@ -1569,7 +1569,6 @@ public: ...@@ -1569,7 +1569,6 @@ public:
the current and level */ the current and level */
COND_EQUAL() COND_EQUAL()
{ {
max_members= 0;
upper_levels= 0; upper_levels= 0;
} }
}; };
......
...@@ -6738,6 +6738,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, ...@@ -6738,6 +6738,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
DBUG_PRINT("info", ("thd->mark_used_columns: %d", thd->mark_used_columns)); DBUG_PRINT("info", ("thd->mark_used_columns: %d", thd->mark_used_columns));
select_lex->cond_count= 0; select_lex->cond_count= 0;
select_lex->between_count= 0; select_lex->between_count= 0;
select_lex->max_equal_elems= 0;
for (table= tables; table; table= table->next_local) for (table= tables; table; table= table->next_local)
{ {
......
...@@ -749,6 +749,12 @@ void query_cache_end_of_result(THD *thd) ...@@ -749,6 +749,12 @@ void query_cache_end_of_result(THD *thd)
if (thd->net.query_cache_query == 0) if (thd->net.query_cache_query == 0)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
if (thd->killed)
{
query_cache_abort(&thd->net);
DBUG_VOID_RETURN;
}
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
query_cache_insert(&thd->net, (char*)thd, query_cache_insert(&thd->net, (char*)thd,
emb_count_querycache_size(thd)); emb_count_querycache_size(thd));
...@@ -775,28 +781,31 @@ void query_cache_end_of_result(THD *thd) ...@@ -775,28 +781,31 @@ void query_cache_end_of_result(THD *thd)
DUMP(&query_cache); DUMP(&query_cache);
BLOCK_LOCK_WR(query_block); BLOCK_LOCK_WR(query_block);
Query_cache_query *header= query_block->query(); Query_cache_query *header= query_block->query();
Query_cache_block *last_result_block= header->result()->prev; Query_cache_block *last_result_block;
ulong allign_size= ALIGN_SIZE(last_result_block->used); ulong allign_size;
ulong len= max(query_cache.min_allocation_unit, allign_size); ulong len;
if (last_result_block->length >= query_cache.min_allocation_unit + len)
query_cache.split_block(last_result_block,len);
#ifndef DBUG_OFF
if (header->result() == 0) if (header->result() == 0)
{ {
DBUG_PRINT("error", ("end of data whith no result. query '%s'", DBUG_PRINT("error", ("End of data with no result blocks; "
header->query())); "Query '%s' removed from cache.", header->query()));
query_cache.wreck(__LINE__, "");
/* /*
We do not need call of BLOCK_UNLOCK_WR(query_block); here because Extra safety: empty result should not happen in the normal call
query_cache.wreck() switched query cache off but left content to this function. In the release version that query should be ignored
untouched for investigation (it is debugging method). and removed from QC.
*/ */
DBUG_ASSERT(0);
query_cache.free_query(query_block);
STRUCT_UNLOCK(&query_cache.structure_guard_mutex); STRUCT_UNLOCK(&query_cache.structure_guard_mutex);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#endif
last_result_block= header->result()->prev;
allign_size= ALIGN_SIZE(last_result_block->used);
len= max(query_cache.min_allocation_unit, allign_size);
if (last_result_block->length >= query_cache.min_allocation_unit + len)
query_cache.split_block(last_result_block,len);
header->found_rows(current_thd->limit_found_rows); header->found_rows(current_thd->limit_found_rows);
header->result()->type= Query_cache_block::RESULT; header->result()->type= Query_cache_block::RESULT;
......
...@@ -1517,6 +1517,7 @@ void st_select_lex::init_query() ...@@ -1517,6 +1517,7 @@ void st_select_lex::init_query()
*/ */
parent_lex->push_context(&context); parent_lex->push_context(&context);
cond_count= between_count= with_wild= 0; cond_count= between_count= with_wild= 0;
max_equal_elems= 0;
conds_processed_with_permanent_arena= 0; conds_processed_with_permanent_arena= 0;
ref_pointer_array= 0; ref_pointer_array= 0;
select_n_where_fields= 0; select_n_where_fields= 0;
......
...@@ -607,6 +607,7 @@ public: ...@@ -607,6 +607,7 @@ public:
uint select_n_having_items; uint select_n_having_items;
uint cond_count; /* number of arguments of and/or/xor in where/having/on */ uint cond_count; /* number of arguments of and/or/xor in where/having/on */
uint between_count; /* number of between predicates in where/having/on */ uint between_count; /* number of between predicates in where/having/on */
uint max_equal_elems; /* maximal number of elements in multiple equalities */
/* /*
Number of fields used in select list or where clause of current select Number of fields used in select list or where clause of current select
and all inner subselects. and all inner subselects.
......
...@@ -3562,10 +3562,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, ...@@ -3562,10 +3562,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
uint and_level,i,found_eq_constant; uint and_level,i,found_eq_constant;
KEY_FIELD *key_fields, *end, *field; KEY_FIELD *key_fields, *end, *field;
uint sz; uint sz;
uint m= 1; uint m= max(select_lex->max_equal_elems,1);
if (cond_equal && cond_equal->max_members)
m= cond_equal->max_members;
/* /*
We use the same piece of memory to store both KEY_FIELD We use the same piece of memory to store both KEY_FIELD
...@@ -3585,7 +3582,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, ...@@ -3585,7 +3582,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
it is considered as sargable only for its first argument. it is considered as sargable only for its first argument.
Multiple equality can add elements that are filled after Multiple equality can add elements that are filled after
substitution of field arguments by equal fields. There substitution of field arguments by equal fields. There
can be not more than cond_equal->max_members such substitutions. can be not more than select_lex->max_equal_elems such
substitutions.
*/ */
sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))* sz= max(sizeof(KEY_FIELD),sizeof(SARGABLE_PARAM))*
(((thd->lex->current_select->cond_count+1)*2 + (((thd->lex->current_select->cond_count+1)*2 +
...@@ -7387,8 +7385,7 @@ static bool check_equality(THD *thd, Item *item, COND_EQUAL *cond_equal, ...@@ -7387,8 +7385,7 @@ static bool check_equality(THD *thd, Item *item, COND_EQUAL *cond_equal,
just an argument of a comparison predicate. just an argument of a comparison predicate.
The function also determines the maximum number of members in The function also determines the maximum number of members in
equality lists of each Item_cond_and object assigning it to equality lists of each Item_cond_and object assigning it to
cond_equal->max_members of this object and updating accordingly thd->lex->current_select->max_equal_elems.
the upper levels COND_EQUAL structures.
NOTES NOTES
Multiple equality predicate =(f1,..fn) is equivalent to the conjuction of Multiple equality predicate =(f1,..fn) is equivalent to the conjuction of
...@@ -7433,7 +7430,6 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, ...@@ -7433,7 +7430,6 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
COND_EQUAL *inherited) COND_EQUAL *inherited)
{ {
Item_equal *item_equal; Item_equal *item_equal;
uint members;
COND_EQUAL cond_equal; COND_EQUAL cond_equal;
cond_equal.upper_levels= inherited; cond_equal.upper_levels= inherited;
...@@ -7471,19 +7467,8 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, ...@@ -7471,19 +7467,8 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
{ {
item_equal->fix_length_and_dec(); item_equal->fix_length_and_dec();
item_equal->update_used_tables(); item_equal->update_used_tables();
members= item_equal->members(); set_if_bigger(thd->lex->current_select->max_equal_elems,
if (cond_equal.max_members < members) item_equal->members());
cond_equal.max_members= members;
}
members= cond_equal.max_members;
if (inherited && inherited->max_members < members)
{
do
{
inherited->max_members= members;
inherited= inherited->upper_levels;
}
while (inherited);
} }
((Item_cond_and*)cond)->cond_equal= cond_equal; ((Item_cond_and*)cond)->cond_equal= cond_equal;
...@@ -7538,10 +7523,12 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, ...@@ -7538,10 +7523,12 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
{ {
item_equal->fix_length_and_dec(); item_equal->fix_length_and_dec();
item_equal->update_used_tables(); item_equal->update_used_tables();
return item_equal;
} }
else else
return eq_list.pop(); item_equal= (Item_equal *) eq_list.pop();
set_if_bigger(thd->lex->current_select->max_equal_elems,
item_equal->members());
return item_equal;
} }
else else
{ {
...@@ -7557,9 +7544,8 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond, ...@@ -7557,9 +7544,8 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
{ {
item_equal->fix_length_and_dec(); item_equal->fix_length_and_dec();
item_equal->update_used_tables(); item_equal->update_used_tables();
members= item_equal->members(); set_if_bigger(thd->lex->current_select->max_equal_elems,
if (cond_equal.max_members < members) item_equal->members());
cond_equal.max_members= members;
} }
and_cond->cond_equal= cond_equal; and_cond->cond_equal= cond_equal;
args->concat((List<Item> *)&cond_equal.current_level); args->concat((List<Item> *)&cond_equal.current_level);
...@@ -9417,7 +9403,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9417,7 +9403,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
bool using_unique_constraint= 0; bool using_unique_constraint= 0;
bool use_packed_rows= 0; bool use_packed_rows= 0;
bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS); bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
char *tmpname, *tmppath, path[FN_REFLEN], table_name[NAME_LEN+1]; char *tmpname,path[FN_REFLEN];
uchar *pos, *group_buff, *bitmaps; uchar *pos, *group_buff, *bitmaps;
uchar *null_flags; uchar *null_flags;
Field **reg_field, **from_field, **default_field; Field **reg_field, **from_field, **default_field;
...@@ -9441,12 +9427,12 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9441,12 +9427,12 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
temp_pool_slot = bitmap_lock_set_next(&temp_pool); temp_pool_slot = bitmap_lock_set_next(&temp_pool);
if (temp_pool_slot != MY_BIT_NONE) // we got a slot if (temp_pool_slot != MY_BIT_NONE) // we got a slot
sprintf(table_name, "%s_%lx_%i", tmp_file_prefix, sprintf(path, "%s_%lx_%i", tmp_file_prefix,
current_pid, temp_pool_slot); current_pid, temp_pool_slot);
else else
{ {
/* if we run out of slots or we are not using tempool */ /* if we run out of slots or we are not using tempool */
sprintf(table_name, "%s%lx_%lx_%x", tmp_file_prefix,current_pid, sprintf(path,"%s%lx_%lx_%x", tmp_file_prefix,current_pid,
thd->thread_id, thd->tmp_table++); thd->thread_id, thd->tmp_table++);
} }
...@@ -9454,8 +9440,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9454,8 +9440,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
No need to change table name to lower case as we are only creating No need to change table name to lower case as we are only creating
MyISAM or HEAP tables here MyISAM or HEAP tables here
*/ */
fn_format(path, table_name, mysql_tmpdir, "", fn_format(path, path, mysql_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
MY_REPLACE_EXT|MY_UNPACK_FILENAME);
if (group) if (group)
{ {
...@@ -9501,8 +9487,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9501,8 +9487,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
sizeof(*key_part_info)*(param->group_parts+1), sizeof(*key_part_info)*(param->group_parts+1),
&param->start_recinfo, &param->start_recinfo,
sizeof(*param->recinfo)*(field_count*2+4), sizeof(*param->recinfo)*(field_count*2+4),
&tmppath, (uint) strlen(path)+1, &tmpname, (uint) strlen(path)+1,
&tmpname, (uint) strlen(table_name)+1,
&group_buff, (group && ! using_unique_constraint ? &group_buff, (group && ! using_unique_constraint ?
param->group_length : 0), param->group_length : 0),
&bitmaps, bitmap_buffer_size(field_count)*2, &bitmaps, bitmap_buffer_size(field_count)*2,
...@@ -9521,8 +9506,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9521,8 +9506,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
DBUG_RETURN(NULL); /* purecov: inspected */ DBUG_RETURN(NULL); /* purecov: inspected */
} }
param->items_to_copy= copy_func; param->items_to_copy= copy_func;
strmov(tmppath, path); strmov(tmpname,path);
strmov(tmpname, table_name);
/* make table according to fields */ /* make table according to fields */
bzero((char*) table,sizeof(*table)); bzero((char*) table,sizeof(*table));
...@@ -9547,7 +9531,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9547,7 +9531,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
table->keys_in_use_for_query.init(); table->keys_in_use_for_query.init();
table->s= share; table->s= share;
init_tmp_table_share(share, "", 0, tmpname, tmppath); init_tmp_table_share(share, "", 0, tmpname, tmpname);
share->blob_field= blob_field; share->blob_field= blob_field;
share->blob_ptr_size= mi_portable_sizeof_char_ptr; share->blob_ptr_size= mi_portable_sizeof_char_ptr;
share->db_low_byte_first=1; // True for HEAP and MyISAM share->db_low_byte_first=1; // True for HEAP and MyISAM
......
...@@ -397,9 +397,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, ...@@ -397,9 +397,15 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
{ {
Item_field *field; Item_field *field;
if ((field= item->filed_for_view_update())) if ((field= item->filed_for_view_update()))
{
/*
any_privileges may be reset later by the Item_field::set_field
method in case of a system temporary table.
*/
field->any_privileges= 1; field->any_privileges= 1;
} }
} }
}
#endif #endif
if (open_and_lock_tables(thd, tables)) if (open_and_lock_tables(thd, tables))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment