summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index afc42dc08d5..9d6fe5ac5ab 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1432,13 +1432,20 @@ void Item_exists_subselect::fix_length_and_dec()
{
DBUG_ENTER("Item_exists_subselect::fix_length_and_dec");
init_length_and_dec();
- /*
- We need only 1 row to determine existence (i.e. any EXISTS that is not
- an IN always requires LIMIT 1)
- */
- thd->change_item_tree(&unit->global_parameters->select_limit,
- new Item_int((int32) 1));
- DBUG_PRINT("info", ("Set limit to 1"));
+ // If limit is not set or it is constant more than 1
+ if (!unit->global_parameters->select_limit ||
+ (unit->global_parameters->select_limit->basic_const_item() &&
+ unit->global_parameters->select_limit->val_int() > 1))
+ {
+ /*
+ We need only 1 row to determine existence (i.e. any EXISTS that is not
+ an IN always requires LIMIT 1)
+ */
+ thd->change_item_tree(&unit->global_parameters->select_limit,
+ new Item_int((int32) 1));
+ unit->global_parameters->explicit_limit= 1; // we set the limit
+ DBUG_PRINT("info", ("Set limit to 1"));
+ }
DBUG_VOID_RETURN;
}