1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

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.

Other things:
- Fixed that we get correct row numbers for warnings generated with
  WITH RECURSIVE

Reviewer: Alexander Barkov <bar@mariadb.com>
This commit is contained in:
Monty
2022-08-05 17:57:27 +03:00
parent 43c7f6a0f3
commit a5a9fcdfe4
6 changed files with 223 additions and 3 deletions

View File

@ -297,7 +297,27 @@ bool select_unit::send_eof()
int select_union_recursive::send_data(List<Item> &values)
{
int rc= select_unit::send_data(values);
int rc;
bool save_abort_on_warning= thd->abort_on_warning;
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
long save_counter;
/*
For recursive CTE's give warnings for wrong field info
However, we don't do that for CREATE TABLE ... SELECT or INSERT ... SELECT
as the upper level code for these handles setting of abort_on_warning
depending on if 'IGNORE' is used.
*/
if (thd->lex->sql_command != SQLCOM_CREATE_TABLE &&
thd->lex->sql_command != SQLCOM_INSERT_SELECT)
thd->abort_on_warning= thd->is_strict_mode();
thd->count_cuted_fields= CHECK_FIELD_WARN;
save_counter= thd->get_stmt_da()->set_current_row_for_warning(++row_counter);
rc= select_unit::send_data(values);
thd->get_stmt_da()->set_current_row_for_warning(save_counter);
thd->count_cuted_fields= save_count_cuted_fields;
thd->abort_on_warning= save_abort_on_warning;
if (rc == 0 &&
write_err != HA_ERR_FOUND_DUPP_KEY &&
@ -476,6 +496,7 @@ void select_union_recursive::cleanup()
thd->rec_tables= tab;
tbl->derived_result= 0;
}
row_counter= 0;
}