Commit graph

56 commits

Author SHA1 Message Date
Michael Widenius
a7abddeffa Create 'main' test directory and move 't' and 'r' there 2018-03-29 13:59:44 +03:00
Igor Babaev
907b236112 Fixed MDEV-14883 Usage of EXCEPT and INTERSECT in recursive CTE
is not supported

Allowed to use recursive references in derived tables.
As a result usage of recursive references in operands of
INTERSECT / EXCEPT is now supported.
2018-02-22 10:26:56 -08:00
Marko Mäkelä
b006d2ead4 Merge bb-10.2-ext into 10.3 2018-02-15 10:22:03 +02:00
Alexander Barkov
3cad31f2a7 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-02-08 19:06:25 +04:00
Igor Babaev
2ef41622e2 Fixed mdev-15162 Query with CTE hangs if assignment operator (:=) is used
If setting user variable was used in the specification of a recursive CTE
then Item_func_set_user_var::fix_fields() went into an infinite loop.
2018-02-06 12:12:19 -08:00
Igor Babaev
f271100836 Fixed mdev-15162 Query with CTE hangs if assignment operator (:=) is used
If setting user variable was used in the specification of a recursive CTE
then Item_func_set_user_var::fix_fields() went into an infinite loop.
2018-02-05 18:07:31 -08:00
Marko Mäkelä
cca611d1c0 Merge 10.2 into bb-10.2-ext 2018-01-11 18:00:31 +02:00
Igor Babaev
7d201d7b30 Fixed mdev-14879 Lost rows for query using recursive CTE
with recursive reference in subquery

If a recursive CTE uses a subquery with recursive reference then
the virtual function reset() must be called after each iteration
performed at the execution of the CTE.
2018-01-09 09:29:16 -08:00
Igor Babaev
15b1840f43 Added the test case from for mdev-14777: Crash in MariaDB 10.2.12 on query
using VIEW and WITH RECURSIVE.

The cause of this crash was the same as of the crash reported in mdev-14755.
2018-01-05 12:13:23 -08:00
Marko Mäkelä
028e91f380 Merge 10.2 into bb-10.2-ext 2017-12-19 17:12:14 +02:00
Galina Shalygina
079c359971 MDEV-14629: failing assertion when a user-defined variable is defined by the recursive CTE
During the user-defined variable defined by the recursive CTE handling procedure
check_dependencies_in_with_clauses that checks dependencies between the tables
that are defined in the CTE and find recursive definitions wasn't called.
2017-12-19 11:49:40 +02:00
Monty
0bb0d52221 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Conflicts:
	mysql-test/r/cte_recursive.result
	mysql-test/r/derived_cond_pushdown.result
	mysql-test/t/cte_recursive.test
	mysql-test/t/derived_cond_pushdown.test
	sql/datadict.cc
	sql/handler.cc
2017-11-09 23:21:41 +02:00
Igor Babaev
e0cd6f4b07 Fixed bugs: mdev-13780 CTE not found, mdev-14184 recursive CTE not found
The support of embedded CTEs was not correct in the cases when
embedded CTEs were used multiple times. The problems occurred with
both non-recursive (bug mdev-13780) and recursive (bug mdev-14184)
embedded CTEs.
2017-11-05 18:46:05 -08:00
Alexander Barkov
98b3f28862 MDEV-14217 [db crash] Recursive CTE when SELECT includes new field 2017-11-05 22:22:01 +04:00
Igor Babaev
7a29ca2776 Fixed the bug mdev-12563.
The bug happened when the specification of a recursive CTE had
no recursive references at the top level of the specification.
In this case the regular processing of derived table references
of the select containing a non-recursive reference to this
recursive CTE misses handling the specification unit.
At the preparation stage any non-recursive reference to a
recursive CTE must be handled after the preparation of the
specification unit for this CTE. So we have to force this
preparation when regular handling of derived tables does not
do it.
2017-04-28 21:59:11 -07:00
Igor Babaev
c7a153453e Fixed the bug mdev-12556.
When the rows produced on the current iteration are sent to the
temporary table T of the UNION type created for CTE the rows
that were not there simultaneously are sent to the temporary
table D that contains rows for the next iteration. The test
whether a row was in T checks the return code of writing into T.
If just a HEAP table is used for T then the return code is
HA_ERR_FOUND_DUPP_KEY, but if an ARIA table is used for T then
the return code is HA_ERR_FOUND_DUPP_UNIQUE.
The implementation of select_union_recursive::send_data()
erroneously checked only for the first return code. So if an Aria
table was used for T then all rows produced by the current iteration
went to D and and in most cases D grew with each iteration.
Whether T has reached stabilization is detected by
checking whether D is empty. So as a result, the iterations were
never stopped unless a limit for them was set.

Fixed by checking for both HA_ERR_FOUND_DUPP_KEY and
HA_ERR_FOUND_DUPP_UNIQUE as return codes returned by
the function writing a row into the temporary table T.
2017-04-26 10:16:03 -07:00
Igor Babaev
d66c171e0f Fixed the bug mdev-12554.
When the WHERE condition is always FALSE then JOIN::join_tab is NULL.
2017-04-22 23:45:38 -07:00
Igor Babaev
54a995cd22 Fixed the bug mdev-12519.
This patch fixed some problems that occurred with subqueries that
contained directly or indirectly recursive references to recursive CTEs.

1. A [NOT] IN predicate with a constant left operand and a non-correlated
subquery as the right operand used in the specification of a recursive CTE
was considered as a constant predicate and was evaluated only once.
Now such a predicate is re-evaluated after every iteration of the process
that produces the records of the recursive CTE.
2. The Exists-To-IN transformation could be applied to [NOT] IN predicates
with recursive references. This opened a possibility of materialization
for the subqueries used as right operands. Yet, materialization
is prohibited for the subqueries if they contain a recursive reference.
Now the Exists-To-IN transformation cannot be applied for subquery
predicates with recursive references.

The function st_select_lex::check_subqueries_with_recursive_references()
is called now only for the first execution of the SELECT.
2017-04-21 09:33:36 -07:00
Igor Babaev
93dd70ced8 Fixed bug mdev-12375.
The function st_select_lex_unit::exec_recursive() incorrectly determined
that a CTE mutually recursive with some others was stabilized in the case
when the non-recursive part of the CTE returned an empty set. As a result
the server fell into an infinite loop when executing a query using
this CTE.
2017-03-27 14:41:17 -07:00
Igor Babaev
ad7da60ded Fixed bug mdev-12368.
Mutually recursive CTE could cause a crash of the server in the case
when they were not Standard compliant. The crash happened in
mysql_derived_prepare(), because the destructor the derived_result
object created for a CTE that was mutually recursive with some others
was called twice. Yet this destructor should not be called for resursive
references.
2017-03-26 23:00:28 -07:00
Igor Babaev
5a4537f092 Fixed bug mdev-12360.
The method With_element::check_unrestricted_recursive() icorrectly performed
the check that no recursive reference is not encountered in inner parts of
outer joins. As a result the server reported errors for valid specifications
with outer joins.
2017-03-26 23:00:28 -07:00
Sergei Golubchik
f3914d10b6 Merge branch 'bb-10.2-serg-merge' into 10.2 2017-02-11 09:45:34 +01:00
Sergei Golubchik
2195bb4e41 Merge branch '10.1' into 10.2 2017-02-10 17:01:45 +01:00
Nirbhay Choubey
185d140f19 MDEV-7635: Renamed standards_compliant_cte to standard_compliant_cte 2017-02-10 06:30:42 -05:00
Sergei Golubchik
9f918b9cf4 take into account scientific notation of floats in regex_replace
this fixes occasional main.cte_recursive failures
2017-01-30 17:57:02 +01:00
Igor Babaev
abfcdb8fbc Fixed bug mdev-10773.
The temporary tables created for recursive table references
should be closed in close_thread_tables(), because they might
be used in the statements like ANALYZE WITH r AS (...) SELECT * from r
where r is defined through recursion.
2017-01-28 15:47:11 -08:00
Sergei Petrunia
25e5ce1982 NOT FIXED: MDEV-10773: ANALYZE FORMAT=JSON query_with_CTE crashes
Remove the testcase. It turns out, the crash still happens, just not
on all platforms.
2017-01-18 14:13:11 +03:00
Sergei Petrunia
45f11a729c MDEV-10773: ANALYZE FORMAT=JSON query_with_CTE crashes
Added testcase
2017-01-18 00:56:24 +03:00
Igor Babaev
348ccb6f03 Fixed bug mdev-11674.
1. The rows of a recursive CTE at some point may overflow
the HEAP temporary table containing them. At this point
the table is converted to a MyISAM temporary table and the
new added rows are placed into this MyISAM table.
A bug in the of select_union_recursive::send_data prevented
the server from writing the row that caused the overflow
into the temporary table used for the result of the iteration
steps. This could lead, in particular,to a premature end
of the iterations.
2. The method TABLE::insert_all_rows_into() that was used
to copy all rows of one temporary table into another
did not take into account that the destination temporary
table must be converted to a MyISAM table at some point.
This patch fixed this problem. It also renamed the method
into TABLE::insert_all_rows_into_tmp_table() and added
an extra parameter needed for the conversion.
2017-01-04 14:33:24 -08:00
Igor Babaev
0b869814dc Made the result output deterministic. 2016-11-15 09:25:33 -08:00
Igor Babaev
8283d7f70e Added the test case from mdev-11259. 2016-11-13 14:56:30 -08:00
Igor Babaev
92bcb906a0 Fixed bug mdev-11278.
If a recursive CTE referred to a materialized view/derived table then
the query that used this CTE returned a bogus error message.
2016-11-13 14:56:29 -08:00
Igor Babaev
3b314ec633 Fixed bug mdev-10933.
The bug was caused by a misplaced construct opt_with_clause
for one of the variants of CREATE ... SELECT.
2016-09-30 17:40:43 -07:00
Igor Babaev
6aeaebd8cf Fixed the bug number in the comment of the test case for mdev-10899. 2016-09-30 17:40:40 -07:00
Igor Babaev
b91bd822fa Fixed bug mdev-10889
The bug was in the code of the recursive method
With_element::check_unrestricted_recursive. For recursive
calls of this method sel->get_with_element()->owner != owner.
2016-09-26 10:40:44 -07:00
Igor Babaev
54efb08022 Fixed bug mdev-10881
The server missed to call check_dependencies_in_with_clauses()
when processing PREPARE ... FROM CREATE ... SELECT / INSERT ... SELECT
with WITH clause before SELECT.
2016-09-24 21:05:36 -07:00
Igor Babaev
61ab7333db Fixed bug mdev-10883.
When a prepared statement uses a CTE definition with a column list
renaming of columns of the CTE expression  must be performed
for every execution of the prepared statement.
2016-09-24 21:05:36 -07:00
Igor Babaev
48b4e33596 Allowed to use WITH clauses before SELECT in CREATE ... SELECT
and INSERT ... SELECT.
Added test cases.
2016-09-22 01:45:05 -07:00
Igor Babaev
5c7d829346 Another attempt to fix bug mdev-10736. 2016-09-09 13:25:02 -07:00
Igor Babaev
d6f87e68f1 For some unclear reasons the test case for bug mdev-10736
does not work in non-debug modes.
2016-09-06 14:36:59 -07:00
Igor Babaev
2d36e5aa38 Fixed bug mdev-10736 that caused crashes.
The bug manifested itself for recursive definitions that
used anchors over tables with blobs.
2016-09-06 10:05:36 -07:00
Igor Babaev
8ae65920fa Fixed bug mdev-10737.
This bug in st_select_lex_node::move_node could result
in invalid select lists in recursive units that could
cause falling into infinite loops when iterating over
selects in such units.
2016-09-05 23:07:31 -07:00
Igor Babaev
501fc1a9e2 Returned the test case that was removed by mistake. 2016-08-29 22:58:01 -07:00
Igor Babaev
9ac235ab7d mdev-9864: cleanup, re-factoring.
Added comments.
Added reaction for exceeding maximum number of elements in with clause.
Added a test case to check this reaction.
Added a test case where the specification of a recursive table
uses two non-recursive with tables.
2016-08-29 22:45:17 -07:00
Igor Babaev
2f9555c40f Removed the parameter from st_select_lex_unit::exec_recursive.
Moved checking whether the limit set for the number of iterations
when executing a recursive query has been reached from
st_select_lex_unit::exec_recursive to TABLE_LIST::fill_recursive.
Changed the name of the system variable max_recursion_level for
max_recursive_iterations.
Adjusted test cases.
2016-08-10 15:51:40 -07:00
Sergei Petrunia
a2f245e49f MDEV-10372: EXPLAIN fixes for recursive CTEs, including FORMAT=JSON
- Tabular EXPLAIN now prints "RECURSIVE UNION".
- There is a basic implementation of EXPLAIN FORMAT=JSON.
- it produces "recursive_union" JSON struct
- No other details or ANALYZE support, yet.
2016-08-08 23:02:52 +03:00
Igor Babaev
f982d1074a Fixed the following problem:
Temporary tables created for recursive CTE
were instantiated at the prepare phase. As
a result these temporary tables missed
indexes for look-ups and optimizer could not
use them.
2016-07-26 22:58:33 -07:00
Igor Babaev
8c6a9aa30f Added a proper check for acceptable mutually recursive CTE. 2016-06-30 15:13:12 -07:00
Igor Babaev
0a6e6d705b Fixed numerous problems for mutually recursive CTE.
Actually mutually recursive CTE were not functional. Now the code
for mutually recursive CTE looks like functional, but still needs
re-writing.
Added many new test cases for mutually recursive CTE.
2016-06-06 10:01:16 -07:00
Galina Shalygina
b4f1f42062 Fixed the problem of wrong identification of WITH tables defined in WITH clauses without RECURSIVE.
Added test cases to check the fix.
Fixed the problem of wrong types of recursive tables when the type of anchor part does not coincide with the
type of recursive part.
Prevented usage of marerialization and subquery cache for subqueries with recursive references.
Introduced system variables 'max_recursion_level'.
Added a test case to test usage of this variable.
2016-05-24 21:29:52 +03:00