diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2019-07-17 12:31:45 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2019-07-19 18:00:10 +0200 |
commit | f90040fd9ccb99cb4541d181a7052c37dc38decb (patch) | |
tree | 95a9b6d092ba63de4740105c8a2cdfae206e2256 /sql | |
parent | cc86a0bd11a436dfe4df0622481c571f83b1680a (diff) | |
download | mariadb-git-f90040fd9ccb99cb4541d181a7052c37dc38decb.tar.gz |
MDEV-19429: Wrong query result with EXISTS and LIMIT 0bb-5.5-MDEV-19429
Check EXISTS LIMIT before rewriting.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_subselect.cc | 21 | ||||
-rw-r--r-- | sql/sql_lex.cc | 5 |
2 files changed, 16 insertions, 10 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; } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 28f56282bad..fe4dcfd1524 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2456,14 +2456,13 @@ void st_select_lex::print_limit(THD *thd, if (item && unit->global_parameters == this) { Item_subselect::subs_type subs_type= item->substype(); - if (subs_type == Item_subselect::EXISTS_SUBS || - subs_type == Item_subselect::IN_SUBS || + if (subs_type == Item_subselect::IN_SUBS || subs_type == Item_subselect::ALL_SUBS) { return; } } - if (explicit_limit) + if (explicit_limit && select_limit) { str->append(STRING_WITH_LEN(" limit ")); if (offset_limit) |