summaryrefslogtreecommitdiff
path: root/sql/sql_derived.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch '10.3' into 10.4Oleksandr Byelkin2019-12-091-1/+8
|\
| * MDEV-21147 Assertion `marked_for_read()' upon UPDATE on versioned table via viewAleksey Midenkov2019-12-041-1/+8
| | | | | | | | | | | | | | | | Unit prepare prematurely fixed field which must be fixed via setup_conds() to correctly update table->covering_keys. Call vers_setup_conds() directly instead, because actually everything else is not needed.
* | Merge 10.3 into 10.4Aleksey Midenkov2019-12-021-4/+19
|\ \ | |/
| * MDEV-21155 Assertion with versioned table upon DELETE from view of view ↵Aleksey Midenkov2019-12-021-4/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after replacing first view When view is merged by DT_MERGE_FOR_INSERT it is then skipped from processing and doesn't update WHERE clause with vers_setup_conds(). Note that view itself cannot work in vers_setup_conds() because it doesn't have row_start, row_end fields. Thus it is required to descend down to material TABLE_LIST through calls of mysql_derived_prepare() and run vers_setup_conds() from there. Luckily, all views (views of views, views of views of views, etc.) are linked in one list through next_global pointer, so we can skip all views of views and get straight to non-view TABLE_LIST by checking its merge_underlying_list property for zero value (it is assigned by DT_MERGE_FOR_INSERT for merged derived tables). We have to do that only for UPDATE and DELETE. Other DML commands don't use WHERE clause. MDEV-21146 Assertion `m_lock_type == 2' in handler::ha_drop_table upon LOAD DATA LOAD DATA does not use WHERE and the above call of vers_setup_conds() is not needed. unit->prepare() led to wrongly locked temporary table.
| * MDEV-18727 improve DML operation of System VersioningAleksey Midenkov2019-11-221-0/+10
| | | | | | | | | | | | | | | | | | 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-0/+10
| | | | | | | | | | | | | | UPDATE, DELETE: replace linear search of current/historical records with vers_setup_conds(). Additional DML cases in view.test
* | Merge branch '10.3' into 10.4Oleksandr Byelkin2019-05-191-1/+1
|\ \ | |/
| * 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-19263: Server crashes in mysql_handle_single_derived upon 2nd execution ↵Oleksandr Byelkin2019-04-161-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of PS Fix case of prelocking placeholder
* | | | | Cleanup of sql_derived.cc filebb-10.4-cleanupOleksandr Byelkin2019-04-161-11/+17
| | | | |
* | | | | MDEV-17362: SIGSEGV in JOIN::optimize_inner or Assertion `fixed == 0' failed ↵Oleksandr Byelkin2019-04-161-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in Item_equal::fix_fields, server crashes after 2nd execution of PS Move reinitialisation of pushdown variables for every query, because it used now not only for derived tables.
* | | | | MDEV-18769 Assertion `fixed == 1' failed in Item_cond_or::val_intGalina Shalygina2019-04-041-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug is caused by pushdown from HAVING into WHERE. It appears because condition that is pushed wasn't fixed. It is also discovered that condition pushdown from HAVING into WHERE is done wrong. There is no need to build clones for some conditions that can be pushed. They can be simply moved from HAVING into WHERE without cloning. build_pushable_cond_for_having_pushdown(), remove_pushed_top_conjuncts_for_having() methods are changed. It is found that there is no transformation made for fields of pushed condition. field_transformer_for_having_pushdown transformer is added. New tests are added. Some comments are changed.
* | | | | Merge branch '10.3' into 10.4Oleksandr Byelkin2019-03-081-0/+1
|\ \ \ \ \ | |/ / / /
| * | | | Fix of PS after merge from 10.2.Oleksandr Byelkin2019-03-081-0/+1
| | | | | | | | | | | | | | | | | | | | TVC uses derived as singlatable calls
* | | | | Merge 10.3 into 10.4Marko Mäkelä2019-03-061-30/+1
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.2 into 10.3Marko Mäkelä2019-03-051-30/+1
| |\ \ \ \ | | |/ / / | | | | | | | | | | | | | | | | | | | | 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-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-18679 Server crashes in JOIN::optimizeIgor Babaev2019-02-261-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug manifested itself when executing a query with materialized view/derived/CTE whose specification was a SELECT query contained another materialized derived and impossible WHERE/HAVING condition was detected for this SELECT. As soon as such condition is detected the join structures of all derived tables used in the SELECT are destroyed. So optimization of the queries specifying these derived tables is impossible. Besides it's not needed. In 10.3 optimization of a materialized derived table is performed before detection of impossible WHERE/HAVING condition in the embedding SELECT.
* | | | | | Merge branch '10.4' into bb-10.4-mdev7486Galina Shalygina2019-02-191-22/+21
|\ \ \ \ \ \
| * | | | | | Minor cleanup in the optimizer trace code.Varun Gupta2019-02-181-22/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | More test coverage added for the optimizer trace.
* | | | | | | MDEV-7486: Condition pushdown from HAVING into WHEREGalina Shalygina2019-02-171-5/+3
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Condition can be pushed from the HAVING clause into the WHERE clause if it depends only on the fields that are used in the GROUP BY list or depends on the fields that are equal to grouping fields. Aggregate functions can't be pushed down. How the pushdown is performed on the example: SELECT t1.a,MAX(t1.b) FROM t1 GROUP BY t1.a HAVING (t1.a>2) AND (MAX(c)>12); => SELECT t1.a,MAX(t1.b) FROM t1 WHERE (t1.a>2) GROUP BY t1.a HAVING (MAX(c)>12); The implementation scheme: 1. Extract the most restrictive condition cond from the HAVING clause of the select that depends only on the fields that are used in the GROUP BY list of the select (directly or indirectly through equalities) 2. Save cond as a condition that can be pushed into the WHERE clause of the select 3. Remove cond from the HAVING clause if it is possible The optimization is implemented in the function st_select_lex::pushdown_from_having_into_where(). New test file having_cond_pushdown.test is created.
* | | | | | Merge branch '10.4' into bb-10.4-mdev17096Igor Babaev2019-02-121-8/+41
|\ \ \ \ \ \
| * | | | | | MDEV-6111 Optimizer TraceVarun Gupta2019-02-131-8/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This task involves the implementation for the optimizer trace. This feature produces a trace for any SELECT/UPDATE/DELETE/, which contains information about decisions taken by the optimizer during the optimization phase (choice of table access method, various costs, transformations, etc). This feature would help to tell why some decisions were taken by the optimizer and why some were rejected. Trace is session-local, controlled by the @@optimizer_trace variable. To enable optimizer trace we need to write: set @@optimizer_trace variable= 'enabled=on'; To display the trace one can run: SELECT trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; This task also involves: MDEV-18489: Limit the memory used by the optimizer trace introduces a switch optimizer_trace_max_mem_size which limits the memory used by the optimizer trace. This was implemented by Sergei Petrunia.
* | | | | | | MDEV-17096 Pushdown of simple derived tables to storage enginesIgor Babaev2019-02-121-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-17631 select_handler for a full query pushdown Added comments and file headers for files introduced in these tasks.
* | | | | | | MDEV-17096 Pushdown of simple derived tables to storage enginesIgor Babaev2019-02-091-9/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Resolved the problem of forming a proper query string for FEDERATEDX. Added test cases. Cleanup of extra spaces.
* | | | | | | Merge branch '10.4' into bb-10.4-mdev17096Igor Babaev2019-02-061-1/+4
|\ \ \ \ \ \ \ | |/ / / / / /
| * | | | | | Merge 10.3 into 10.4Marko Mäkelä2018-10-051-1/+4
| |\ \ \ \ \ \ | | |/ / / / /
| | * | | | | Merge branch '10.2' into 10.3Sergei Golubchik2018-09-281-2/+4
| | |\ \ \ \ \ | | | |/ / / /
| | | * | | | 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.
* | | | | | | MDEV-17096 Pushdown of simple derived tables to storage enginesIgor Babaev2019-02-061-3/+79
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-17631 select_handler for a full query pushdown Interfaces + Proof of Concept for federatedx with test cases. The interfaces have been developed for integration of ColumnStore engine.
* | | | | | MDEV-11953: support of brackets in UNION/EXCEPT/INTERSECT operationsOleksandr Byelkin2018-07-041-1/+2
| | | | | |
* | | | | | Merge remote-tracking branch 'origin/10.3' into 10.4Alexander Barkov2018-06-051-3/+1
|\ \ \ \ \ \ | |/ / / / /
| * | | | | MDEV-16385 ROW SP variable is allowed in unexpected contextAlexander Barkov2018-06-051-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem described in the bug report happened because the code did not test check_cols(1) after fix_fields() in a few places. Additionally, fix_fields() could be called multiple times for SP variables, because they are all fixed at a early stage in append_for_log(). Solution: 1. Adding a few helper methods - fix_fields_if_needed() - fix_fields_if_needed_for_scalar() - fix_fields_if_needed_for_bool() - fix_fields_if_needed_for_order_by() and using it in many cases instead of fix_fields() where the "fixed" status is not definitely known to be "false". 2. Adding DBUG_ASSERT(!fixed) into Item_splocal*::fix_fields() to catch double execution. 3. Adding tests. As a good side effect, the patch removes a lot of duplicate code (~60 lines): if (!item->fixed && item->fix_fields(..) && item->check_cols(1)) return true;
* | | | | | Merge branch '10.3' into 10.4Igor Babaev2018-06-031-5/+4
|\ \ \ \ \ \ | |/ / / / /
| * | | | | MDEV-14820 System versioning is applied incorrectly to CTEsSergei Golubchik2018-05-121-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure that SELECT_LEX_UNIT::derived, behaves as documented (points to the "TABLE_LIST representing this union in the embedding select"). For recursive CTE this was not necessarily the case, it could've pointed to the TABLE_LIST inside the CTE, not in the embedding select. To fix: * don't update unit->derived in mysql_derived_prepare(), pass derived as an argument to st_select_lex_unit::prepare() * prefer to set unit->derived in TABLE_LIST::init_derived() to the TABLE_LIST in the embedding select, not to the recursive reference. Fail if there are many TABLE_LISTs in the embedding select with conflicting FOR SYSTEM_TIME clauses. cleanup: * remove redundant THD* argument from st_select_lex_unit::prepare()
| * | | | | Add likely/unlikely to speed up executionMonty2018-05-071-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added to: - if (error) - Lex - sql_yacc.yy and sql_yacc_ora.yy - In header files to alloc() calls - Added thd argument to thd_net_is_killed()
* | | | | | MDEV-12387 Push conditions into materialized subqueriesGalina Shalygina2018-05-151-121/+90
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The logic and the implementation scheme are similar with the MDEV-9197 Pushdown conditions into non-mergeable views/derived tables How the push down is made on the example: select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 group by x); --> select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 where x>3 group by x having max(y)>10); The implementation scheme: 1. Search for the condition cond that depends only on the fields from the left part of the IN subquery (left_part) 2. Find fields F_group in the select of the right part of the IN subquery (right_part) that are used in the GROUP BY 3. Extract from the cond condition cond_where that depends only on the fields from the left_part that stay at the same places in the left_part (have the same indexes) as the F_group fields in the projection of the right_part 4. Transform cond_where so it can be pushed into the WHERE clause of the right_part and delete cond_where from the cond 5. Transform cond so it can be pushed into the HAVING clause of the right_part The optimization is made in the Item_in_subselect::pushdown_cond_for_in_subquery() and is controlled by the variable condition_pushdown_for_subquery. New test file in_subq_cond_pushdown.test is created. There are also some changes made for setup_jtbm_semi_joins(). Now it is decomposed into the 2 procedures: setup_degenerate_jtbm_semi_joins() that is called before optimize_cond() for cond and setup_jtbm_semi_joins() that is called after optimize_cond(). New setup_jtbm_semi_joins() is made in the way so that the result of its work is the same as if it was called before optimize_cond(). The code that is common for pushdown into materialized derived and into materialized IN subqueries is factored out into pushdown_cond_for_derived(), Item_in_subselect::pushdown_cond_for_in_subquery() and st_select_lex::pushdown_cond_into_where_clause().
* | | | | Fixed MDEV-14883 Usage of EXCEPT and INTERSECT in recursive CTEIgor Babaev2018-02-221-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-02-151-1/+21
|\ \ \ \ \
| * \ \ \ \ Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2018-02-081-1/+21
| |\ \ \ \ \ | | |/ / / /
| | * | | | 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
| | | |\ \ \ | | | | |/ /