summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2019-07-26 22:42:35 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2019-07-26 22:42:35 +0200
commitd97342b6f2cfdd55eb0f82b390ebc89c5997c382 (patch)
tree238dbb11c51a2352c99de198586b84f260b3aad9 /sql/item_subselect.cc
parent00a254cc069e77f2088f6fbf8c367f247cfdd0dc (diff)
parent32c6f40a6319d493e5270c72ac5d27dc99d1b242 (diff)
downloadmariadb-git-d97342b6f2cfdd55eb0f82b390ebc89c5997c382.tar.gz
Merge branch '10.2' into 10.3
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 4603a85aa87..1bac7b6e527 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1518,16 +1518,23 @@ bool 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)
- */
- Item *item= new (thd->mem_root) Item_int(thd, (int32) 1);
- if (!item)
- DBUG_RETURN(TRUE);
- thd->change_item_tree(&unit->global_parameters()->select_limit,
- item);
- 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)
+ */
+ Item *item= new (thd->mem_root) Item_int(thd, (int32) 1);
+ if (!item)
+ DBUG_RETURN(TRUE);
+ thd->change_item_tree(&unit->global_parameters()->select_limit,
+ item);
+ unit->global_parameters()->explicit_limit= 1; // we set the limit
+ DBUG_PRINT("info", ("Set limit to 1"));
+ }
DBUG_RETURN(FALSE);
}