summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch '10.3' into 10.4Oleksandr Byelkin2021-07-311-3/+32
|\
| * MDEV-24511 null field is created with CREATE..SELECTSergei Golubchik2021-07-291-1/+2
| | | | | | | | | | When creating fields for UNION results, Field_null is not allowed. Should create binary(0) instead.
| * MDEV-9234 Add Type_handler::union_element_finalize()Alexander Barkov2021-07-291-5/+5
| |
| * Merge branch '10.2' into 10.3Sergei Golubchik2021-07-211-2/+30
| |\
| | * MDEV-25565 Crash on 2-nd execution of SP/PS for query calculating window ↵Igor Babaev2021-07-201-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functions from view A crash of the server happened when executing a stored procedure whose the only query calculated window functions over a mergeable view specified as a select from non-mergeable view. The crash could be reproduced if the window specifications of the window functions were identical and both contained PARTITION lists and ORDER BY lists. A crash also happened on the second execution of the prepared statement created for such query. If to use derived tables or CTE instead of views the problem still manifests itself crashing the server. When optimizing the window specifications of a window function the server can substitute the partition lists and the order lists for the corresponding lists from another window specification in the case when the lists are identical. This substitution is not permanent and should be rolled back before the second execution. It was not done and this ultimately led to a crash when resolving the column names at the second execution of SP/PS.
| | * MDEV-26135 Assertion failure when executing PS with a hanging recursive CTEIgor Babaev2021-07-191-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug affected execution of queries with With clauses containing so-called hanging recursive CTEs in PREPARE mode. A CTE is hanging if it's not used in the query. Preparation of a prepared statement from a query with a hanging CTE caused a leak in the server and execution of this prepared statement led to an assert failure of the server built in the debug mode. This happened because the units specifying recursive CTEs erroneously were not cleaned up if those CTEs were hanging. The patch enforces cleanup of hanging recursive CTEs in the same way as other hanging CTEs. Approved by dmitry.shulga@mariadb.com
* | | Merge branch '10.3' into 10.4bb-10.4-MDEV-23468Oleksandr Byelkin2020-12-251-26/+42
|\ \ \ | |/ /
| * | Merge branch '10.2' into 10.3Oleksandr Byelkin2020-12-231-26/+42
| |\ \ | | |/
| | * MDEV-23406 Signal 8 in maria_create after recursive cte queryIgor Babaev2020-12-161-26/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug could cause a crash when executing queries that used mutually recursive CTEs with system variable big_tables set to 1. It happened due to several bugs in the code that handled recursive table references referred mutually recursive CTEs. For each recursive table reference a temporary table is created that contains all rows generated for the corresponding recursive CTE table on the previous step of recursion. This temporary table should be created in the same way as the temporary table created for a regular materialized derived table using the method select_union::create_result_table(). In this case when the temporary table is created it uses the select_union::TMP_TABLE_PARAM structure as the parameter for the table construction. However the code created the temporary table using just the function create_tmp_table() and passed pointers to certain fields of the TMP_TABLE_PARAM structure used for accumulation of rows of the recursive CTE table as parameters for update. This was a mistake because now different temporary tables cannot share some TMP_TABLE_PARAM fields in a general case. Besides, depending on how mutually recursive CTE tables were defined and which of them were referred in the executed query the select_union object allocated for a recursive table reference could be allocated again after the the temporary table had been created. In this case the TMP_TABLE_PARAM object associated with the temporary table created for the recursive table reference contained unassigned fields needed for execution when Aria engine is employed as the engine for temporary tables. This patch ensures that - select_union object is created only once for any recursive table reference - any temporary table created for recursive CTEs uses its own TMP_TABLE_PARAM structure The patch also fixes a problem caused by incomplete cleanup of join tables associated with recursive table references. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | Merge 10.3 into 10.4Marko Mäkelä2020-12-011-0/+1
|\ \ \ | |/ /
| * | Merge 10.2 into 10.3Marko Mäkelä2020-12-011-0/+1
| |\ \ | | |/
| | * MDEV-24220 Server crash in base_list_iterator::next orIgor Babaev2020-11-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in TABLE_LIST::is_recursive_with_tables After the patch for MDEV-23619 the code of st_select_lex::cleanup started using the list st_select_lex::leaf_tables. This list is built for any query with FROM clause in the function setup_tables(). If such query is used in a stored procedure it must be ensured that the list is empty before each new call of the procedure. Otherwise if the first call of the procedure is successful while the second call reports an error before the setup_tables() is invoked then list st_select_lex::leaf_tables would point to a piece of memory that has been already freed. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | MDEV-23619: Merge 10.3 into 10.4Marko Mäkelä2020-11-131-20/+22
|\ \ \ | |/ /
| * | MDEV-23619: Merge 10.2 into 10.3Marko Mäkelä2020-11-131-20/+22
| |\ \ | | |/
| | * MDEV-23619 MariaDB crash on WITH RECURSIVE UNION ALL (CTE) queryIgor Babaev2020-11-131-20/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to a premature cleanup of the unit that specified a recursive CTE used in the second operand of union the server fell into an infinite loop in the reported test case. In other cases this premature cleanup could cause other problems. The bug is the result of a not quite correct fix for MDEV-17024. The unit that specifies a recursive CTE has to be cleaned only after the cleanup of the last external reference to this CTE. It means that cleanups of the unit triggered not by the cleanup of a external reference to the CTE must be blocked. Usage of local table chains in selects to get external references to recursive CTEs was not correct either because of possible merges of some selects. Also fixed a minor bug in st_select_lex::set_explain_type() that caused typing 'RECURSIVE UNION' instead of 'UNION' in EXPLAIN output for external references to a recursive CTE.
* | | MDEV-23094: Multiple calls to a Stored Procedure from another Stored ↵bb-10.4-MDEV-23094Oleksandr Byelkin2020-08-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Procedure crashes server Added system-SELECT to IF/WHILE/REPET/FOR for correct subqueries connecting. Added control of system/usual selects for correct error detection.
* | | Merge 10.3 into 10.4Marko Mäkelä2020-08-101-1/+21
|\ \ \ | |/ /
| * | Merge 10.2 into 10.3Marko Mäkelä2020-08-101-1/+21
| |\ \ | | |/
| | * Merge 10.1 into 10.2Marko Mäkelä2020-08-101-0/+19
| | |\
| | | * MDEV-9513: Assertion `join->group_list || !join->is_in_subquery()' failed in ↵Varun Gupta2020-08-061-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | create_sort_index Removing the ORDER BY clause from the UNION when UNION is inside an IN/ALL/ANY/EXISTS subquery. The rewrites are done for subqueries but this rewrite is not done for the fake_select of the UNION.
* | | | Merge 10.3 into 10.4Marko Mäkelä2020-06-081-0/+13
|\ \ \ \ | |/ / /
| * | | Merge 10.2 into 10.3Marko Mäkelä2020-06-081-0/+13
| |\ \ \ | | |/ /
| | * | MDEV-22748 MariaDB crash on WITH RECURSIVE large queryIgor Babaev2020-06-061-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug is the same as the bug MDEV-17024. The crashes caused by these bugs were due to premature cleanups of the unit specifying recursive CTEs that happened in some cases when there were several outer references the same recursive CTE. The problem of premature cleanups for recursive CTEs could be already resolved by the correction in TABLE_LIST::set_as_with_table() introduced in this patch. ALL other changes introduced by the patches for MDEV-17024 and MDEV-22748 guarantee that this clean-ups are performed as soon as possible: when the select containing the last outer reference to a recursive CTE is being cleaned up the specification of the recursive CTE should be cleaned up as well.
| * | | MDEV-18727 improve DML operation of System VersioningAleksey Midenkov2019-11-221-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables UPDATE, DELETE: replace linear search of current/historical records with vers_setup_conds(). Additional DML cases in view.test
* | | | MDEV-18727 improve DML operation of System Versioning (10.4)Aleksey Midenkov2019-11-251-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | UPDATE, DELETE: replace linear search of current/historical records with vers_setup_conds(). Additional DML cases in view.test
* | | | MDEV-19956 Queries with subqueries containing UNION are not parsedIgor Babaev2019-09-231-12/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Shift-Reduce conflicts prevented parsing some queries with subqueries that used set operations when the subqueries occurred in expressions or in IN predicands. The grammar rules for query expression were transformed in order to avoid these conflicts. New grammar rules employ an idea taken from MySQL 8.0.
* | | | Merge 10.3 into 10.4Marko Mäkelä2019-09-231-0/+1
|\ \ \ \ | |/ / / | | | | | | | | Disable MDEV-20576 assertions until MDEV-20595 has been fixed.
| * | | MDEV-20229 CTE defined with table value constructor cannot be used in viewsIgor Babaev2019-09-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A CTE can be defined as a table values constructor. In this case the CTE is always materialized in a temporary table. If the definition of the CTE contains a list of the names of the CTE columns then the query expression that uses this CTE can refer to the CTE columns by these names. Otherwise the names of the columns are taken from the names of the columns in the result set of the query that specifies the CTE. Thus if the column names of a CTE are provided in the definition the columns of result set should be renamed. In a general case renaming of the columns is done in the select lists of the query specifying the CTE. If a CTE is specified by a table value constructor then there are no such select lists and renaming is actually done for the columns of the result of materialization. Now if a view is specified by a query expression that uses a CTE specified by a table value constructor saving the column names of the CTE in the stored view definition becomes critical: without these names the query expression is not able to refer to the columns of the CTE. This patch saves the given column names of CTEs in stored view definitions that use them.
* | | | Merge branch '10.3' into 10.4Oleksandr Byelkin2019-05-191-4/+38
|\ \ \ \ | |/ / /
| * | | Merge 10.2 into 10.3Marko Mäkelä2019-05-141-1/+1
| |\ \ \ | | |/ /
| | * | Merge 10.1 into 10.2Marko Mäkelä2019-05-131-1/+1
| | |\ \ | | | |/
| | | * Merge branch '5.5' into 10.1Vicențiu Ciorbaru2019-05-111-1/+1
| | | |\
| | | | * Update FSF AddressVicențiu Ciorbaru2019-05-111-1/+1
| | | | | | | | | | | | | | | | | | | | * Update wrong zip-code
| * | | | MDEV-17894 Assertion `(thd->lex)->current_select' failed in MYSQLparse(),Igor Babaev2019-05-081-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | query with VALUES() A table value constructor can be used in all contexts where a select can be used. In particular an ORDER BY clause or a LIMIT clause or both of them can be attached to a table value constructor to produce a new query. Unfortunately execution of such queries was not supported. This patch fixes the problem.
* | | | | Merge 10.3 into 10.4Marko Mäkelä2019-05-051-0/+40
|\ \ \ \ \ | |/ / / /
| * | | | MDEV-9959: A serious MariaDB server performance bugVarun Gupta2019-04-301-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | If a derived table has SELECT DISTINCT, provide index statistics for it so that the join optimizer in the upper select knows that ref access to the table will produce one row.
* | | | | MDEV-9234 Add Type_handler::union_element_finalize()10.4-stagingAlexander Barkov2019-04-231-5/+5
| | | | |
* | | | | Merge 10.3 into 10.4Marko Mäkelä2019-03-201-9/+18
|\ \ \ \ \ | |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The MDEV-17262 commit 26432e49d37a37d09b862bb49a021e44bdf4789c was skipped. In Galera 4, the implementation would seem to require changes to the streaming replication. In the tests archive.rnd_pos main.profiling, disable_ps_protocol for SHOW STATUS and SHOW PROFILE commands until MDEV-18974 has been fixed.
| * | | | Merge branch '10.2' into 10.3Sergei Golubchik2019-03-171-9/+18
| |\ \ \ \ | | |/ / /
| | * | | Merge branch '10.1' into 10.2Sergei Golubchik2019-03-151-9/+18
| | |\ \ \ | | | |/ /
| | | * | Fix of prepared CREATE VIEW with global ORDER/GROUPOleksandr Byelkin2019-03-121-10/+21
| | | | |
* | | | | Merge 10.3 into 10.4Marko Mäkelä2019-03-061-2/+3
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.2 into 10.3Marko Mäkelä2019-03-051-2/+3
| |\ \ \ \ | | |/ / / | | | | | | | | | | | | | | | | | | | | FIXME: Properly resolve conflicts between MDEV-18883 and MDEV-7742/MDEV-8305, and record the correct result for main.log_slow
| | * | | Merge 10.1 into 10.2Marko Mäkelä2019-03-041-2/+3
| | |\ \ \ | | | |/ /
| | | * | Merge branch '10.0' into 10.1Oleksandr Byelkin2019-03-011-2/+3
| | | |\ \
| | | | * \ Merge branch '5.5' into 10.0Oleksandr Byelkin2019-02-281-2/+3
| | | | |\ \ | | | | | |/
| | | | | * MDEV-17055: Server crashes in find_order_in_list upon 2nd (3rd) execution of ↵Oleksandr Byelkin2019-02-281-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SP with UPDATE 1. Always drop merged_for_insert flag on cleanup (there could be errors which prevent TABLE to be assigned) 2. Make more precise cleanup of select parts which was touched
* | | | | | Merge 10.3 into 10.4Marko Mäkelä2018-12-041-2/+5
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge 10.2 into 10.3Marko Mäkelä2018-12-041-2/+5
| |\ \ \ \ \ | | |/ / / /
| | * | | | MDEV-17871 Crash when running explain with CTEIgor Babaev2018-12-011-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the with clause of a query contains a recursive CTE that is not used then processing of EXPLAIN for this query does not require optimization of the unit specifying this CTE. In this case if 'derived' is the TABLE_LIST object created for this CTE then derived->derived_result is NULL and any assignment to derived->derived_result->table causes a crash. After fixing this problem in the code of st_select_lex_unit::prepare() EXPLAIN for such a query worked without crashes. Yet an execution plan for the recursive CTE appeared there. The cause of this problem was an incorrect condition used in JOIN::save_explain_data_intern() that determined whether CTE was to be optimized or not. A similar condition was used in select_describe() and this patch has corrected it as well.