summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2022-04-21 15:03:23 +0300
committerSergei Petrunia <sergey@mariadb.com>2022-04-22 13:57:16 +0300
commit3c209bfc040ddfc41ece8357d772547432353fd2 (patch)
tree2fa9324d2e19629451044b6e92e47dde71bd321d /sql/item_subselect.cc
parent2be617d869e614e2c0e7313fd77649a03c891cfd (diff)
downloadmariadb-git-3c209bfc040ddfc41ece8357d772547432353fd2.tar.gz
MDEV-25994: Crash with union of my_decimal type in ORDER BY clause
When single-row subquery fails with "Subquery reutrns more than 1 row" error, it will raise an error and return NULL. On the other hand, Item_singlerow_subselect sets item->maybe_null=0 for table-less subqueries like "(SELECT not_null_value)" (*) This discrepancy (item with maybe_null=0 returning NULL) causes the code in Type_handler_decimal_result::make_sort_key_part() to crash. Fixed this by allowing inference (*) only when the subquery is NOT a UNION.
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index e01c92b7a4f..7033d38c07b 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1266,11 +1266,18 @@ bool Item_singlerow_subselect::fix_length_and_dec()
}
unsigned_flag= value->unsigned_flag;
/*
- If there are not tables in subquery then ability to have NULL value
- depends on SELECT list (if single row subquery have tables then it
- always can be NULL if there are not records fetched).
+ If the subquery has no tables (1) and is not a UNION (2), like:
+
+ (SELECT subq_value)
+
+ then its NULLability is the same as subq_value's NULLability.
+
+ (1): A subquery that uses a table will return NULL when the table is empty.
+ (2): A UNION subquery will return NULL if it produces a "Subquery returns
+ more than one row" error.
*/
- if (engine->no_tables())
+ if (engine->no_tables() &&
+ engine->engine_type() != subselect_engine::UNION_ENGINE)
maybe_null= engine->may_be_null();
else
{