summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3Alexander Barkov2018-02-041-7/+10
|\
| * Added name to MEM_ROOT for esier debuggingMonty2018-02-021-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | This will make it easier to how memory allocation is done when debugging with either DBUG or gdb. Will especially help when debugging stored procedures Main change is a name argument as second argument to init_alloc_root() init_sql_alloc() Other things: - Added DBUG_ENTER/EXIT to some Virtual_tmp_table functions
* | Changed database, tablename and alias to be LEX_CSTRINGMonty2018-01-301-31/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 "")
* | Fixed mdev-15017 Server crashes in in st_join_table::fix_splittingIgor Babaev2018-01-291-6/+3
| | | | | | | | Do not apply splitting for constant tables.
* | Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3Alexander Barkov2018-01-291-0/+66
|\ \ | |/
| * MDEV-15107 Add virtual Field::sp_prepare_and_store_item(), make sp_rcontext ↵Alexander Barkov2018-01-291-0/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 remote-tracking branch 'origin/10.2' into bb-10.2-extMonty2018-01-271-0/+2
| |\ | | | | | | | | | | | | Conflicts: sql/table.cc
| | * Fixed memory overrun in create_postjoin_aggr_table()Monty2018-01-261-0/+2
| | |
* | | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-241-1/+9
|\ \ \ | |/ /
| * | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2018-01-231-1/+9
| |\ \ | | |/
| | * MDEV-13352: Server crashes in st_join_table::remove_duplicatesSergei Petrunia2018-01-221-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | join_tab->distinct=true means "Before doing record read with this join_tab, call join_tab->remove_duplicates() to eliminate duplicates". remove_duplicates() assumes that - there is a temporary table $T with rows that are to be de-duplicated - there is a previous join_tab (e.g. with join_tab->fields) which was used to populate the temp.table $T. When the query has "Impossible WHERE" and window function, then the above conditions are not met (but we still might need a window function computation step when the query has implicit grouping). The fix is to not add remove_duplicates step if the select execution is degenerate (and we'll have at most one row in the output anyway).
* | | Merge branch 'github/10.3' into bb-10.3-temporalmariadb-10.3.4Sergei Golubchik2018-01-171-3/+3
|\ \ \
| * \ \ Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-111-3/+3
| |\ \ \ | | |/ /
| | * | Merge 10.2 into bb-10.2-extMarko Mäkelä2018-01-111-3/+3
| | |\ \ | | | |/
| | | * Fix Compile Error while using Flag '-DUSE_ARIA_FOR_TMP_TABLES:BOOL=OFF'Sachin Setiya2018-01-071-3/+3
| | | |
* | | | Revert "MDEV-14786 Server crashes in Item_cond::transform on 2nd execution ↵Sergei Golubchik2018-01-171-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of SP querying from a view [fixes #436]" This reverts commit 7069071d7de774dcf28f73b6a968bcb730a12885 And add a test to show that optimization steps that a) are repeated for every execution b) create new items cannot be done on the statement arena
* | | | MDEV-14816 Assertion `join->best_read < double(1.797...e+308L)` failed in ↵Eugene Kosov2018-01-121-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | bool greedy_search
* | | | System Versioning 1.0 pre8Aleksey Midenkov2018-01-101-260/+56
|\ \ \ \ | |/ / / | | | | | | | | 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
| | | |
| * | | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-041-0/+16
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extMonty2018-01-011-0/+16
| | |\ \ | | | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: cmake/make_dist.cmake.in mysql-test/r/func_json.result mysql-test/r/ps.result mysql-test/t/func_json.test mysql-test/t/ps.test sql/item_cmpfunc.h
| | | * MDEV-13683: crash in Item_window_func::update_used_tablesVicențiu Ciorbaru2017-12-281-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Window definitions are resolved during fix fields. Updating used tables for window functions must be done after all window functions have had a chance to be resolved. There was an additional problem with the implementation: expressions that contained window functions never updated the expression's used tables. To fix both these issues, make sure to call "update_used_tables" on all items that contain window functions after we have passed through all items.
| * | | This is a full cost-based implementation of the optimization that employsIgor Babaev2017-12-301-259/+39
| | | | | | | | | | | | | | | | | | | | splitting technique for equi-joins of materialized derived tables/views/CTEs. (see mdev-13369 and mdev-13389).
* | | | SQL: error messagesSergei Golubchik2018-01-091-16/+3
| | | | | | | | | | | | | | | | | | | | remove unused error messages reword ER_VERS_SYS_FIELD_NOT_HIDDEN->ER_VERS_SYS_FIELD_EXISTS
* | | | SQL: derived, hiding, error messagesSergei Golubchik2018-01-091-68/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many related changes. Note that AS OF condition must always be pushed down to physical tables, it cannot be applied to a derived or a view. Thus: * no versioning for internal temporary tables, they can never store historical data. * remove special versioning code from mysql_derived_prepare and remove ER_VERS_DERIVED_PROHIBITED - derived can have no historical data and cannot be prohibited for system versioning related reasons. * do not expand select list for derived/views with sys vers fields, derived/views can never have historical data. * remove special invisiblity rules for sys vers fields, they are no longer needed after the previous change * remove system_versioning_hide, it lost the meaning after the previous change. * remove ER_VERS_SYSTEM_TIME_CLASH, it's no "clash", the inner AS OF clause always wins. * non-versioned fields in a historical query reword the warning text, downgrade to note, don't replace values with NULLs
* | | | MDEV-14786 Server crashes in Item_cond::transform on 2nd execution of SP ↵Aleksey Midenkov2018-01-011-0/+4
| | | | | | | | | | | | | | | | querying from a view [fixes #436]
* | | | MDEV-14751 Server crashes in TABLE::versioned on 2nd execution of SP [fixes ↵Aleksey Midenkov2017-12-261-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #431] SQL: TABLE_LIST cleanup on free_tmp_table() May affect non-versioning tests (main suite passed).
* | | | SQL: SP forced invalidate via 0Aleksey Midenkov2017-12-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Invalidate via ULONG_MAX was wrong because sp_cache_flush_obsolete() works incorrectly in this case. Fixes MDEV-14749
* | | | MDEV-14689 Server crashes in find_field_in_tables on 2nd execution of PS ↵Eugene Kosov2017-12-211-6/+18
| | | | | | | | | | | | | | | | | | | | with versioned table and view SQL: wrong usage of Item::transform()
* | | | MDEV-14686 Server crashes in Item_field::used_tables on 2nd call of SP ↵Aleksey Midenkov2017-12-211-43/+9
| | | | | | | | | | | | | | | | [fixes #422]
* | | | MDEV-14676 Redundancy in error codesAleksey Midenkov2017-12-191-2/+2
| | | | | | | | | | | | | | | | ER_VERS_NOT_VERSIONED vs ER_VERSIONING_REQUIRED
* | | | SQL: removed VERS_HIDDEN_FLAG [closes #409]Aleksey Midenkov2017-12-191-3/+8
| | | |
* | | | Timestamp-based versioning for InnoDB [closes #209]Aleksey Midenkov2017-12-181-35/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Removed integer_fields check * Reworked Vers_parse_info::check_sys_fields() * Misc renames * versioned as vers_sys_type_t * Removed versioned_by_sql(), versioned_by_engine() versioned() works as before; versioned(VERS_TIMESTAMP) is versioned_by_sql(); versioned(VERS_TRX_ID) is versioned_by_engine(). * create_tmp_table() fix * Foreign constraints for timestamp-based * Range auto-specifier fix * SQL: 1-row partition rotation fix [fixes #260] * Fix 'drop system versioning, algorithm=inplace'
* | | | System Versioning 1.0 pre6Aleksey Midenkov2017-12-151-0/+21
|\ \ \ \ | | | | | | | | | | | | | | | Merge remote-tracking branch 'mariadb/bb-10.3-temporal-serg' into trunk
| * | | | if a table is partitioned by system_time, its partitions are not versionedSergei Golubchik2017-12-131-0/+21
| | | | | | | | | | | | | | | | | | | | they store history and the history does not have history
* | | | | System Versioning 1.0 pre5 [closes #407]Aleksey Midenkov2017-12-151-3/+3
|\ \ \ \ \ | | |/ / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Merge branch '10.3' into trunk Both field_visibility and VERS_HIDDEN_FLAG exist independently. TODO: VERS_HIDDEN_FLAG should be replaced with SYSTEM_INVISIBLE (or COMPLETELY_INVISIBLE?).
* | | | | SQL: unit resolution Item_field not yet accessible [fixes #398]Aleksey Midenkov2017-12-141-0/+4
| | | | |
* | | | | MDEV-14645: AS OF TIMESTAMP is misused as TRX_ID [fixes #396]Aleksey Midenkov2017-12-141-0/+42
| | | | |
* | | | | SQL: inner/outer system_time consistency [fixes #384]Aleksey Midenkov2017-12-141-19/+25
| | | | |
* | | | | SQL: VIEW system fields propagation removed [fixes #393]Aleksey Midenkov2017-12-131-28/+13
| | | | |
* | | | | SQL: recursive CTE inner derived vers_conditions [fix #385]Aleksey Midenkov2017-12-131-8/+16
| | | | |
* | | | | Cleanup: unwrapped large block in vers_setup_conds()Aleksey Midenkov2017-12-131-162/+162
| | | | |
* | | | | MDEV-14631 Assertion `!sys_trx_start && !sys_trx_end' failed in crete_tmp_tableEugene Kosov2017-12-121-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SQL: remove unneeded assertion SQL: disallow set sys_trx fields in INSERT ... SELECT Fixes by @midenok.
* | | | | SQL: create..select revisited [closes #370]Aleksey Midenkov2017-12-121-1/+3
| | | | |
* | | | | SQL: RIGHT JOIN in derived [fix #383]Aleksey Midenkov2017-12-121-14/+25
| |/ / / |/| | |
* | | | System Versioning 1.0 pre3Aleksey Midenkov2017-12-111-9/+43
|\ \ \ \ | |/ / / | | | | | | | | Merge branch '10.3' into trunk
| * | | Add direct join support for SpiderMonty2017-12-031-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Includes Spider patches - 062_mariadb-10.2.0.direct_join_1and3.diff - 063_mariadb-10.2.0.direct_join_for_single_partition.diff - Test cases from Kentoku Allows Spider to push full joins to the Spider engine trough the create_group_by interface. Other things: - Increased MYSQL_VERSION_ID to check for 10211 (latest 10.2 version) - Fix for const_table at calling create_group_by(). Original author: Kentoku SHIBA
| * | | Adding Full Text Search support to partitionsMonty2017-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Contains Spiral patches: 007_mariadb-10.2.0.partition_fulltext.diff MDEV-7705 038_mariadb-10.2.0.partition_fulltext2.diff MDEV-7734 This commit has the following differences compared to the original patches: - Added necessary full text search cleanup at the storage engine layer that was omitted in the original patch. - Added test case. - A lot of code cleanups to make the code notable smaller. - Changed SQL code to use ha_ft_end() instead of ft_end() Original author: Kentoku SHIBA First reviewer: Jacob Mathew Second reviewer: Michael Widenius