summaryrefslogtreecommitdiff
path: root/mysql-test/main/cte_recursive.test
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2022-08-05 17:57:27 +0300
committerMonty <monty@mariadb.org>2022-08-08 11:19:55 +0300
commita5a9fcdfe44ffb093887a255254d128fe3752fd1 (patch)
tree98be8b5feb50765aa8c802f80edf824c1b9ba2ca /mysql-test/main/cte_recursive.test
parent43c7f6a0f3d2d636fea0decfc9b5818e4a7c885a (diff)
downloadmariadb-git-a5a9fcdfe44ffb093887a255254d128fe3752fd1.tar.gz
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>
Diffstat (limited to 'mysql-test/main/cte_recursive.test')
-rw-r--r--mysql-test/main/cte_recursive.test43
1 files changed, 43 insertions, 0 deletions
diff --git a/mysql-test/main/cte_recursive.test b/mysql-test/main/cte_recursive.test
index 4c4bd99c24c..ca97c2d2900 100644
--- a/mysql-test/main/cte_recursive.test
+++ b/mysql-test/main/cte_recursive.test
@@ -3165,4 +3165,47 @@ SELECT * FROM cte;
DROP TABLE t1;
+--echo #
+--echo # MDEV-12325 Unexpected data type and truncation when using CTE
+--echo #
+
+CREATE TABLE t1
+(
+ id INT, mid INT, name TEXT
+);
+INSERT INTO t1 VALUES (0,NULL,'Name'),(1,0,'Name1'),(2,0,'Name2'),(11,1,'Name11'),(12,1,'Name12');
+
+let $query=
+WITH RECURSIVE
+cteReports (level, id, mid, name) AS
+(
+ SELECT 1, id, mid, name FROM t1 WHERE mid IS NULL
+ UNION ALL
+ SELECT r.level + 1, e.id, e.mid + 1000000000000, e.name FROM t1 e
+ INNER JOIN cteReports r ON e.mid = r.id
+)
+SELECT
+ level, id, mid, name,
+ (SELECT name FROM t1 WHERE id= cteReports.mid) AS mname
+FROM cteReports ORDER BY level, mid;
+
+--error ER_WARN_DATA_OUT_OF_RANGE
+--eval $query
+--error ER_WARN_DATA_OUT_OF_RANGE
+--eval create table t2 as $query;
+--eval create table t2 ignore as $query;
+show create table t2;
+--error ER_WARN_DATA_OUT_OF_RANGE
+--eval insert into t2 $query;
+--eval insert ignore into t2 $query;
+drop table t2;
+set @@sql_mode="";
+--eval $query
+--eval create table t2 as $query;
+show create table t2;
+set @@sql_mode=default;
+drop table t1,t2;
+
+--echo #
--echo # End of 10.3 tests
+--echo #