summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* 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 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.
* 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.
* | 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.
* | 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
* | | 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.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
* | | | 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.
* | | | MDEV-17201 dropped anchor rows with non-null recursion queryIgor Babaev2018-09-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The function st_select_lex_unit::exec_recursive() missed resetting of select_limit_cnt and offset_limit_cnt before execution of union parts. As a result recursive CTEs specified by UNIONs whose SELECTs contained LIMIT/OFFSET could return wrong sets of records.
* | | | MDEV-17024 Crash on large queryIgor Babaev2018-09-071-1/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This problem manifested itself when a join query used two or more materialized CTE such that each of them employed the same recursive CTE. The bug caused a crash. The crash happened because the cleanup() function was performed premature for recursive CTE. This clean up was induced by the cleanup of the first CTE referenced the recusrsive CTE. This cleanup destroyed the structures that would allow to read from the temporary table containing the rows of the recursive CTE and an attempt to read these rows for the second CTE referencing the recursive CTE triggered a crash. The clean up for a recursive CTE R should be performed after the cleanup of the last materialized CTE that uses R.
* | | | Add PART_INDIRECT_KEY_FLAGMonty2018-06-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to mark that a field is indirectly part of a key, which simplifes checking if we need to have this field up to date to evaluate a key. For example: CREATE TABLE t1 (a int, b int as (a) virtual, c int as (b) virtual, index(c)) would mark a and b with PART_INDIRECT_KEY_FLAG. c is marked with PART_KEY_FLAG as before.
* | | | MDEV-16353 Server crash on query with CTEIgor Babaev2018-05-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug caused crashes for queries with unreferenced non-recursive CTEs specified by unions.It happened because the function st_select_lex_unit::prepare() tried to use the value of the field 'derived' that could not be set for unferenced CTEs as there was no derived table associated with an unreferenced CTE.
* | | | MDEV-15581 Incorrect result (missing row) with UNION DISTINCT in anchor partsIgor Babaev2018-05-171-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | 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-16212 Memory leak with recursive CTE that uses global ORDER BYIgor Babaev2018-05-171-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with recursive subquery There were two problems: 1. The code did not report that usage of global ORDER BY / LIMIT clauses was not supported yet. 2. The code just reset fake_select_lex of the the unit specifying a recursive CTE to NULL and that caused memory leaks in some cases.
* | | | MDEV-14695: Assertion `n < m_size' failed in ↵Varun Gupta2018-05-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bounds_checked_array<Element_type>::operator In this issue we hit the assert because we are adding addition fields to the field JOIN::all_fields list. This is done because HEAP tables can't index BIT fields so we need to use an additional hidden field for grouping because later it will be converted to a LONG field. Original field will remain of the BIT type and will be returned. This happens when we convert DISTINCT to GROUP BY. The solution is to take into account the number of such hidden fields that would be added to the field JOIN::all_fields list while calculating the size of the ref_pointer_array.
* | | | MDEV-15575 different results when using CTE and big_tables=1.Igor Babaev2018-04-161-13/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug happened due to a defect of the implementation of the handler function ha_delete_all_rows() for the ARIA engine. The function maria_delete_all_rows() truncated the table, but it didn't touch the write cache, so the cache's write offset was not reset. In the scenario like in the function st_select_lex_unit::exec_recursive when first all records were deleted from the table and then several new records were added some metadata became inconsistent with the state of the cache. As a result the table scan function could not read records at the end of the table. The same defect could be found in the implementation of ha_delete_all_rows() for the MYISAM engine mi_delete_all_rows(). Additionally made late instantiation for the temporary table used to store rows that were used for each new iteration when executing a recursive CTE.
* | | | MDEV-15478: Lost name of a explicitly named CTE column used inGalina Shalygina2018-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the non-recursive CTE defined with UNION The problem appears as the columns of the non-recursive CTE weren't renamed. The renaming procedure was called for recursive CTEs only. To fix it in the procedure st_select_lex_unit::prepare With_element::rename_columns_of_derived_unit is called now for both CTEs: recursive and non-recursive.
* | | | Merge branch 'github/10.1' into 10.2Sergei Golubchik2018-02-061-16/+0
|\ \ \ \ | |/ / /
| * | | Merge branch 'github/10.0' into 10.1Sergei Golubchik2018-02-021-16/+0
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch '5.5' into 10.0Vicențiu Ciorbaru2018-01-241-16/+0
| | |\ \ | | | |/
| | | * Correct TRASH() macro usageSergei Golubchik2018-01-221-16/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TRASH was mapped to TRASH_FREE and was supposed to be used for memory that should not be accessed anymore, while TRASH_ALLOC() is to be used for uninitialized but to-be-used memory. But sometimes TRASH() was used in the latter sense. Remove TRASH() macro, always use explicit TRASH_ALLOC() or TRASH_FREE().
* | | | Fixed mdev-14879 Lost rows for query using recursive CTEIgor Babaev2018-01-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Merge branch '10.1' into 10.2Sergei Golubchik2017-08-171-3/+15
|\ \ \ \ | |/ / /
| * | | Merge branch '10.0' into 10.1Sergei Golubchik2017-08-081-3/+15
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch 'origin/5.5' into 10.0Vicențiu Ciorbaru2017-07-251-3/+15
| | |\ \ | | | |/
| | | * Merge remote-tracking branch 'mysql/5.5' into 5.5Sergei Golubchik2017-07-181-3/+15
| | | |\
| | | | * Bug #24595639: INCORRECT BEHAVIOR IN QUERY WITH UNION ANDSreeharsha Ramanavarapu2017-05-241-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GROUP BY Issue 1: -------- This problem occurs in the following conditions: 1) A UNION is present in the subquery of select list and handles multiple columns. 2) Query has a GROUP BY. A temporary table is created to handle the UNION. Item_field objects are based on the expressions of the result of the UNION (ie. the fake_select_lex). While checking validity of the columns in the GROUP BY list, the columns of the temporary table are checked in Item_ident::local_column. But the Item_field objects created for the temporary table don't have information like the Name_resolution_context that they belong to or whether they are dependent on an outer query. Since these members are null, incorrect behavior is caused. This can happen when such Item objects are cached to apply the IN-to-EXISTS transform for Item_row. Solution to Issue 1: -------------------- Context information of the first select in the UNION will be assigned to the new Item_field objects. Issue 2: -------- This problem occurs in the following conditions: 1) A UNION is present in the subquery of select list. 2) A column in the UNION's first SELECT refers to a table in the outer-query making it a dependent union. 3) GROUP BY column refers to the outer-referencing column. While resolving the select list with an outer-reference, an Item_outer_ref object is created to handle the outer-query's GROUP BY list. The Item_outer_ref object replaces the Item_field object in the item tree. Item_outer_ref::fix_fields will be called only while fixing the inner references of the outer query. Before resolving the outer-query, an Item_type_holder object needs to be created to handle the UNION. But as explained above, the Item_outer_ref object has not been fixed yet. Having a fixed Item object is a pre-condition for creating an Item_type_holder. Solution to Issue 2: -------------------- Use the reference (real_item()) of an Item_outer_ref object instead of the object itself while creating an Item_type_holder.
| | | | * Bug #17059925: UNIONS COMPUTES ROWS_EXAMINED INCORRECTLYmithun2014-05-081-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ISSUE: ------ For UNION of selects, rows examined by the query will be sum of rows examined by individual select operations and rows examined for union operation. The value of session level global counter that is used to count the rows examined by a select statement should be accumulated and reset before it is used for next select statement. But we have missed to reset the same. Because of this examined row count of a select query is accounted more than once. SOLUTION: --------- In union reset the session level global counter used to accumulate count of examined rows after its value is saved.
| | | | * Bug #18167356: EXPLAIN W/ EXISTS(SELECT* UNION SELECT*)mithun2014-04-281-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | WHERE ONE OF SELECT* IS DISTINCT FAILS. ISSUE: ------ There are 2 issues related to explain union. 1. If we have subquery with union of selects. And, one of the select need temp table to materialize its results then it will replace its query structure with a simple select from temporary table. Trying to display new internal temporary table scan resulted in crash. But to display the query plan, we should save the original query structure. 2. Multiple execution of prepared explain statement which have union of subqueries resulted in crash. If we have constant subqueries, fake select used in union operation will be evaluated once before using it for explain. During first execution we have set fake select options to SELECT_DESCRIBE, but did not reset after the explain. Hence during next execution of prepared statement during first time evaluation of fake select we had our select options as SELECT_DESCRIBE this resulted in improperly initialized data structures and crash. SOLUTION: --------- 1. If called by explain now we save the original query structure. And this will be used for displaying. 2. Reset the fake select options after it is called for explain of union.
| | | | * merge 5.1-security => 5.5-securityTor Didriksen2011-07-111-8/+30
| | | | |\
| | | | | * Bug#11765255 - 58201: VALGRIND/CRASH WHEN ORDERING BY MULTIPLE AGGREGATE ↵Tor Didriksen2011-07-111-9/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | FUNCTIONS We must allocate a larger ref_pointer_array. We failed to account for extra items allocated here: #0 find_order_in_list uint el= all_fields.elements; all_fields.push_front(order_item); /* Add new field to field list. */ ref_pointer_array[el]= order_item; order->item= ref_pointer_array + el; #1 setup_order #2 setup_without_group #3 JOIN::prepare
| | | | * | Updated/added copyright headersKent Boortz2011-06-301-2/+2
| | | | |\ \ | | | | | |/
| | | | | * Updated/added copyright headersKent Boortz2011-06-301-2/+4
| | | | | |\
| | | | | | * Updated/added copyright headersKent Boortz2011-06-301-2/+3
| | | | | | |
| | | | * | | Bug#57704 Cleanup code dies with void TABLE::set_keyread(bool): Assertion ↵Oystein Grovlen2010-11-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `file' failed. This bug was introduced in this revision: kostja@sun.com-20100727102553-b4n2ojcyfj79l2x7 ("A pre-requisite patch for the fix for Bug#52044.") It happens because close_thread_tables() is now called in open_and_lock_tables upon failure. Hence, table is no longer open when optimizer tries to do cleanup. Fix: Make sure to do cleanup in st_select_lex_unit::prepare() upon failure. This way, cleanup() is called before tables are released.
| | | | * | | Merge of mysql-5.1-bugteam into mysql-5.5-bugteam.Davi Arnaut2010-10-201-9/+0
| | | | |\ \ \ | | | | | |/ /
| | | | | * | Bug#45288: pb2 returns a lot of compilation warningsDavi Arnaut2010-10-201-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix assorted warnings that are generated in optimized builds. Most of it is silencing variables that are set but unused. This patch also introduces the MY_ASSERT_UNREACHABLE macro which helps the compiler to deduce that a certain piece of code is unreachable.
| | | | * | | Implement WL#5502 Remove dead 5.0 class Sensitive_cursor.Konstantin Osipov2010-07-271-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove dead and unused code. Update to reflect the code review requests.
| | | | * | | Merge of mysql-5.1-bugteam into mysql-trunk-merge.Davi Arnaut2010-06-101-20/+18
| | | | |\ \ \ | | | | | |/ /
| | | | | * | Bug#42733: Type-punning warnings when compiling MySQL --Davi Arnaut2010-06-101-20/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | strict aliasing violations. One somewhat major source of strict-aliasing violations and related warnings is the SQL_LIST structure. For example, consider its member function `link_in_list` which takes a pointer to pointer of type T (any type) as a pointer to pointer to unsigned char. Dereferencing this pointer, which is done to reset the next field, violates strict-aliasing rules and might cause problems for surrounding code that uses the next field of the object being added to the list. The solution is to use templates to parametrize the SQL_LIST structure in order to deference the pointers with compatible types. As a side bonus, it becomes possible to remove quite a few casts related to acessing data members of SQL_LIST.
| | | | * | | WL#5030: Split and remove mysql_priv.hMats Kindahl2010-03-311-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch: - Moves all definitions from the mysql_priv.h file into header files for the component where the variable is defined - Creates header files if the component lacks one - Eliminates all include directives from mysql_priv.h - Eliminates all circular include cycles - Rename time.cc to sql_time.cc - Rename mysql_priv.h to sql_priv.h
| | | | * | | Manual merge from mysql-trunk-merge.Alexander Nozdrin2010-01-191-1/+30
| | | | |\ \ \ | | | | | |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: - configure.in - include/m_string.h - mysql-test/extra/rpl_tests/rpl_row_func003.test - mysql-test/r/mysqlbinlog.result - mysql-test/r/union.result - mysql-test/suite/binlog/r/binlog_killed_simulate.result - mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result - mysql-test/suite/binlog/r/binlog_unsafe.result - mysql-test/suite/binlog/t/binlog_unsafe.test - mysql-test/suite/rpl/r/rpl_loaddata_fatal.result - mysql-test/suite/rpl/r/rpl_loaddata_map.result - mysql-test/suite/rpl/r/rpl_stm_loaddata_concurrent.result - mysql-test/suite/rpl/r/rpl_stm_log.result - mysql-test/suite/rpl/t/rpl_optimize.test - mysql-test/t/mysqlbinlog.test - mysql-test/t/union.test - sql/rpl_utility.h - sql/sql_union.cc - strings/Makefile.am