summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorunknown <monty@narttu.mysql.fi>2003-10-07 11:24:38 +0300
committerunknown <monty@narttu.mysql.fi>2003-10-07 11:24:38 +0300
commit890f427fa7e4af0aaa2324641560dd9a33fa85ab (patch)
tree09c2f8151d8de52c74dc9ab670269ec0b07d5356 /sql/item_subselect.cc
parent118d6df516dff65bf883e2615dc4e8d1ff2db142 (diff)
parent18374b97cde958d4b39dbc5d1471b72876cec1c6 (diff)
downloadmariadb-git-890f427fa7e4af0aaa2324641560dd9a33fa85ab.tar.gz
merge
sql/item_subselect.h: Auto merged sql/mysqld.cc: Auto merged
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc69
1 files changed, 33 insertions, 36 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index abe89eb6a76..937d6f61913 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -36,7 +36,7 @@ inline Item * and_items(Item* cond, Item *item)
Item_subselect::Item_subselect():
Item_result_field(), engine_owner(1), value_assigned(0), substitution(0),
- have_to_be_excluded(0), engine_changed(0)
+ engine(0), have_to_be_excluded(0), engine_changed(0)
{
reset();
/*
@@ -46,6 +46,7 @@ Item_subselect::Item_subselect():
null_value= 1;
}
+
void Item_subselect::init(THD *thd, st_select_lex *select_lex,
select_subselect *result)
{
@@ -62,6 +63,7 @@ void Item_subselect::init(THD *thd, st_select_lex *select_lex,
DBUG_VOID_RETURN;
}
+
Item_subselect::~Item_subselect()
{
if (engine_owner)
@@ -767,6 +769,7 @@ Item_in_subselect::row_value_transformer(JOIN *join,
DBUG_RETURN(RES_OK);
}
+
Item_subselect::trans_res
Item_in_subselect::select_transformer(JOIN *join)
{
@@ -776,6 +779,7 @@ Item_in_subselect::select_transformer(JOIN *join)
return row_value_transformer(join, left_expr);
}
+
Item_subselect::trans_res
Item_allany_subselect::select_transformer(JOIN *join)
{
@@ -786,9 +790,9 @@ subselect_single_select_engine::
subselect_single_select_engine(THD *thd,
st_select_lex *select,
select_subselect *result,
- Item_subselect *item):
- subselect_engine(thd, item, result),
- prepared(0), optimized(0), executed(0)
+ Item_subselect *item)
+ :subselect_engine(thd, item, result),
+ prepared(0), optimized(0), executed(0)
{
select_lex= select;
SELECT_LEX_UNIT *unit= select_lex->master_unit();
@@ -807,11 +811,12 @@ subselect_single_select_engine::
this->select_lex= select_lex;
}
+
subselect_union_engine::subselect_union_engine(THD *thd,
st_select_lex_unit *u,
select_subselect *result,
- Item_subselect *item):
- subselect_engine(thd, item, result)
+ Item_subselect *item)
+ :subselect_engine(thd, item, result)
{
unit= u;
if (!result)
@@ -994,6 +999,7 @@ int subselect_union_engine::exec()
return res;
}
+
int subselect_uniquesubquery_engine::exec()
{
DBUG_ENTER("subselect_uniquesubquery_engine::exec");
@@ -1015,34 +1021,22 @@ int subselect_uniquesubquery_engine::exec()
{
error= 0;
table->null_row= 0;
- if (table->status)
- ((Item_in_subselect *) item)->value= 0;
- else
- ((Item_in_subselect *) item)->value= (!cond || cond->val_int()?1:0);
+ ((Item_in_subselect *) item)->value= (!table->status &&
+ (!cond || cond->val_int()) ? 1 :
+ 0);
}
}
- DBUG_RETURN(end_exec(table) || (error != 0));
+ DBUG_RETURN(error != 0);
}
-int subselect_uniquesubquery_engine::end_exec(TABLE *table)
+
+subselect_uniquesubquery_engine::~subselect_uniquesubquery_engine()
{
- DBUG_ENTER("subselect_uniquesubquery_engine::end_exec");
- int error=0, tmp;
- if ((tmp= table->file->extra(HA_EXTRA_NO_CACHE)))
- {
- DBUG_PRINT("error", ("extra(HA_EXTRA_NO_CACHE) failed"));
- error= 1;
- }
- if ((tmp= table->file->index_end()))
- {
- DBUG_PRINT("error", ("index_end() failed"));
- error= 1;
- }
- if (error == 1)
- table->file->print_error(tmp, MYF(0));
- DBUG_RETURN(error != 0);
+ /* Tell handler we don't need the index anymore */
+ tab->table->file->index_end();
}
+
int subselect_indexsubquery_engine::exec()
{
DBUG_ENTER("subselect_indexsubselect_engine::exec");
@@ -1051,9 +1045,11 @@ int subselect_indexsubquery_engine::exec()
TABLE *table= tab->table;
((Item_in_subselect *) item)->value= 0;
+
if (check_null)
{
- *tab->null_ref_key= 0;
+ /* We need to check for NULL if there wasn't a matching value */
+ *tab->null_ref_key= 0; // Search first for not null
((Item_in_subselect *) item)->was_null= 0;
}
@@ -1071,7 +1067,7 @@ int subselect_indexsubquery_engine::exec()
error= report_error(table, error);
else
{
- for(;;)
+ for (;;)
{
error= 0;
table->null_row= 0;
@@ -1083,7 +1079,7 @@ int subselect_indexsubquery_engine::exec()
((Item_in_subselect *) item)->was_null= 1;
else
((Item_in_subselect *) item)->value= 1;
- goto finish;
+ break;
}
error= table->file->index_next_same(table->record[0],
tab->ref.key_buff,
@@ -1091,25 +1087,26 @@ int subselect_indexsubquery_engine::exec()
if (error && error != HA_ERR_END_OF_FILE)
{
error= report_error(table, error);
- goto finish;
+ break;
}
}
else
{
if (!check_null || null_finding)
- goto finish;
+ break; /* We don't need to check nulls */
*tab->null_ref_key= 1;
null_finding= 1;
- if (safe_index_read(tab))
- goto finish;
+ /* Check if there exists a row with a null value in the index */
+ if ((error= safe_index_read(tab)))
+ break;
}
}
}
}
-finish:
- DBUG_RETURN(end_exec(table) || (error != 0));
+ DBUG_RETURN(error != 0);
}
+
uint subselect_single_select_engine::cols()
{
return select_lex->item_list.elements;