Hi!
Just to make things easy, here is the patch:
commit a556c4d972eaa09bb8ad586b9bda6cfb2a7b574a
Author: Monty <monty@xxxxxxxxxxx>
Date: Fri Aug 5 17:57:27 2022 +0300
MDEV-12325 Unexpected data type and truncation when using CTE
When creating a recursive CTE, the column types are taken from the
non recursive part of the CTE (this is according to the SQL standard).
This patch adds code to abort the CTE if the calculated values in the
recursive part does not fit in the fields in the created temporary table.
The new code only affects recursive CTE, so it should not cause any notable
problems for old applications.
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 48d8c16db68..d271a919a4e 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -111,6 +111,8 @@ int select_unit::send_data(List<Item> &values)
{
int rc;
int not_reported_error= 0;
+ enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
+
if (unit->offset_limit_cnt)
{ // using limit offset,count
unit->offset_limit_cnt--;
@@ -118,8 +120,10 @@ int select_unit::send_data(List<Item> &values)
}
if (thd->killed == ABORT_QUERY)
return 0;
+
if (table->no_rows_with_nulls)
table->null_catch_flags= CHECK_ROW_FOR_NULLS_TO_REJECT;
+
if (intersect_mark)
{
fill_record(thd, table, table->field + 1, values, TRUE, FALSE);
@@ -127,6 +131,8 @@ int select_unit::send_data(List<Item> &values)
}
else
fill_record(thd, table, table->field, values, TRUE, FALSE);
+ thd->count_cuted_fields= save_count_cuted_fields;
+
if (unlikely(thd->is_error()))
{
rc= 1;
@@ -297,7 +303,13 @@ bool select_unit::send_eof()