summaryrefslogtreecommitdiff
path: root/sql/sql_derived.cc
Commit message (Collapse)AuthorAgeFilesLines
* MDEV-25362 Incorrect name resolution for subqueries in ON expressionsprot-10.2Igor Babaev2021-04-171-0/+31
| | | | | | | | | | | | | | | | | | This patch sets the proper name resolution context for outer references used in a subquery from an ON clause. Usually this context is more narrow than the name resolution context of the parent select that were used before this fix. This fix revealed another problem that concerned ON expressions used in from clauses of specifications of derived tables / views / CTEs. The name resolution outer context for such ON expression must be set to NULL to prevent name resolution beyond the derived table where it is used. The solution to resolve this problem applied in sql_derived.cc was provided by Sergei Petrunia <sergey@mariadb.com>. The change in sql_parse.cc is not good for 10.4+. A corresponding diff for 10.4+ will be provided in JIRA entry for this bug. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* MDEV-24346 valgrind error in main.precedenceSergei Golubchik2020-12-191-2/+0
| | | | | | | | | | | | | | | in queries like create view v1 as select 2 like 1 escape (3 in (select 0 union select 1)); select 2 union select * from v1; Item_func_like::escape was left uninitialized, because Item_in_optimizer is const_during_execution() but not actually const_item() during execution. It's not, because const subquery evaluation was disabled for derived. Practically it only needs to be disabled for multi-update that runs fix_fields() before all tables are locked.
* MDEV-23406 Signal 8 in maria_create after recursive cte queryIgor Babaev2020-12-161-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-19179 Regression: SELECT ... UNION ... with inconsistent column names failsIgor Babaev2020-11-191-2/+20
| | | | | | | | | | | | A bogus error message was issued when a condition was pushed into a materialized derived table or view specified as union of selects with aggregation when the corresponding columns of the selects had different names. This happened because the expression pushed into having clauses of the selects was adjusted for the names of the first select of the union. The easiest solution was to rename the columns of the other selects to be name compatible with the columns of the first select. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* MDEV-22748 MariaDB crash on WITH RECURSIVE large queryIgor Babaev2020-06-061-5/+1
| | | | | | | | | | | | | | 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 10.1 into 10.2Marko Mäkelä2019-03-041-30/+1
|\ \ \ | |/ /
| * | Merge branch '10.0' into 10.1Oleksandr Byelkin2019-03-011-30/+1
| |\ \
| | * \ Merge branch '5.5' into 10.0Oleksandr Byelkin2019-02-281-30/+1
| | |\ \ | | | |/
| | | * MDEV-17055: Server crashes in find_order_in_list upon 2nd (3rd) execution of ↵Oleksandr Byelkin2019-02-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| | | * A cleanup in derived table handling: removing duplicate code from ↵Alexander Barkov2019-02-281-30/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | st_select_lex::handle_derived() st_select_lex::handle_derived() and mysql_handle_list_of_derived() had exactly the same implementations. - Adding a new method LEX::handle_list_of_derived() instead - Removing public function mysql_handle_list_of_derived() - Reusing LEX::handle_list_of_derived() in st_select_lex::handle_derived()
* | | | MDEV-17024 Crash on large queryIgor Babaev2018-09-071-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | don't set derived->merged until derived is really irreversibly mergedSergei Golubchik2018-02-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | it was set before big if() that could decide not to merge and go with materialization. this fixes a crash in main.view test
* | | | Merge branch 'github/10.1' into 10.2Sergei Golubchik2018-02-061-0/+20
|\ \ \ \ | |/ / /
| * | | Merge branch 'github/10.0' into 10.1Sergei Golubchik2018-02-021-0/+20
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch '5.5' into 10.0Vicențiu Ciorbaru2018-01-241-0/+20
| | |\ \ | | | |/
| | | * MDEV-14786: Server crashes in Item_cond::transform on 2nd execution of SP ↵Oleksandr Byelkin2018-01-231-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | querying from a view MDEV-14957: JOIN::prepare gets unusable "conds" as argument Do not touch merged derived (it is irreversible) Fix first argument of in_optimizer for calls possible before fix_fields()
* | | | Merge 10.1 into 10.2, with some MDEV-14799 fixupsmariadb-10.2.12Marko Mäkelä2018-01-031-6/+47
|\ \ \ \ | |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | trx_undo_page_report_modify(): For SPATIAL INDEX, keep logging updated off-page columns twice, so that the minimum bounding rectangle (MBR) will be logged. Avoiding the redundant logging would require larger changes to the undo log format. row_build_index_entry_low(): Handle SPATIAL_UNKNOWN more robustly, by refusing to purge the record from the spatial index. We can get this code when processing old undo log from 10.2.10 or 10.2.11 (the releases affected by MDEV-14799, which was a regression from MDEV-14051).
| * | | Merge 10.0 into 10.1Marko Mäkelä2018-01-021-5/+46
| |\ \ \ | | |/ /
| | * | Merge 5.5 into 10.0Marko Mäkelä2018-01-021-5/+46
| | |\ \ | | | |/
| | | * MDEV-10657: incorrect result returned with binary protocol (prepared statements)Oleksandr Byelkin2017-12-271-2/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If translation table present when we materialize the derived table then change it to point to the materialized table. Added debug info to see really what happens with what derived.
* | | | Merge remote-tracking branch 'origin/10.1' into 10.2Alexander Barkov2017-11-091-2/+4
|\ \ \ \ | |/ / /
| * | | Merge remote-tracking branch 'origin/10.0' into 10.1Alexander Barkov2017-11-091-2/+4
| |\ \ \ | | |/ /
| | * | MDEV-14164: Unknown column error when adding aggregate to function in oracle ↵Oleksandr Byelkin2017-11-091-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | style procedure FOR loop Make differentiation between pullout for merge and pulout of outer field during exists2in transformation. In last case the field was outer and so we can safely start from name resolution context of the SELECT where it was pulled. Old behavior lead to inconsistence between list of tables and outer name resolution context (which skips one SELECT for merge purposes) which creates problem vor name resolution.
| * | | Merge branch '10.0' into 10.1Vicențiu Ciorbaru2017-09-191-2/+2
| |\ \ \ | | |/ /
| | * | Merge branch '5.5' into 10.0Vicențiu Ciorbaru2017-09-191-2/+2
| | |\ \ | | | |/
| | | * MDEV-11240: Server crashes in check_view_single_update or Assertion ↵Oleksandr Byelkin2017-08-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | `derived->table' failed in mysql_derived_merge_for_insert Before "merge" view shoud be inited to maintaing transitive attributes like "multitable".
* | | | MDEV-13844 : Fix Windows warnings. Fix DBUG_PRINT.Vladislav Vaintroub2017-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Fix win64 pointer truncation warnings (usually coming from misusing 0x%lx and long cast in DBUG) - Also fix printf-format warnings Make the above mentioned warnings fatal. - fix pthread_join on Windows to set return value.
* | | | MDEV-11240: Server crashes in check_view_single_update or Assertion ↵mariadb-10.2.8Oleksandr Byelkin2017-08-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | `derived->table' failed in mysql_derived_merge_for_insert Before "merge" view shoud be inited to maintaing transitive attributes like "multitable".
* | | | Merge branch '10.1' into 10.2Sergei Golubchik2017-08-171-0/+2
|\ \ \ \ | |/ / /
| * | | Merge branch '10.0' into 10.1Sergei Golubchik2017-08-081-0/+2
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch 'origin/5.5' into 10.0Vicențiu Ciorbaru2017-07-251-0/+2
| | |\ \ | | | |/
| | | * MDEV-11240: Server crashes in check_view_single_update or Assertion ↵Oleksandr Byelkin2017-07-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | `derived->table' failed in mysql_derived_merge_for_insert Move table pointer for single table view (even if it is view over other view) to make the access universal.
* | | | MDEV-13439: Database permissions are not enough to run a subquery with GROUP ↵Oleksandr Byelkin2017-08-101-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | BY within a view The bug is result adding ability to have derived tables inside views. Fixed checks should be a switch between view/derived or select derived and information schema.
* | | | Fixed the bug mdev-12845.Igor Babaev2017-06-221-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fills in a serious flaw in the code that supports condition pushdown into materialized views / derived tables. If a predicate happened to contain a reference to a mergeable view / derived table and it does not depended directly on the target materialized view / derived table then the predicate was not considered as a subject to pusdown to this view / derived table.
* | | | Fixed the bug mdev-12563.Igor Babaev2017-04-281-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-12373.Igor Babaev2017-04-241-0/+3
| | | | | | | | | | | | | | | | | | | | Condition pushdown into derived tables / views with side effects is not allowed.
* | | | Merge branch '10.1' into 10.2Sergei Golubchik2017-03-301-0/+3
|\ \ \ \ | |/ / /
| * | | Merge 10.0 into 10.1Marko Mäkelä2017-03-091-0/+3
| |\ \ \ | | |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, implement MDEV-11027 a little differently from 5.5 and 10.0: recv_apply_hashed_log_recs(): Change the return type back to void (DB_SUCCESS was always returned). Report progress also via systemd using sd_notifyf().
| | * | Merge branch '5.5' into 10.0Vicențiu Ciorbaru2017-03-031-0/+3
| | |\ \ | | | |/
| | | * Fixed bug mdev-12099.Igor Babaev2017-02-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function mysql_derived_merge() erroneously did not mark newly formed AND formulas in ON conditions with the flag abort_on_null. As a result not_null_tables() calculated incorrectly for these conditions. This could prevent conversion of embedded outer joins into inner joins. Changed a test case from table_elim.test to preserve the former execution plan.
* | | | Fixed bug mdev-12368.Igor Babaev2017-03-261-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Fixed bug mdev-11820.Igor Babaev2017-01-241-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The fields st_select_lex::cond_pushed_into_where and st_select_lex::cond_pushed_into_having should be re-initialized for the unit specifying a derived table at every re-execution of the query that uses this derived table, because the result of condition pushdown may be different for different executions.
* | | | Such big blocks in query processing should be represented in the debugging ↵Oleksandr Byelkin2017-01-181-7/+8
| | | | | | | | | | | | | | | | trace.
* | | | Fixed bug mdev-11674.Igor Babaev2017-01-041-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Merge branch '10.1' into 10.2Sergei Golubchik2016-12-291-0/+1
|\ \ \ \ | |/ / /
| * | | Merge branch '10.0' into 10.1Sergei Golubchik2016-12-111-0/+1
| |\ \ \ | | |/ /
| | * | Merge branch '5.5' into 10.0Sergei Golubchik2016-12-091-0/+2
| | |\ \ | | | |/