summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-02-10 17:59:16 +0200
committerunknown <monty@mashka.mysql.fi>2003-02-10 17:59:16 +0200
commit96273457dd172291892b279c420a770e64e0a5a3 (patch)
treeafc92b80727719cbb09f63c506e547cb0aed94f4 /sql
parented95131e0637d6adb280e3501134dbf7496da3a4 (diff)
downloadmariadb-git-96273457dd172291892b279c420a770e64e0a5a3.tar.gz
Move tmp_table_used to THD
Optimize depending sub querys Remove valgrind warnings libmysqld/lib_sql.cc: Better way to reset errors mysql-test/mysql-test-run.sh: Remove wrong ` mysql-test/r/subselect.result: Don't use table t1 mysql-test/t/subselect.test: Don't use table t1 sql/item.cc: Indentation fix sql/item.h: optimize depending sub querys sql/item_func.cc: Remove warning for uninitalized data sql/item_row.cc: Remove warning sql/item_strfunc.h: Fixed memory overrun sql/item_subselect.cc: Better debugging names sql/log_event.cc: Move tmp_table_used to THD sql/sql_base.cc: Move tmp_table_used to THD sql/sql_class.cc: Move tmp_table_used to THD sql/sql_class.h: Move tmp_table_used to THD sql/sql_lex.cc: Move tmp_table_used to THD sql/sql_lex.h: Move tmp_table_used to THD sql/sql_parse.cc: Move tmp_table_used to THD sql/sql_select.cc: optimize depending sub querys sql/sql_table.cc: Move tmp_table_used to THD
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc2
-rw-r--r--sql/item.h9
-rw-r--r--sql/item_func.cc4
-rw-r--r--sql/item_row.cc2
-rw-r--r--sql/item_strfunc.h2
-rw-r--r--sql/item_subselect.cc4
-rw-r--r--sql/log_event.cc2
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_lex.cc4
-rw-r--r--sql/sql_lex.h3
-rw-r--r--sql/sql_parse.cc1
-rw-r--r--sql/sql_select.cc20
-rw-r--r--sql/sql_table.cc4
15 files changed, 35 insertions, 27 deletions
diff --git a/sql/item.cc b/sql/item.cc
index d6f0d59e058..ee7af1ae0fd 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -286,7 +286,7 @@ table_map Item_field::used_tables() const
{
if (field->table->const_table)
return 0; // const item
- return (depended_from? RAND_TABLE_BIT : field->table->map);
+ return (depended_from ? RAND_TABLE_BIT : field->table->map);
}
Item *Item_field::get_tmp_table_item(THD *thd)
diff --git a/sql/item.h b/sql/item.h
index 8c7914cefeb..531817c4844 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -102,6 +102,7 @@ public:
virtual void save_in_result_field(bool no_conversions) {}
virtual void no_rows_in_result() {}
virtual Item *copy_or_same(THD *thd) { return this; }
+ virtual Item *real_item() { return this; }
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
virtual bool binary() const
@@ -468,9 +469,10 @@ class Item_ref :public Item_ident
public:
Field *result_field; /* Save result here */
Item **ref;
- Item_ref(char *db_par,char *table_name_par,char *field_name_par)
+ Item_ref(const char *db_par, const char *table_name_par,
+ const char *field_name_par)
:Item_ident(db_par,table_name_par,field_name_par),ref(0) {}
- Item_ref(Item **item, char *table_name_par,char *field_name_par)
+ Item_ref(Item **item, const char *table_name_par, const char *field_name_par)
:Item_ident(NullS,table_name_par,field_name_par),ref(item) {}
// Constructor need to process subselect with temporary tables (see Item)
Item_ref(THD *thd, Item_ref &item)
@@ -521,6 +523,7 @@ public:
{
(*ref)->save_in_field(result_field, no_conversions);
}
+ Item *real_item() { return *ref; }
};
class Item_in_subselect;
@@ -530,7 +533,7 @@ protected:
Item_in_subselect* owner;
public:
Item_ref_null_helper(Item_in_subselect* master, Item **item,
- char *table_name_par, char *field_name_par):
+ const char *table_name_par, const char *field_name_par):
Item_ref(item, table_name_par, field_name_par), owner(master) {}
double val();
longlong val_int();
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 6494573458c..788961a954d 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -120,10 +120,10 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
used_tables_cache|=(*arg)->used_tables();
const_item_cache&= (*arg)->const_item();
}
- if (result_type() == STRING_RESULT)
- set_charset((*args)->charset());
}
fix_length_and_dec();
+ if (result_type() == STRING_RESULT)
+ set_charset((*args)->charset());
fixed= 1;
return 0;
}
diff --git a/sql/item_row.cc b/sql/item_row.cc
index 23cafe7ec31..cf745e21e45 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -26,7 +26,7 @@
*/
Item_row::Item_row(List<Item> &arg):
- Item(), used_tables_cache(0), array_holder(1), const_item_cache(1)
+ Item(), used_tables_cache(0), array_holder(1), const_item_cache(1), with_null(0)
{
//TODO: think placing 2-3 component items in item (as it done for function)
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 3a7810fa306..b2e54474494 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -262,7 +262,7 @@ public:
class Item_func_old_password :public Item_str_func
{
- char tmp_value[16]; /* old password length */
+ char tmp_value[17]; /* old password length +1 */
public:
Item_func_old_password(Item *a) :Item_str_func(a) {}
String *val_str(String *);
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 21acb31a7d5..fb51b5561e9 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -489,8 +489,8 @@ void Item_in_subselect::single_value_transformer(THD *thd,
sl->order_list.elements + sl->group_list.elements);
item= (*func)(expr, new Item_ref_null_helper(this,
sl->ref_pointer_array,
- (char *)"<no matter>",
- (char*)"<result>"));
+ (char *)"<ref>",
+ this->full_name()));
sl->having= and_items(sl->having, item);
}
else
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 34e3deebf69..0631e21fbd1 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -766,7 +766,7 @@ int Query_log_event::write_data(IO_CACHE* file)
#ifndef MYSQL_CLIENT
Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
ulong query_length, bool using_trans)
- :Log_event(thd_arg, !thd_arg->lex.tmp_table_used ?
+ :Log_event(thd_arg, !thd_arg->tmp_table_used ?
0 : LOG_EVENT_THREAD_SPECIFIC_F, using_trans),
data_buf(0), query(query_arg),
db(thd_arg->db), q_len((uint32) query_length),
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index f4a32b482b3..97c92ff2b8f 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -792,7 +792,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
DBUG_RETURN(0);
}
table->query_id=thd->query_id;
- thd->lex.tmp_table_used= 1;
+ thd->tmp_table_used= 1;
goto reset;
}
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 4d78a03289b..23a8a6fa8f1 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -87,7 +87,7 @@ THD::THD():user_time(0), is_fatal_error(0),
locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password=
query_start_used=prepare_command=0;
db_length=query_length=col_access=0;
- query_error=0;
+ query_error= tmp_table_used= 0;
next_insert_id=last_insert_id=0;
open_tables= temporary_tables= handler_tables= derived_tables= 0;
current_tablenr=0;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 51067d94990..2d492b19a2b 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -550,6 +550,7 @@ public:
bool query_error, bootstrap, cleanup_done;
bool volatile killed;
bool prepare_command;
+ bool tmp_table_used;
/*
If we do a purge of binary logs, log index info of the threads
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 6bb81de5fcf..29d56905788 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -167,7 +167,6 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->slave_thd_opt=0;
lex->sql_command=SQLCOM_END;
lex->safe_to_cache_query= 1;
- lex->tmp_table_used= 0;
bzero(&lex->mi,sizeof(lex->mi));
return lex;
}
@@ -1051,8 +1050,7 @@ void st_select_lex::init_select()
use_index.empty();
ftfunc_list_alloc.empty();
ftfunc_list= &ftfunc_list_alloc;
- if (linkage != UNION_TYPE)
- linkage= UNSPECIFIED_TYPE;
+ linkage= UNSPECIFIED_TYPE;
}
/*
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 3ce865e7b39..4ef8ffa840e 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -221,9 +221,11 @@ public:
static void *operator new(size_t size)
{
+ // TODO: Change to alloc() and explicitely clear elements in constructors
return (void*) sql_calloc((uint) size);
}
static void operator delete(void *ptr,size_t size) {}
+ st_select_lex_node() {}
virtual ~st_select_lex_node() {}
inline st_select_lex_node* get_master() { return master; }
virtual void init_query();
@@ -475,7 +477,6 @@ typedef struct st_lex
uint slave_thd_opt;
CHARSET_INFO *charset;
char *help_arg;
- bool tmp_table_used;
inline void uncacheable()
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index d9bfc901475..08e37a5576b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3181,6 +3181,7 @@ mysql_init_query(THD *thd)
thd->sent_row_count= thd->examined_row_count= 0;
thd->is_fatal_error= thd->rand_used= 0;
thd->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
+ thd->tmp_table_used= 0;
if (opt_bin_log)
reset_dynamic(&thd->user_var_events);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 00f7ed9bfc9..4543c6bc5d0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1902,9 +1902,10 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
case Item_func::OPTIMIZE_NONE:
break;
case Item_func::OPTIMIZE_KEY:
- if (cond_func->key_item()->type() == Item::FIELD_ITEM)
+ if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM)
add_key_field(key_fields,*and_level,
- ((Item_field*) (cond_func->key_item()))->field,
+ ((Item_field*) (cond_func->key_item()->real_item()))
+ ->field,
0,(Item*) 0,usable_tables);
break;
case Item_func::OPTIMIZE_OP:
@@ -1912,18 +1913,20 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
bool equal_func=(cond_func->functype() == Item_func::EQ_FUNC ||
cond_func->functype() == Item_func::EQUAL_FUNC);
- if (cond_func->arguments()[0]->type() == Item::FIELD_ITEM)
+ if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM)
{
add_key_field(key_fields,*and_level,
- ((Item_field*) (cond_func->arguments()[0]))->field,
+ ((Item_field*) (cond_func->arguments()[0])->real_item())
+ ->field,
equal_func,
(cond_func->arguments()[1]),usable_tables);
}
- if (cond_func->arguments()[1]->type() == Item::FIELD_ITEM &&
+ if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM &&
cond_func->functype() != Item_func::LIKE_FUNC)
{
add_key_field(key_fields,*and_level,
- ((Item_field*) (cond_func->arguments()[1]))->field,
+ ((Item_field*) (cond_func->arguments()[1])->real_item())
+ ->field,
equal_func,
(cond_func->arguments()[0]),usable_tables);
}
@@ -1931,10 +1934,11 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level,
}
case Item_func::OPTIMIZE_NULL:
/* column_name IS [NOT] NULL */
- if (cond_func->arguments()[0]->type() == Item::FIELD_ITEM)
+ if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM)
{
add_key_field(key_fields,*and_level,
- ((Item_field*) (cond_func->arguments()[0]))->field,
+ ((Item_field*) (cond_func->arguments()[0])->real_item())
+ ->field,
cond_func->functype() == Item_func::ISNULL_FUNC,
new Item_null, usable_tables);
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 9738e1dd86d..66168459c7a 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -250,7 +250,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
wrong_tables.append(String(table->real_name,default_charset_info));
}
}
- thd->lex.tmp_table_used= tmp_table_deleted;
+ thd->tmp_table_used= tmp_table_deleted;
if (some_tables_deleted || tmp_table_deleted)
{
query_cache_invalidate3(thd, tables, 0);
@@ -885,7 +885,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name,
(void) rm_temporary_table(create_info->db_type, path);
goto end;
}
- thd->lex.tmp_table_used= 1;
+ thd->tmp_table_used= 1;
}
if (!tmp_table && !no_log)
{