summaryrefslogtreecommitdiff
path: root/sql/sql_select.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge bb-10.2-ext into 10.3Marko Mäkelä2018-02-151-2/+2
|\
| * Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2018-02-081-2/+2
| |\
| | * Merge branch 'github/10.1' into 10.2Sergei Golubchik2018-02-061-2/+2
| | |\
| | | * Merge branch 'github/10.0' into 10.1Sergei Golubchik2018-02-021-1/+1
| | | |\
| | | | * Merge remote-tracking branch '5.5' into 10.0Vicențiu Ciorbaru2018-01-241-1/+1
| | | | |\
| | | | | * MDEV-14715: Assertion `!table || (!table->read_set... failed in ↵Vicențiu Ciorbaru2018-01-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Field_num::val_decimal The assertion failure was caused by an incorrectly set read_set for functions in the ORDER BY clause in part of a union, when we are using a mergeable view and the order by clause can be skipped (removed). An order by clause can be skipped if it's part of one part of the UNION as the result set is not meaningful when multiple SELECT queries are UNIONed. The server is aware of this optimization and tries to remove the order by clause before JOIN::prepare. The problem is that we need to throw an error when the ORDER BY clause contains invalid columns. To do this, we attempt resolving the ORDER BY expressions, then subsequently drop them if resolution succeeded. However, ORDER BY resolution had the side effect of adding the expressions to the all_fields list, which is used to construct temporary tables to store the result. We may be ignoring the ORDER BY statement, but the tmp table still tried to compute the values for the expressions, even if the columns are never used. The assertion only shows itself if the order by clause contains members which were not previously in the select list, and are part of a function. There is an additional question as to why this only manifests when using VIEWS and not when using a regular table. The difference lies with the "reset" of the read_set for the temporary table during SELECT_LEX::update_used_tables() in JOIN::optimize(). The changes introduced in fdf789a7eadf864ecc0e617f25f795fafda55026 cleared the read_set when a mergeable view is encountered in the TABLE_LIST defintion. Upon initial order_list resolution, the table's read_set is updated correctly. JOIN::optimize() will only reset the read_set if it encounters a VIEW. Since we no longer have ORDER BY clause in JOIN::optimize() we never get to correctly update the read_set again. Other relevant commit by Timour, which first introduced the order resolution when we "can_skip_sort_order": 883af99e7dac91e3f258135a2053e6b8e3c05fc3 Solution: Don't add the resolved ORDER BY elements to all_fields. We only resolve them to check if an error should be returned for the query. Ignore them completely otherwise.
* | | | | | Remove ER_NON_VERSIONED_FIELD_IN_HISTORICAL_QUERYSergei Golubchik2018-02-121-2/+0
| | | | | |
* | | | | | Windows, compile : reenable previously disabled warning C4291Vladislav Vaintroub2018-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | no matching operator delete found; memory will not be freed if initialization throws an exception Added a no-op delete() for MEM_ROOT based placement-new()
* | | | | | Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3Alexander Barkov2018-02-041-1/+1
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Setting Field::field_index for Virtual_tmp_table fieldsAlexander Barkov2018-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Virtial_tmp_table did not set the "field_index" member for its Fields. Fixing Virtual_tmp_table::add() to set "field_index" to the Field's ordinal position inside the table, like a normal TABLE does, for consistency. Although, this flaw did not seem to cause any bugs, having field_index properly set is helpful for debugging purposes.
* | | | | | Changed database, tablename and alias to be LEX_CSTRINGMonty2018-01-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was done in, among other things: - thd->db and thd->db_length - TABLE_LIST tablename, db, alias and schema_name - Audit plugin database name - lex->db - All db and table names in Alter_table_ctx - st_select_lex db Other things: - Changed a lot of functions to take const LEX_CSTRING* as argument for db, table_name and alias. See init_one_table() as an example. - Changed some function arguments from LEX_CSTRING to const LEX_CSTRING - Changed some lists from LEX_STRING to LEX_CSTRING - threads_mysql.result changed because process list_db wasn't always correctly updated - New append_identifier() function that takes LEX_CSTRING* as arguments - Added new element tmp_buff to Alter_table_ctx to separate temp name handling from temporary space - Ensure we store the length after my_casedn_str() of table/db names - Removed not used version of rename_table_in_stat_tables() - Changed Natural_join_column::table_name and db_name() to never return NULL (used for print) - thd->get_db() now returns db as a printable string (thd->db.str or "")
* | | | | | Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3Alexander Barkov2018-01-291-0/+42
|\ \ \ \ \ \ | |/ / / / /
| * | | | | MDEV-15107 Add virtual Field::sp_prepare_and_store_item(), make sp_rcontext ↵Alexander Barkov2018-01-291-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | symmetric for scalar and ROW After MDEV-14212, the Virtual_tmp_table instance that stores a ROW variable elements is accessible from the underlying Field_row (rather than Item_field_row). This patch makes some further changes by moving the code from sp_instr_xxx, sp_rcontext, Item_xxx to Virtual_tmp_table and Field_xxx. The data type specific code (scalar vs ROW) now resides in a new virtual method Field_xxx::sp_prepare_and_store_item(). The the code in sp_rcontext::set_variable() and sp_eval_expr() is now symmetric for scalar and ROW values. The code in sp_rcontext::set_variable_row_field(), sp_rcontext::set_variable_row_field(), sp_rcontext::set_variable_row() is now symmetric for ROW elements (i.e. scalar and ROW elements inside a ROW). Rationale: Prepare the code to implement these tasks soon easier: - MDEV-12252 ROW data type for stored function return values - MDEV-12307 ROW data type for built-in function return values - MDEV-6121 Data type: Array - MDEV-10593 sql_mode=ORACLE: TYPE .. AS OBJECT: basic functionality - ROW with ROW fields (no MDEV yet) Details: 1. Moving the code in sp_eval_expr() responsible to backup/restore thd->count_cuted_fields, thd->abort_on_warning, thd->transaction.stmt.modified_non_trans_table into a new helper class Sp_eval_expr_state, to reuse it easier. Fixing sp_eval_expr() to use this new class. 2. Moving sp_eval_expr() and sp_prepare_func_item() from public functions to methods in THD, so they can be reused in *.cc files easier without a need to include "sp_head.h". Splitting sp_prepare_func_item() into two parts. Adding a new function sp_fix_func_item(), which fixes the underlying items, but does not do check_cols() for them. Reusing sp_fix_func_item() in Field_row::sp_prepare_and_store_item(). 3. Moving the code to find ROW fields by name from Item to Virtual_tmp_table Moving the code searching for ROW fields by their names from Item_field_row::element_index_by_name() to a new method Item_field_row to Virtual_tmp_table::sp_find_field_by_name(). Adding wrapper methods sp_rcontext::find_row_field_by_name() and find_row_field_by_name_or_error(), to search for a ROW variable fields by the variable offset and its field name. Changing Item_splocal_row_field_by_name::fix_fields() to do use sp_rcontext::find_row_field_by_name_or_error(). Removing virtual Item::element_index_by_name(). 4. Splitting sp_rcontext::set_variable() Adding a new virtual method Field::sp_prepare_and_store_item(). Spliting the two branches of the code in sp_rcontext::set_variable() into two virtual implementations of Field::sp_prepare_and_store_item(), (for Field and for Field_row). Moving the former part of sp_rcontext::set_variable() with the loop doing set_null() for all ROW fields into a new method Virtual_tmp_table::set_all_fields_to_null() and using it in Field_row::sp_prepare_and_store_item(). Moving the former part of sp_rcontext::set_variable() with the loop doing set_variable_row_field() into a new method Virtual_tmp_table::set_all_fields_from_item() and using it in Field_row::sp_prepare_and_store_item(). The loop in the new method now uses sp_prepare_and_store_item() instead of set_variable_row_field(), because saving/restoring THD flags is now done on the upper level. No needs to save/restore on every iteration. 5. Fixing sp_eval_expr() to simply do two things: - backup/restore THD flags - call result_field->sp_prepare_and_store_item() So now sp_eval_expr() can be used for both scalar and ROW variables. Reusing it in sp_rcontext::set_variable*(). 6. Moving the loop in sp_rcontext::set_variable_row() into a new method Virtual_tmp_table::sp_set_all_fields_from_item_list(). Changing the loop body to call field->sp_prepare_and_store_item() instead of doing set_variable_row_field(). This removes saving/restoring of the THD flags from every interation. Instead, adding the code to save/restore the flags around the entire loop in set_variable_row(), using Sp_eval_expr_state. So now saving/restoring is done only once for the entire ROW (a slight performance improvement). 7. Removing the code in sp_instr_set::exec_core() that sets a variable to NULL if the value evaluation failed. sp_rcontext::set_variable() now makes sure to reset the variable properly by effectively calling sp_eval_expr(), which calls virtual Field::sp_prepare_and_store_item(). Removing the similar code from sp_instr_set_row_field::exec_core() and sp_instr_set_row_field_by_name::exec_core(). Removing the method sp_rcontext::set_variable_row_field_to_null(), as it's not used any more. 8. Removing the call for sp_prepare_func_item() from sp_rcontext::set_variable_row_field(), as it was duplicate: it was done inside sp_eval_expr(). Now it's done inside virtual Field::sp_prepare_and_store_item(). 9. Moving the code from sp_instr_set_row_field_by_name::exec_core() into sp_rcontext::set_variable_row_field_by_name(), for symmetry with other sp_instr_set*::exec_core()/sp_rcontext::set_variable*() pairs. Now sp_instr_set_row_field_by_name::exec_core() calls sp_rcontext::set_variable_row_field_by_name(). 10. Misc: - Adding a helper private method sp_rcontext::virtual_tmp_table_for_row(), reusing it in a new sp_rcontext methods. - Removing Item_field_row::get_row_field(), as it's not used any more. - Removing the "Item *result_item" from sp_eval_expr(), as it's not needed any more.
* | | | | | Merge branch 'github/10.3' into bb-10.3-temporalmariadb-10.3.4Sergei Golubchik2018-01-171-2/+2
|\ \ \ \ \ \
| * \ \ \ \ \ Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-111-2/+2
| |\ \ \ \ \ \ | | |/ / / / /
| | * | | | | Merge 10.2 into bb-10.2-extMarko Mäkelä2018-01-111-2/+2
| | |\ \ \ \ \ | | | |/ / / /
| | | * | | | Fix Compile Error while using Flag '-DUSE_ARIA_FOR_TMP_TABLES:BOOL=OFF'Sachin Setiya2018-01-071-2/+2
| | | | | | |
* | | | | | | System Versioning 1.0 pre8Aleksey Midenkov2018-01-101-11/+71
|\ \ \ \ \ \ \ | |/ / / / / / | | | | | | | | | | | | | | Merge branch '10.3' into trunk
| * | | | | | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-051-1/+1
| |\ \ \ \ \ \ | | |/ / / / /
| | * | | | | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extMonty2018-01-051-1/+1
| | |\ \ \ \ \ | | | |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: mysql-test/r/cte_nonrecursive.result mysql-test/suite/galera/r/galera_bf_abort.result mysql-test/suite/galera/r/galera_bf_abort_get_lock.result mysql-test/suite/galera/r/galera_bf_abort_sleep.result mysql-test/suite/galera/r/galera_enum.result mysql-test/suite/galera/r/galera_fk_conflict.result mysql-test/suite/galera/r/galera_insert_multi.result mysql-test/suite/galera/r/galera_many_indexes.result mysql-test/suite/galera/r/galera_mdl_race.result mysql-test/suite/galera/r/galera_nopk_bit.result mysql-test/suite/galera/r/galera_nopk_blob.result mysql-test/suite/galera/r/galera_nopk_large_varchar.result mysql-test/suite/galera/r/galera_nopk_unicode.result mysql-test/suite/galera/r/galera_pk_bigint_signed.result mysql-test/suite/galera/r/galera_pk_bigint_unsigned.result mysql-test/suite/galera/r/galera_serializable.result mysql-test/suite/galera/r/galera_toi_drop_database.result mysql-test/suite/galera/r/galera_toi_lock_exclusive.result mysql-test/suite/galera/r/galera_toi_truncate.result mysql-test/suite/galera/r/galera_unicode_pk.result mysql-test/suite/galera/r/galera_var_auto_inc_control_off.result mysql-test/suite/galera/r/galera_wsrep_log_conficts.result sql/field.cc sql/rpl_gtid.cc sql/share/errmsg-utf8.txt sql/sql_acl.cc sql/sql_parse.cc sql/sql_partition_admin.cc sql/sql_prepare.cc sql/sql_repl.cc sql/sql_table.cc sql/sql_yacc.yy
| | | * | | | Fix out-of-date comments.Sergei Petrunia2018-01-041-1/+1
| | | | | | |
| * | | | | | This is a full cost-based implementation of the optimization that employsIgor Babaev2017-12-301-10/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | splitting technique for equi-joins of materialized derived tables/views/CTEs. (see mdev-13369 and mdev-13389).
* | | | | | | SQL: RIGHT JOIN in derived [fix #383]Aleksey Midenkov2017-12-121-0/+4
| | | | | | |
* | | | | | | System Versioning 1.0 pre3Aleksey Midenkov2017-12-111-1/+1
|\ \ \ \ \ \ \ | |/ / / / / / | | | | | | | | | | | | | | Merge branch '10.3' into trunk
| * | | | | | Mark constant 'null_tables' with table->const_table=1Monty2017-12-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was done to make thing consistent. It gives the additional benefit that EXPLAIN EXTENDED now treat null_tables like constant's and replaces columns with NULL, in a similar way that it replaces columns with constants for constant tables. - Null tables are tables where all columns are always NULL. The most common NULL TABLE is a table used in a LEFT_JOIN that is never true. - All result changes comes from replacing columns with NULL for null_tables. - "Impossible where" is now also shows constants for const columns. - Removed duplicated s->type= JT_CONST - Reset found_const_table_map when JOIN is created (safety fix)
* | | | | | | SQL: vers_setup_select() misc refactoringAleksey Midenkov2017-12-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Renamed to SELECT_LEX::vers_setup_conds(). Moved optimized fields check to JOIN::vers_check_items().
* | | | | | | System Versioning 1.0pre2Aleksey Midenkov2017-11-231-3/+3
|\ \ \ \ \ \ \ | |/ / / / / / | | | | | | | | | | | | | | Merge branch '10.3' into trunk
| * | | | | | Handle failures from mallocMichael Widenius2017-11-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Most "new" failures fixed in the following files: - sql_select.cc - item.cc - item_func.cc - opt_subselect.cc Other things: - Allocate udf_handler strings in mem_root - Required changes in sql_string.h - Add mem_root as argument to some new [] calls - Mark udf_handler strings as thread specific - Removed some comment blocks with code
* | | | | | | System Versioning pre1.0Aleksey Midenkov2017-11-131-0/+4
|\ \ \ \ \ \ \ | |/ / / / / / | | | | | | | | | | | | | | Merge branch '10.3' into trunk
| * | | | | | Merge bb-10.2-ext into 10.3Marko Mäkelä2017-11-101-0/+3
| |\ \ \ \ \ \ | | |/ / / / /
| | * | | | | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-11-031-0/+1
| | |\ \ \ \ \ | | | |/ / / /
| | | * | | | Fixed mdev-14093 Wrong result upon JOIN with INDEX with no rowsIgor Babaev2017-11-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in joined table + GROUP BY + GROUP_CONCAT + HAVING + ORDER BY [by field from HAVING] + 1 row expected The fix is actually a port of the fix for bug #17055185 from mysql code line (see commit f289aeeef0743508ff87211084453b3b88a6d017 by Mithun C Y into mysql-5.6). The test case for the bug #17055185 was also ported.
| | * | | | | Fixed compiler warning and unitialized memory warningMonty2017-11-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - The valgrind warning came from JOIN::optimize() (sql_select.cc:1123)
| * | | | | | Merge remote-tracking branch 'shagalla/10.3-mdev12172' into 10.3Igor Babaev2017-11-011-0/+1
| |\ \ \ \ \ \ | | |/ / / / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As a result of this merge the code for the following tasks appears in 10.3: - MDEV-12172 Implement tables specified by table value constructors - MDEV-12176 Transform [NOT] IN predicate with long list of values INTO [NOT] IN subquery.
| | * | | | | Post review changes for the optimization of IN predicates into IN subqueries.Galina Shalygina2017-09-021-1/+1
| | | | | | |
| | * | | | | Summarized results of two previous commits (26 July, 25 August)Galina Shalygina2017-08-291-0/+1
| | | | | | |
* | | | | | | System Versioning pre0.12Aleksey Midenkov2017-11-071-0/+3
|\ \ \ \ \ \ \ | |/ / / / / / |/| | | | | | | | | | | | | Merge remote-tracking branch 'origin/archive/2017-10-17' into 10.3
| * | | | | | 0.6: truncate history feature [closes #96]kevg2017-05-051-0/+3
| | | | | | |
* | | | | | | A cleanup for MDEV-10914 ROW data type for stored routine variablesAlexander Barkov2017-10-031-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Changing datatypes for: - Item_spvar_args::m_table - sp_rcontext::m_var_table - return value of create_virtual_tmp_table() from TABLE* to Virtual_tmp_table* Advantages: - Stricter data type control - Removing the duplicate code (a loop with free_blobs) from destructors ~sp_rcontext() and ~Item_spvar_args(), using "delete m_(var_)table" in both instead. - Using Virtual_tmp_table::delete makes the code call Field::delete, which calls TRASH() for the freed fields, which is good for valgrind test runs.
* | | | | | | Fixed the bug mdev-13709.Igor Babaev2017-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently condition pushdown into materialized views / derived tables is not implemented yet (see mdev-12387) and grouping views are optimized early when subqueries are converted to semi-joins in convert_join_subqueries_to_semijoins(). If a subquery that is converted to a semi-join uses a grouping view this view is optimized in two phases. For such a view V only the first phase of optimization is done after the conversion of subqueries of the outer join into semi-joins. At the same time the reference of the view V appears in the join expression of the outer join. In fixed code there was an attempt to push conditions into this view and to optimize it after this. This triggered the second phase of the optimization of the view and it was done prematurely. The second phase of the optimization for the materialized view is supposed to be called after the splitting condition is pushed into the view in the call of JOIN::improve_chosen_plan for the outer join. The fix blocks the attempt to push conditions into splittable views if they have been already partly optimized and the following optimization for them. The test case of the patch shows that the code for mdev-13369 basically supported the splitting technique for materialized views / derived tables. The patch also replaces the name of the state JOIN::OPTIMIZATION_IN_STAGE_2 for JOIN::OPTIMIZATION_PHASE_1_DONE and fixes a bug in TABLE_LIST::fetch_number_of_rows()
* | | | | | | Implemented condition pushdown into derived tables / viewsIgor Babaev2017-08-121-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with window functions (mdev-10855). This patch just modified the function pushdown_cond_for_derived() to support this feature. Some test cases demonstrating this optimization were added to derived_cond_pushdown.test.
* | | | | | | This is a modification of the first patch committed for mdev-13369Igor Babaev2017-08-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | developed to cover the case of mdev-13389: "Optimization for equi-joins of derived tables with window functions".
* | | | | | | This first patch prepared for the task MDEV-13369:Igor Babaev2017-08-101-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "Optimization for equi-joins of derived tables with GROUP BY" should be considered rather as a 'proof of concept'. The task itself is targeted at an optimization that employs re-writing equi-joins with grouping derived tables / views into lateral derived tables. Here's an example of such transformation: select t1.a,t.max,t.min from t1 [left] join (select a, max(t2.b) max, min(t2.b) min from t2 group by t2.a) as t on t1.a=t.a; => select t1.a,tl.max,tl.min from t1 [left] join lateral (select a, max(t2.b) max, min(t2.b) min from t2 where t1.a=t2.a) as t on 1=1; The transformation pushes the equi-join condition t1.a=t.a into the derived table making it dependent on table t1. It means that for every row from t1 a new derived table must be filled out. However the size of any of these derived tables is just a fraction of the original derived table t. One could say that transformation 'splits' the rows used for the GROUP BY operation into separate groups performing aggregation for a group only in the case when there is a match for the current row of t1. Apparently the transformation may produce a query with a better performance only in the case when - the GROUP BY list refers only to fields returned by the derived table - there is an index I on one of the tables T used in FROM list of the specification of the derived table whose prefix covers the the fields from the proper beginning of the GROUP BY list or fields that are equal to those fields. Whether the result of the re-writing can be executed faster depends on many factors: - the size of the original derived table - the size of the table T - whether the index I is clustering for table T - whether the index I fully covers the GROUP BY list. This patch only tries to improve the chosen execution plan using this transformation. It tries to do it only when the chosen plan reaches the derived table by a key whose prefix covers all the fields of the derived table produced by the fields of the table T from the GROUP BY list. The code of the patch does not evaluates the cost of the improved plan. If certain conditions are met the transformation is applied.
* | | | | | | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-07-071-0/+8
|\ \ \ \ \ \ \ | |_|/ / / / / |/| | / / / / | | |/ / / / | |/| | | |
| * | | | | Merge branch '10.1' into 10.2Sergei Golubchik2017-07-051-0/+8
| |\ \ \ \ \ | | | |/ / / | | |/| | |
| | * | | | Merge remote-tracking branch '10.0' into 10.1Vicențiu Ciorbaru2017-06-211-0/+8
| | |\ \ \ \ | | | | |/ / | | | |/| |
| | | * | | Merge remote-tracking branch '5.5' into 10.0Vicențiu Ciorbaru2017-06-201-0/+8
| | | |\ \ \ | | | | | |/ | | | | |/|
| | | | * | Fixed the bug mdev-12838.Igor Babaev2017-06-071-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the optimizer chose an execution plan where a semi-join nest were materialized and the result of materialization was scanned to access other tables by ref access it could build a key over columns of the tables from the nest that were actually inaccessible. The patch performs a proper check whether a key that uses columns of the tables from a materialized semi-join nest can be employed to access outer tables.
* | | | | | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-05-051-0/+2
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Fixed the bug mdev-11990.Igor Babaev2017-05-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The usage of windows functions when all tables were optimized away by min/max optimization were not supported. As result a result, the queries that used window functions with min/max aggregation over the whole table returned wrong result sets. The patch fixed this problem.