summaryrefslogtreecommitdiff
path: root/sql/sql_cte.cc
Commit message (Collapse)AuthorAgeFilesLines
* MDEV-17635 Server hangs after the query with recursive CTEIgor Babaev2018-11-071-1/+1
| | | | | | | | This bug in the code of the function With_element::check_unrestricted_recursive() could force a recursive CTE to be executed in a non-standard compliant mode in which recursive UNION ALL could lead to an infinite execution. This problem could occur only in the case when this CTE was used by another recursive CTE at least twice.
* MDEV-17154 Multiple selects from parametrized CTE fails with syntax errorIgor Babaev2018-09-141-6/+31
| | | | | | | | | | | | | | | | | | | | | | | This patch fills a serious flaw in the implementation of common table expressions. Before this patch an attempt to prepare a statement from a query with a parameter marker in a CTE that was used more than once in the query ended up with a bogus error message. Similarly if a statement in a stored procedure contained a CTE whose specification used a local variables and this CTE was referred to more than once in the statement then the server failed to execute the stored procedure returning a bogus error message on a non-existing field. The problems appeared due to incorrect handling of parameter markers / local variables in CTEs that were referred more than once. This patch fixes the problems by differentiating between the original occurrences of a parameter marker / local variable used in the specification of a CTE and the corresponding occurrences used in copies of this specification. These copies are substituted instead of non-first references to the CTE. The idea of the fix and even some code were taken from the MySQL implementation of the common table expressions.
* Merge branch '10.1' into 10.2Sergei Golubchik2018-05-201-1/+2
|
* MDEV-15581 Incorrect result (missing row) with UNION DISTINCT in anchor partsIgor Babaev2018-05-171-4/+8
| | | | | | The current code does not support recursive CTEs whose specifications contain a mix of ALL UNION and DISTINCT UNION operations. This patch catches such specifications and reports errors for them.
* MDEV-15894 Error, while using aggregated functions/window functions in ↵Igor Babaev2018-04-171-1/+1
| | | | | | | anchor part Usage of aggregate/window functions in non-recursive parts of recursive CTEs is allowed. Error messages complaining about this were reported by mistake.
* MDEV-15556 MariaDB crash with big_tables=1 and CTEIgor Babaev2018-04-161-1/+1
| | | | | | | | This bug manifested itself when the optimizer chose an execution plan with an access of the recursive CTE in a recursive query by key and ARIA/MYISAM temporary tables were used to store recursive tables. The problem appeared due to passing an incorrect parameter to the call of instantiate_tmp_table() in the function With_element::instantiate_tmp_tables().
* MDEV-14297: Lost name of a explicitly named CTE column used inGalina Shalygina2018-02-201-0/+7
| | | | | | | | | | | the non-recursive CTE via prepared statement The problem appears as the column names of the CTE were allocated on the wrong MEMROOT and after the preparation of the statement they disappear. To fix it in the procedure With_element::rename_columns_of_derived_unit the CTE column names are now allocated in the permanent MEMROOT for the prepared statements and stored procedures.
* Corrected the patch for mdev-15119 that caused a failure forIgor Babaev2018-02-081-9/+5
| | | | | | | cte_nonrecursive.test with --embedded. This also fixed some problems for embedded CTEs. Adjusted test results accordingly.
* Fixed mdev-15119 CTE, referencing another CTE, that is declared after,Igor Babaev2018-02-061-11/+15
| | | | | | | does not return error Corrected the code of st_select_lex::find_table_def_in_with_clauses() for a proper identification of CTE references used in embedded CTEs.
* Fixed mdev-15120 CTE table should not belong to database, that is in useIgor Babaev2018-02-061-1/+2
| | | | | | When identifying a table name the following should be taken into account: a CTE name cannot be qualified with a database name, otherwise the table name is considered as the name of a non-CTE table.
* Merge branch 'github/10.1' into 10.2Sergei Golubchik2018-02-061-1/+1
|
* Fixed mdev-14852 Fails to reopen temp table within standard CTEIgor Babaev2018-01-051-0/+7
| | | | | | | | | | | | If the specification of a CTE contains a reference to a temporary table then THD::open_temporary_table() must be called for this reference for any occurrence of the CTE in the query. By mistake this was done only for the first occurrences of CTEs. The patch fixes this problem in With_element::clone_parsed_spec(). It also moves there the call of check_dependencies_in_with_clauses() to its proper place before the call of check_table_access(). Additionally the patch optimizes the number of calls of the function check_dependencies_in_with_clauses().
* Fixed compiler warnings about possible uninitialized variablesMonty2018-01-011-1/+1
|
* Fixed bug mdev-13453 Executing a query via CTE requires more permissionsIgor Babaev2017-11-141-1/+2
| | | | | | | than the query itself ACL checks were not properly supported for tables used in CTE specifications. This patch fixes the problem.
* Fixed bugs: mdev-13780 CTE not found, mdev-14184 recursive CTE not foundIgor Babaev2017-11-051-7/+15
| | | | | | | 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.
* Fixed the bug mdev-13796.Igor Babaev2017-10-111-1/+9
| | | | | | | | | | A reference to a CTE may occur not in the master of the CTE specification. In this case if the reference to the CTE is the first one the specification should be detached from its master and attached to the referencing select. Also fixed the TYPE column in the lines of the EXPLAIN output created for CTE tables.
* Fixed the bug mdev-12563.Igor Babaev2017-04-281-1/+59
| | | | | | | | | | | | | 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.
* Fixed the bug mdev-12558.Igor Babaev2017-04-251-0/+11
| | | | | | | | | | | | | | | | | | | | | | In the current code temporary tables we identified and opened before other tables. CTE tables are identified in the same procedure as regular tables. When a temporary table and a CTE table have the same name T any reference to T that is in the scope of the CTE declaration must be associated with this CTE. Yet it was not done properly. When a reference to T was found in the scope of the declaration of CTE T a pointer to this CTE was set in the reference. No check that the reference had been already associated with a temporary table was done. As a result, if the temporary table T had been created then the reference to T was considered simultaneously as reference to the CTE named T and as a reference to the temporary table named T. This confused the code that were executed later and caused a crash of the server. Now when a table reference is associated with a CTE any previous association with a temporary table is dropped. This problem could be easily avoided if the temporary tables were not identified prematurely. as reference to CTE named T and
* Fixed the bug mdev-12519.Igor Babaev2017-04-211-0/+1
| | | | | | | | | | | | | | | | | | | | 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.
* Fixed the bug mdev-12440.Igor Babaev2017-04-061-0/+1
| | | | | | | | | When a CTE referring to another CTE from the same with clause was used twice then the server could not find the second CTE and reported a bogus error message. This happened because for any unit that was created as a clone of a CTE specification the pointer to the WITH clause that owned this CTE was not set.
* Fixed bug mdev-12360.Igor Babaev2017-03-261-0/+2
| | | | | | | 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.
* Fixed bug mdev-12185.Igor Babaev2017-03-071-1/+1
| | | | | | | The bug was caused by a wrong order of statements in With_clause::print(). As a result any view definition containing WITH clause with several CTE specifications was put the frm file in a syntactically incorrect form.
* MDEV-7635: Renamed standards_compliant_cte to standard_compliant_cteNirbhay Choubey2017-02-101-3/+3
|
* Fixed bug mdev-11818.Igor Babaev2017-01-181-0/+6
| | | | | | | When a query containing a WITH clause is printed by EXPLAIN EXTENDED command there should not be any data expansion in the query specifications of the WITH elements of this WITH clause.
* Fixed bug mdev-11278.Igor Babaev2016-11-131-11/+0
| | | | | If a recursive CTE referred to a materialized view/derived table then the query that used this CTE returned a bogus error message.
* Fixed bug mdev-10923.Igor Babaev2016-09-301-4/+9
| | | | | | | The code for st_select_lex::find_table_def_in_with_clauses() did not take into account the fact that the specs for mergeable CTEs were cloned and were not processed by the function With_element::check_dependencies_in_spec().
* Fixed bug mdev-10889Igor Babaev2016-09-261-2/+2
| | | | | | 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.
* Fixed bug mdev-10736 that caused crashes.Igor Babaev2016-09-061-0/+3
| | | | | The bug manifested itself for recursive definitions that used anchors over tables with blobs.
* mdev-9864: cleanup, re-factoring.Igor Babaev2016-08-291-0/+32
| | | | | | | | 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.
* mdev-9864: cleanup, re-factoring.Igor Babaev2016-08-261-137/+436
| | | | Added comments.
* Fixed the following problem:Igor Babaev2016-07-261-0/+18
| | | | | | | | 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.
* Added a proper check for acceptable mutually recursive CTE.Igor Babaev2016-06-301-33/+40
|
* Simplified the code that fills recursive tables.Igor Babaev2016-06-251-13/+23
|
* Fixed the problem of wrong identification of WITH tables defined in WITH ↵Galina Shalygina2016-05-241-62/+110
| | | | | | | | | | | 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.
* Fixed many problems in the code of With_element::check_unrestricted_recursive().Galina Shalygina2016-05-191-19/+34
| | | | | | | Added the check whether there are set functions in the specifications of recursive CTE. Added the check whether there are recursive references in subqueries. Introduced boolean system variable 'standards_compliant_cte'. By default it's set to 'on'. When it's set to 'off' non-standard compliant CTE can be executed.
* Fixed a bug that caused crashes for SHOW CREATE VIEW <view> when <view> was ↵Galina Shalygina2016-05-141-2/+6
| | | | recursive. Added a test case to check the fix.
* Made prepared statement, explain and views working with recursuve CTE.Galina Shalygina2016-05-121-4/+16
|
* Main patch for mdev-9864Galina Shalygina2016-05-091-23/+281
|
* Merge branch '10.2' into 10.2-mdev9864Galina Shalygina2016-05-081-1/+4
|
* Addressed the issues raised in the review for the main patchbb-10.2-mdev8789Igor Babaev2016-02-171-15/+19
| | | | | | | | of mdev-8789. Fixed a bug in TABLE_LIST::print. Fixed another bug for the case when the definition of a WITH table contained column list while the join in the main query used two instances of this table.
* Fixed compile errors of the merge of the patch for mdev-8789 with 10.2.Igor Babaev2015-12-211-6/+8
|
* MDEV-8789 Implement non-recursive common table expressionsGalina Shalygina2015-12-181-0/+595
Initial implementation