Commit 51f98790 authored by monty@narttu.mysql.fi's avatar monty@narttu.mysql.fi

Removed compiler warnings

Fixed memory leak in new filesort code
Optimzed sub selects to use keys with outer references.
Increased max tables in join to 62
parent ee8190f2
...@@ -22,7 +22,6 @@ LIBS = @CLIENT_LIBS@ ...@@ -22,7 +22,6 @@ LIBS = @CLIENT_LIBS@
LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysql/libmysqlclient.la LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysql/libmysqlclient.la
bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \ bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \
mysqldump mysqlimport mysqltest mysqlbinlog mysqlmanagerc mysqlmanager-pwgen mysqldump mysqlimport mysqltest mysqlbinlog mysqlmanagerc mysqlmanager-pwgen
noinst_PROGRAMS = insert_test select_test thread_test
noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \ noinst_HEADERS = sql_string.h completion_hash.h my_readline.h \
client_priv.h client_priv.h
mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc
......
...@@ -3117,7 +3117,8 @@ int sort_ft_buf_flush(MI_SORT_PARAM *sort_param) ...@@ -3117,7 +3117,8 @@ int sort_ft_buf_flush(MI_SORT_PARAM *sort_param)
SORT_INFO *sort_info=sort_param->sort_info; SORT_INFO *sort_info=sort_param->sort_info;
SORT_KEY_BLOCKS *key_block=sort_info->key_block; SORT_KEY_BLOCKS *key_block=sort_info->key_block;
MYISAM_SHARE *share=sort_info->info->s; MYISAM_SHARE *share=sort_info->info->s;
uint val_off, val_len, error; uint val_off, val_len;
int error;
SORT_FT_BUF *ft_buf=sort_info->ft_buf; SORT_FT_BUF *ft_buf=sort_info->ft_buf;
uchar *from, *to; uchar *from, *to;
...@@ -3126,14 +3127,17 @@ int sort_ft_buf_flush(MI_SORT_PARAM *sort_param) ...@@ -3126,14 +3127,17 @@ int sort_ft_buf_flush(MI_SORT_PARAM *sort_param)
to=ft_buf->lastkey+val_off; to=ft_buf->lastkey+val_off;
if (ft_buf->buf) if (ft_buf->buf)
{ /* flushing first-level tree */ {
error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,HA_OFFSET_ERROR); /* flushing first-level tree */
error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,
HA_OFFSET_ERROR);
for (from=to+val_len; for (from=to+val_len;
!error && from < ft_buf->buf; !error && from < ft_buf->buf;
from+= val_len) from+= val_len)
{ {
memcpy(to, from, val_len); memcpy(to, from, val_len);
error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,HA_OFFSET_ERROR); error=sort_insert_key(sort_param,key_block,ft_buf->lastkey,
HA_OFFSET_ERROR);
} }
return error; return error;
} }
......
...@@ -491,7 +491,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo, ...@@ -491,7 +491,7 @@ static int underflow(register MI_INFO *info, register MI_KEYDEF *keyinfo,
if (info->s->keyinfo+info->lastinx == keyinfo) if (info->s->keyinfo+info->lastinx == keyinfo)
info->page_changed=1; info->page_changed=1;
if ((keypos < anc_buff+anc_length && (share->rnd++ & 1)) || if ((keypos < anc_buff+anc_length && (info->state->records & 1)) ||
keypos == anc_buff+2+key_reflength) keypos == anc_buff+2+key_reflength)
{ /* Use page right of anc-page */ { /* Use page right of anc-page */
DBUG_PRINT("test",("use right page")); DBUG_PRINT("test",("use right page"));
......
...@@ -427,10 +427,6 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -427,10 +427,6 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share->kfile=kfile; share->kfile=kfile;
share->this_process=(ulong) getpid(); share->this_process=(ulong) getpid();
share->rnd= (int) share->this_process; /* rnd-counter for splits */
#ifndef DBUG_OFF
share->rnd=0; /* To make things repeatable */
#endif
share->last_process= share->state.process; share->last_process= share->state.process;
share->base.key_parts=key_parts; share->base.key_parts=key_parts;
share->base.all_key_parts=key_parts+unique_key_parts; share->base.all_key_parts=key_parts+unique_key_parts;
......
...@@ -662,7 +662,8 @@ static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo, ...@@ -662,7 +662,8 @@ static int _mi_balance_page(register MI_INFO *info, MI_KEYDEF *keyinfo,
curr_keylength=k_length+nod_flag; curr_keylength=k_length+nod_flag;
info->page_changed=1; info->page_changed=1;
if ((father_key_pos != father_buff+father_length && (info->s->rnd++ & 1)) || if ((father_key_pos != father_buff+father_length &&
(info->state->records & 1)) ||
father_key_pos == father_buff+2+info->s->base.key_reflength) father_key_pos == father_buff+2+info->s->base.key_reflength)
{ {
right=1; right=1;
......
...@@ -193,7 +193,6 @@ typedef struct st_mi_isam_share { /* Shared between opens */ ...@@ -193,7 +193,6 @@ typedef struct st_mi_isam_share { /* Shared between opens */
uint w_locks,r_locks,tot_locks; /* Number of read/write locks */ uint w_locks,r_locks,tot_locks; /* Number of read/write locks */
uint blocksize; /* blocksize of keyfile */ uint blocksize; /* blocksize of keyfile */
myf write_flag; myf write_flag;
int rnd; /* rnd-counter */
enum data_file_type data_file_type; enum data_file_type data_file_type;
my_bool changed, /* If changed since lock */ my_bool changed, /* If changed since lock */
global_changed, /* If changed since open */ global_changed, /* If changed since open */
......
...@@ -448,10 +448,6 @@ static int examine_log(my_string file_name, char **table_names) ...@@ -448,10 +448,6 @@ static int examine_log(my_string file_name, char **table_names)
goto end; goto end;
files_open++; files_open++;
file_info.closed=0; file_info.closed=0;
if (opt_myisam_with_debug)
file_info.isam->s->rnd= 0;
else
file_info.isam->s->rnd= isamlog_process;
} }
VOID(tree_insert(&tree, (gptr) &file_info, 0, tree.custom_arg)); VOID(tree_insert(&tree, (gptr) &file_info, 0, tree.custom_arg));
if (file_info.used) if (file_info.used)
...@@ -806,7 +802,6 @@ static int close_some_file(TREE *tree) ...@@ -806,7 +802,6 @@ static int close_some_file(TREE *tree)
(void*) &access_param,left_root_right)); (void*) &access_param,left_root_right));
if (!access_param.found) if (!access_param.found)
return 1; /* No open file that is possibly to close */ return 1; /* No open file that is possibly to close */
access_param.found->rnd=access_param.found->isam->s->rnd;
if (mi_close(access_param.found->isam)) if (mi_close(access_param.found->isam))
return 1; return 1;
access_param.found->closed=1; access_param.found->closed=1;
...@@ -826,7 +821,6 @@ static int reopen_closed_file(TREE *tree, struct file_info *fileinfo) ...@@ -826,7 +821,6 @@ static int reopen_closed_file(TREE *tree, struct file_info *fileinfo)
if (!(fileinfo->isam= mi_open(name,O_RDWR,HA_OPEN_WAIT_IF_LOCKED))) if (!(fileinfo->isam= mi_open(name,O_RDWR,HA_OPEN_WAIT_IF_LOCKED)))
return 1; return 1;
fileinfo->closed=0; fileinfo->closed=0;
fileinfo->isam->s->rnd=fileinfo->rnd;
re_open_count++; re_open_count++;
return 0; return 0;
} }
......
...@@ -294,6 +294,10 @@ patient_uq clinic_uq ...@@ -294,6 +294,10 @@ patient_uq clinic_uq
1 1 1 1
1 2 1 2
2 2 2 2
explain select * from t6 where exists (select * from t7 where uq = clinic_uq);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t6 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 t6.clinic_uq 1
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b); select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
Column: 'a' in field list is ambiguous Column: 'a' in field list is ambiguous
drop table if exists t1,t2,t3; drop table if exists t1,t2,t3;
...@@ -1113,3 +1117,10 @@ select -10 IN (select a from t1 FORCE INDEX (indexa)); ...@@ -1113,3 +1117,10 @@ select -10 IN (select a from t1 FORCE INDEX (indexa));
-10 IN (select a from t1 FORCE INDEX (indexa)) -10 IN (select a from t1 FORCE INDEX (indexa))
NULL NULL
drop table t1; drop table t1;
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
explain SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref salary salary 5 const 1 Using where
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
drop table t1;
...@@ -115,7 +115,7 @@ drop table t1, t2; ...@@ -115,7 +115,7 @@ drop table t1, t2;
create table t1 (a int primary key); create table t1 (a int primary key);
insert into t1 values(1),(2); insert into t1 values(1),(2);
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a); select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a);
--replace_result "31 tables" "XX tables" "63 tables" "XX tables" --replace_result "31 tables" "XX tables" "62 tables" "XX tables"
--error 1116 --error 1116
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a); select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
drop table t1; drop table t1;
......
...@@ -125,6 +125,7 @@ create table t7( uq int primary key, name char(25)); ...@@ -125,6 +125,7 @@ create table t7( uq int primary key, name char(25));
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta"); insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
insert into t6 values (1,1),(1,2),(2,2),(1,3); insert into t6 values (1,1),(1,2),(2,2),(1,3);
select * from t6 where exists (select * from t7 where uq = clinic_uq); select * from t6 where exists (select * from t7 where uq = clinic_uq);
explain select * from t6 where exists (select * from t7 where uq = clinic_uq);
# not unique fields # not unique fields
-- error 1052 -- error 1052
...@@ -703,3 +704,11 @@ create table t1 (a int, unique index indexa (a)); ...@@ -703,3 +704,11 @@ create table t1 (a int, unique index indexa (a));
insert into t1 values (-1), (-4), (-2), (NULL); insert into t1 values (-1), (-4), (-2), (NULL);
select -10 IN (select a from t1 FORCE INDEX (indexa)); select -10 IN (select a from t1 FORCE INDEX (indexa));
drop table t1; drop table t1;
#
# Test optimization for sub selects
#
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
explain SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
drop table t1;
...@@ -262,6 +262,22 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -262,6 +262,22 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
} /* filesort */ } /* filesort */
void filesort_free_buffers(TABLE *table)
{
if (table->sort.record_pointers)
{
my_free((gptr) table->sort.record_pointers,MYF(0));
table->sort.record_pointers=0;
}
if (table->sort.addon_buf)
{
my_free((char *) table->sort.addon_buf, MYF(0));
my_free((char *) table->sort.addon_field, MYF(MY_ALLOW_ZERO_PTR));
table->sort.addon_buf=0;
table->sort.addon_field=0;
}
}
/* Make a array of string pointers */ /* Make a array of string pointers */
static char **make_char_array(register uint fields, uint length, myf my_flag) static char **make_char_array(register uint fields, uint length, myf my_flag)
......
...@@ -349,7 +349,7 @@ table_map Item_field::used_tables() const ...@@ -349,7 +349,7 @@ table_map Item_field::used_tables() const
{ {
if (field->table->const_table) if (field->table->const_table)
return 0; // const item return 0; // const item
return (depended_from ? RAND_TABLE_BIT : field->table->map); return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
} }
Item *Item_field::get_tmp_table_item(THD *thd) Item *Item_field::get_tmp_table_item(THD *thd)
......
...@@ -346,7 +346,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, ...@@ -346,7 +346,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
if (cache->cols() == 1) if (cache->cols() == 1)
{ {
if (args[0]->used_tables()) if (args[0]->used_tables())
cache->set_used_tables(RAND_TABLE_BIT); cache->set_used_tables(OUTER_REF_TABLE_BIT);
else else
cache->set_used_tables(0); cache->set_used_tables(0);
} }
...@@ -356,7 +356,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, ...@@ -356,7 +356,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
for (uint i= 0; i < n; i++) for (uint i= 0; i < n; i++)
{ {
if (args[0]->el(i)->used_tables()) if (args[0]->el(i)->used_tables())
((Item_cache *)cache->el(i))->set_used_tables(RAND_TABLE_BIT); ((Item_cache *)cache->el(i))->set_used_tables(OUTER_REF_TABLE_BIT);
else else
((Item_cache *)cache->el(i))->set_used_tables(0); ((Item_cache *)cache->el(i))->set_used_tables(0);
} }
......
...@@ -128,7 +128,7 @@ void Item_subselect::fix_length_and_dec() ...@@ -128,7 +128,7 @@ void Item_subselect::fix_length_and_dec()
inline table_map Item_subselect::used_tables() const inline table_map Item_subselect::used_tables() const
{ {
return (table_map) (engine->dependent() ? 1L : return (table_map) (engine->dependent() ? 1L :
(engine->uncacheable() ? RAND_TABLE_BIT : 0L)); (engine->uncacheable() ? OUTER_REF_TABLE_BIT : 0L));
} }
Item_singlerow_subselect::Item_singlerow_subselect(THD *thd, Item_singlerow_subselect::Item_singlerow_subselect(THD *thd,
......
...@@ -1348,7 +1348,7 @@ static int group_concat_key_cmp_with_distinct(void* arg, byte* key1, ...@@ -1348,7 +1348,7 @@ static int group_concat_key_cmp_with_distinct(void* arg, byte* key1,
byte* key2) byte* key2)
{ {
Item_func_group_concat* item= (Item_func_group_concat*)arg; Item_func_group_concat* item= (Item_func_group_concat*)arg;
for (int i= 0; i<item->arg_count_field; i++) for (uint i= 0; i < item->arg_count_field; i++)
{ {
Item *field_item= item->expr[i]; Item *field_item= item->expr[i];
Field *field= field_item->tmp_table_field(); Field *field= field_item->tmp_table_field();
...@@ -1377,7 +1377,7 @@ static int group_concat_key_cmp_with_distinct(void* arg, byte* key1, ...@@ -1377,7 +1377,7 @@ static int group_concat_key_cmp_with_distinct(void* arg, byte* key1,
static int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) static int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2)
{ {
Item_func_group_concat* item= (Item_func_group_concat*)arg; Item_func_group_concat* item= (Item_func_group_concat*)arg;
for (int i=0; i<item->arg_count_order; i++) for (uint i=0; i < item->arg_count_order; i++)
{ {
ORDER *order_item= item->order[i]; ORDER *order_item= item->order[i];
Item *item= *order_item->item; Item *item= *order_item->item;
...@@ -1428,7 +1428,7 @@ static int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), ...@@ -1428,7 +1428,7 @@ static int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
tmp.length(0); tmp.length(0);
for (int i= 0; i < group_concat_item->arg_show_fields; i++) for (uint i= 0; i < group_concat_item->arg_show_fields; i++)
{ {
Item *show_item= group_concat_item->expr[i]; Item *show_item= group_concat_item->expr[i];
if (!show_item->const_item()) if (!show_item->const_item())
...@@ -1482,13 +1482,13 @@ static int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), ...@@ -1482,13 +1482,13 @@ static int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
is_separator - string value of separator is_separator - string value of separator
*/ */
Item_func_group_concat::Item_func_group_concat(int is_distinct, Item_func_group_concat::Item_func_group_concat(bool is_distinct,
List<Item> *is_select, List<Item> *is_select,
SQL_LIST *is_order, SQL_LIST *is_order,
String *is_separator) String *is_separator)
:Item_sum(), tmp_table_param(0), warning_available(false), :Item_sum(), tmp_table_param(0), warning_available(false),
separator(is_separator), tree(&tree_base), table(0), distinct(is_distinct), separator(is_separator), tree(&tree_base), table(0),
tree_mode(0), count_cut_values(0) count_cut_values(0), tree_mode(0), distinct(is_distinct)
{ {
original= 0; original= 0;
quick_group= 0; quick_group= 0;
...@@ -1507,39 +1507,31 @@ Item_func_group_concat::Item_func_group_concat(int is_distinct, ...@@ -1507,39 +1507,31 @@ Item_func_group_concat::Item_func_group_concat(int is_distinct,
expr - arg_count_field expr - arg_count_field
order - arg_count_order order - arg_count_order
*/ */
args= (Item**)sql_alloc(sizeof(Item*)*(arg_count+arg_count_order+arg_count_field)+ args= (Item**) sql_alloc(sizeof(Item*)*(arg_count+arg_count_order+
arg_count_field)+
sizeof(ORDER*)*arg_count_order); sizeof(ORDER*)*arg_count_order);
if (!args) if (!args)
{ return; // thd->fatal is set
my_error(ER_OUTOFMEMORY,MYF(0));
}
expr= args; expr= args;
expr+= arg_count+arg_count_order; expr+= arg_count+arg_count_order;
if (arg_count_order)
{ /* fill args items of show and sort */
order= (ORDER**)(expr + arg_count_field);
}
/*
fill args items of show and sort
*/
int i= 0; int i= 0;
List_iterator_fast<Item> li(*is_select); List_iterator_fast<Item> li(*is_select);
Item *item_select; Item *item_select;
while ((item_select= li++)) for ( ; (item_select= li++) ; i++)
{
args[i]= expr[i]= item_select; args[i]= expr[i]= item_select;
i++;
}
if (order) if (arg_count_order)
{ {
uint j= 0; i= 0;
for (ORDER *order_item= (ORDER*)is_order->first; order= (ORDER**)(expr + arg_count_field);
for (ORDER *order_item= (ORDER*) is_order->first;
order_item != NULL; order_item != NULL;
order_item= order_item->next) order_item= order_item->next)
{ {
order[j++]= order_item; order[i++]= order_item;
} }
} }
} }
...@@ -1562,7 +1554,6 @@ Item_func_group_concat::~Item_func_group_concat() ...@@ -1562,7 +1554,6 @@ Item_func_group_concat::~Item_func_group_concat()
} }
if (table) if (table)
free_tmp_table(thd, table); free_tmp_table(thd, table);
if (tmp_table_param)
delete tmp_table_param; delete tmp_table_param;
if (tree_mode) if (tree_mode)
delete_tree(tree); delete_tree(tree);
...@@ -1594,14 +1585,17 @@ bool Item_func_group_concat::add() ...@@ -1594,14 +1585,17 @@ bool Item_func_group_concat::add()
copy_funcs(tmp_table_param->items_to_copy); copy_funcs(tmp_table_param->items_to_copy);
bool record_is_null= TRUE; bool record_is_null= TRUE;
for (int i= 0; i < arg_show_fields; i++) for (uint i= 0; i < arg_show_fields; i++)
{ {
Item *show_item= expr[i]; Item *show_item= expr[i];
if (!show_item->const_item()) if (!show_item->const_item())
{ {
Field *f= show_item->tmp_table_field(); Field *f= show_item->tmp_table_field();
if (!f->is_null()) if (!f->is_null())
{
record_is_null= FALSE; record_is_null= FALSE;
break;
}
} }
} }
if (record_is_null) if (record_is_null)
......
...@@ -643,21 +643,20 @@ class Item_func_group_concat : public Item_sum ...@@ -643,21 +643,20 @@ class Item_func_group_concat : public Item_sum
public: public:
String result; String result;
String *separator; String *separator;
uint show_elements;
TREE tree_base; TREE tree_base;
TREE *tree; TREE *tree;
TABLE *table; TABLE *table;
int arg_count_order;
int arg_count_field;
int arg_show_fields;
int distinct;
Item **expr; Item **expr;
ORDER **order; ORDER **order;
bool tree_mode; TABLE_LIST *tables_list;
int count_cut_values;
ulong group_concat_max_len; ulong group_concat_max_len;
uint show_elements;
uint arg_count_order;
uint arg_count_field;
uint arg_show_fields;
uint count_cut_values;
bool tree_mode, distinct;
bool warning_for_row; bool warning_for_row;
TABLE_LIST *tables_list;
bool always_null; bool always_null;
/* /*
Following is 0 normal object and pointer to original one for copy Following is 0 normal object and pointer to original one for copy
...@@ -665,7 +664,7 @@ class Item_func_group_concat : public Item_sum ...@@ -665,7 +664,7 @@ class Item_func_group_concat : public Item_sum
*/ */
Item_func_group_concat *original; Item_func_group_concat *original;
Item_func_group_concat(int is_distinct,List<Item> *is_select, Item_func_group_concat(bool is_distinct,List<Item> *is_select,
SQL_LIST *is_order,String *is_separator); SQL_LIST *is_order,String *is_separator);
Item_func_group_concat(THD *thd, Item_func_group_concat &item) Item_func_group_concat(THD *thd, Item_func_group_concat &item)
...@@ -675,20 +674,20 @@ class Item_func_group_concat : public Item_sum ...@@ -675,20 +674,20 @@ class Item_func_group_concat : public Item_sum
warning(item.warning), warning(item.warning),
warning_available(item.warning_available), warning_available(item.warning_available),
separator(item.separator), separator(item.separator),
show_elements(item.show_elements),
tree(item.tree), tree(item.tree),
table(item.table), table(item.table),
expr(item.expr),
order(item.order),
tables_list(item.tables_list),
group_concat_max_len(item.group_concat_max_len),
show_elements(item.show_elements),
arg_count_order(item.arg_count_order), arg_count_order(item.arg_count_order),
arg_count_field(item.arg_count_field), arg_count_field(item.arg_count_field),
arg_show_fields(item.arg_show_fields), arg_show_fields(item.arg_show_fields),
distinct(item.distinct),
expr(item.expr),
order(item.order),
tree_mode(0),
count_cut_values(item.count_cut_values), count_cut_values(item.count_cut_values),
group_concat_max_len(item.group_concat_max_len), tree_mode(0),
distinct(item.distinct),
warning_for_row(item.warning_for_row), warning_for_row(item.warning_for_row),
tables_list(item.tables_list),
original(&item) original(&item)
{ {
quick_group = 0; quick_group = 0;
......
...@@ -767,6 +767,7 @@ int MYSQL_LOG::purge_logs(const char *to_log, ...@@ -767,6 +767,7 @@ int MYSQL_LOG::purge_logs(const char *to_log,
!log_in_use(log_info.log_file_name)) !log_in_use(log_info.log_file_name))
{ {
ulong tmp; ulong tmp;
LINT_INIT(tmp);
if (decrease_log_space) //stat the file we want to delete if (decrease_log_space) //stat the file we want to delete
{ {
MY_STAT s; MY_STAT s;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#undef write /* remove pthread.h macro definition for EMX */ #undef write /* remove pthread.h macro definition for EMX */
#endif #endif
typedef ulong table_map; /* Used for table bits in join */ typedef ulonglong table_map; /* Used for table bits in join */
typedef ulong key_map; /* Used for finding keys */ typedef ulong key_map; /* Used for finding keys */
typedef ulong key_part_map; /* Used for finding key parts */ typedef ulong key_part_map; /* Used for finding key parts */
...@@ -846,6 +846,7 @@ void end_read_record(READ_RECORD *info); ...@@ -846,6 +846,7 @@ void end_read_record(READ_RECORD *info);
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder, ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
uint s_length, SQL_SELECT *select, uint s_length, SQL_SELECT *select,
ha_rows max_rows, ha_rows *examined_rows); ha_rows max_rows, ha_rows *examined_rows);
void filesort_free_buffers(TABLE *table);
void change_double_for_sort(double nr,byte *to); void change_double_for_sort(double nr,byte *to);
int get_quick_record(SQL_SELECT *select); int get_quick_record(SQL_SELECT *select);
int calc_weekday(long daynr,bool sunday_first_day_of_week); int calc_weekday(long daynr,bool sunday_first_day_of_week);
......
...@@ -134,19 +134,7 @@ void end_read_record(READ_RECORD *info) ...@@ -134,19 +134,7 @@ void end_read_record(READ_RECORD *info)
} }
if (info->table) if (info->table)
{ {
TABLE *table= info->table; filesort_free_buffers(info->table);
if (table->sort.record_pointers)
{
my_free((gptr) table->sort.record_pointers,MYF(0));
table->sort.record_pointers=0;
}
if (table->sort.addon_buf)
{
my_free((char *) table->sort.addon_buf, MYF(0));
my_free((char *) table->sort.addon_field, MYF(MY_ALLOW_ZERO_PTR));
table->sort.addon_buf=0;
table->sort.addon_field=0;
}
(void) info->file->extra(HA_EXTRA_NO_CACHE); (void) info->file->extra(HA_EXTRA_NO_CACHE);
(void) info->file->rnd_end(); (void) info->file->rnd_end();
info->table=0; info->table=0;
......
...@@ -868,12 +868,14 @@ JOIN::reinit() ...@@ -868,12 +868,14 @@ JOIN::reinit()
exec_tmp_table1->file->extra(HA_EXTRA_RESET_STATE); exec_tmp_table1->file->extra(HA_EXTRA_RESET_STATE);
exec_tmp_table1->file->delete_all_rows(); exec_tmp_table1->file->delete_all_rows();
free_io_cache(exec_tmp_table1); free_io_cache(exec_tmp_table1);
filesort_free_buffers(exec_tmp_table1);
} }
if (exec_tmp_table2) if (exec_tmp_table2)
{ {
exec_tmp_table2->file->extra(HA_EXTRA_RESET_STATE); exec_tmp_table2->file->extra(HA_EXTRA_RESET_STATE);
exec_tmp_table2->file->delete_all_rows(); exec_tmp_table2->file->delete_all_rows();
free_io_cache(exec_tmp_table2); free_io_cache(exec_tmp_table2);
filesort_free_buffers(exec_tmp_table2);
} }
if (items0) if (items0)
memcpy(ref_pointer_array, items0, ref_pointer_array_size); memcpy(ref_pointer_array, items0, ref_pointer_array_size);
...@@ -2319,7 +2321,8 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, ...@@ -2319,7 +2321,8 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
we don't make rec less than 100. we don't make rec less than 100.
*/ */
if (keyuse->used_tables & if (keyuse->used_tables &
(map=(keyuse->used_tables & ~join->const_table_map))) (map=(keyuse->used_tables & ~join->const_table_map &
~OUTER_REF_TABLE_BIT)))
{ {
uint tablenr; uint tablenr;
for (tablenr=0 ; ! (map & 1) ; map>>=1, tablenr++) ; for (tablenr=0 ; ! (map & 1) ; map>>=1, tablenr++) ;
...@@ -2631,7 +2634,7 @@ static double ...@@ -2631,7 +2634,7 @@ static double
prev_record_reads(JOIN *join,table_map found_ref) prev_record_reads(JOIN *join,table_map found_ref)
{ {
double found=1.0; double found=1.0;
found_ref&= ~OUTER_REF_TABLE_BIT;
for (POSITION *pos=join->positions ; found_ref ; pos++) for (POSITION *pos=join->positions ; found_ref ; pos++)
{ {
if (pos->table->table->map & found_ref) if (pos->table->table->map & found_ref)
...@@ -2665,7 +2668,7 @@ get_best_combination(JOIN *join) ...@@ -2665,7 +2668,7 @@ get_best_combination(JOIN *join)
join->full_join=0; join->full_join=0;
used_tables=0; used_tables= OUTER_REF_TABLE_BIT; // Outer row is already read
for (j=join_tab, tablenr=0 ; tablenr < table_count ; tablenr++,j++) for (j=join_tab, tablenr=0 ; tablenr < table_count ; tablenr++,j++)
{ {
TABLE *form; TABLE *form;
...@@ -2936,7 +2939,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -2936,7 +2939,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
DBUG_RETURN(1); // Impossible const condition DBUG_RETURN(1); // Impossible const condition
} }
} }
used_tables=(select->const_tables=join->const_table_map) | RAND_TABLE_BIT; used_tables=((select->const_tables=join->const_table_map) |
OUTER_REF_TABLE_BIT | RAND_TABLE_BIT);
for (uint i=join->const_tables ; i < join->tables ; i++) for (uint i=join->const_tables ; i < join->tables ; i++)
{ {
JOIN_TAB *tab=join->join_tab+i; JOIN_TAB *tab=join->join_tab+i;
...@@ -2946,7 +2950,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -2946,7 +2950,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
It solve problem with select like SELECT * FROM t1 WHERE rand() > 0.5 It solve problem with select like SELECT * FROM t1 WHERE rand() > 0.5
*/ */
if (i == join->tables-1) if (i == join->tables-1)
current_map|= RAND_TABLE_BIT; current_map|= OUTER_REF_TABLE_BIT | RAND_TABLE_BIT;
bool use_quick_range=0; bool use_quick_range=0;
used_tables|=current_map; used_tables|=current_map;
...@@ -3265,7 +3269,10 @@ join_free(JOIN *join, bool full) ...@@ -3265,7 +3269,10 @@ join_free(JOIN *join, bool full)
first non const table in join->table first non const table in join->table
*/ */
if (join->tables > join->const_tables) // Test for not-const tables if (join->tables > join->const_tables) // Test for not-const tables
{
free_io_cache(join->table[join->const_tables]); free_io_cache(join->table[join->const_tables]);
filesort_free_buffers(join->table[join->const_tables]);
}
if (join->select_lex->dependent && !full) if (join->select_lex->dependent && !full)
{ {
for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++) for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
...@@ -3450,7 +3457,8 @@ static void update_depend_map(JOIN *join, ORDER *order) ...@@ -3450,7 +3457,8 @@ static void update_depend_map(JOIN *join, ORDER *order)
table_map depend_map; table_map depend_map;
order->item[0]->update_used_tables(); order->item[0]->update_used_tables();
order->depend_map=depend_map=order->item[0]->used_tables(); order->depend_map=depend_map=order->item[0]->used_tables();
if (!(order->depend_map & RAND_TABLE_BIT)) // Not item_sum() or RAND() // Not item_sum(), RAND() and no reference to table outside of sub select
if (!(order->depend_map & (OUTER_REF_TABLE_BIT | RAND_TABLE_BIT)))
{ {
for (JOIN_TAB **tab=join->map2table; for (JOIN_TAB **tab=join->map2table;
depend_map ; depend_map ;
...@@ -3497,7 +3505,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, bool *simple_order) ...@@ -3497,7 +3505,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, bool *simple_order)
} }
else else
{ {
if (order_tables & RAND_TABLE_BIT) if (order_tables & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT))
*simple_order=0; *simple_order=0;
else else
{ {
...@@ -7428,7 +7436,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables) ...@@ -7428,7 +7436,7 @@ get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables)
DBUG_RETURN(0); DBUG_RETURN(0);
map|=a->item[0]->used_tables(); map|=a->item[0]->used_tables();
} }
if (!map || (map & RAND_TABLE_BIT)) if (!map || (map & (RAND_TABLE_BIT | OUTER_REF_TABLE_BIT)))
DBUG_RETURN(0); DBUG_RETURN(0);
for (; !(map & tables->table->map) ; tables=tables->next) ; for (; !(map & tables->table->map) ; tables=tables->next) ;
......
...@@ -57,7 +57,8 @@ ...@@ -57,7 +57,8 @@
#endif #endif
#define MAX_FIELD_WIDTH 256 /* Max column width +1 */ #define MAX_FIELD_WIDTH 256 /* Max column width +1 */
#define MAX_TABLES (sizeof(table_map)*8-1) /* Max tables in join */ #define MAX_TABLES (sizeof(table_map)*8-2) /* Max tables in join */
#define OUTER_REF_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-2))
#define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1)) #define RAND_TABLE_BIT (((table_map) 1) << (sizeof(table_map)*8-1))
#define MAX_FIELDS 4096 /* Limit in the .frm file */ #define MAX_FIELDS 4096 /* Limit in the .frm file */
......
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