summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
Commit message (Collapse)AuthorAgeFilesLines
* Derived tables and union can now create distinct keysMonty2022-07-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | The idea is that instead of marking all select_lex's with DISTINCT, we only mark those that really need distinct result. Benefits of this change: - Temporary tables used with derived tables, UNION, IN are now smaller as duplicates are removed already on the insert phase. - The optimizer can now produce better plans with EQ_REF. This can be seen from the tests where several queries does not anymore materialize derived tables twice. - Queries affected by 'in_predicate_conversion_threshold' where large IN lists are converted to sub query produces better plans. Other things: - Removed on duplicate call to sel->init_select() in LEX::add_primary_to_query_expression_body() - I moved the testing of tab->table->pos_in_table_list->is_materialized_derived() in join_read_const_table() to the caller as it caused problems for derived tables that could be proven to be const tables. This also is likely to fix some bugs as if join_read_const_table() was aborted, the table was left marked as JT_CONST, which cannot be good. I added an ASSERT there for now that can be removed when the code has been properly tested.
* Optimizer code cleanups, no logic changesMonty2022-07-071-5/+6
| | | | | | | | | | | | | - Updated comments - Added some extra DEBUG - Indentation changes and break long lines - Trivial code changes like: - Combining 2 statements in one - Reorder DBUG lines - Use a variable to store a pointer that is used multiple times - Moved declaration of variables to start of loop/function - Removed dead or commented code - Removed wrong DBUG_EXECUTE code in best_extension_by_limited_search()
* Merge 10.6 into 10.7Marko Mäkelä2022-07-011-2/+0
|\
| * Merge 10.5 into 10.6Marko Mäkelä2022-07-011-2/+0
| |\
| | * Merge 10.4 into 10.5Marko Mäkelä2022-07-011-2/+0
| | |\
| | | * Merge 10.3 into 10.4Marko Mäkelä2022-07-011-2/+0
| | | |\
| | | | * Fix most clang-15 -Wunused-but-set-variableMarko Mäkelä2022-07-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, refactor trx_i_s_common_fill_table() to remove dead code. Warnings about yynerrs in Bison-generated yyparse() will remain for now.
* | | | | Merge branch '10.6' into 10.7mariadb-10.7.4Sergei Golubchik2022-05-181-1/+1
|\ \ \ \ \ | |/ / / /
| * | | | Merge branch '10.5' into 10.6mariadb-10.6.8Sergei Golubchik2022-05-181-1/+1
| |\ \ \ \ | | |/ / /
| | * | | Merge branch '10.4' into 10.5mariadb-10.5.16Sergei Golubchik2022-05-181-1/+1
| | |\ \ \ | | | |/ /
| | | * | Merge branch '10.3' into 10.4mariadb-10.4.25Sergei Golubchik2022-05-181-1/+1
| | | |\ \ | | | | |/
| | | | * MDEV-28588 SIGSEGV in __memmove_avx_unaligned_erms, strmake_rootAlexander Barkov2022-05-171-1/+1
| | | | |
* | | | | Merge branch '10.6' into 10.7Sergei Golubchik2022-05-111-10/+17
|\ \ \ \ \ | |/ / / /
| * | | | Merge branch '10.5' into 10.6Sergei Golubchik2022-05-101-10/+17
| |\ \ \ \ | | |/ / /
| | * | | Merge branch '10.4' into 10.5Sergei Golubchik2022-05-091-10/+17
| | |\ \ \ | | | |/ /
| | | * | Merge branch '10.3' into 10.4Sergei Golubchik2022-05-081-11/+17
| | | |\ \ | | | | |/
| | | | * Merge branch '10.2' into 10.3Sergei Golubchik2022-05-071-10/+17
| | | | |\
| | | | | * MDEV-28437: Assertion `!eliminated' failed: Part #2Sergei Petrunia2022-05-051-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In SELECT_LEX::update_used_tables(), do not run the loop setting tl->table->maybe_null when tl is an eliminated table (Rationale: First, with current table elimination, tl already has maybe_null=1. Second, one should not care what flags eliminated tables had)
| | | | | * MDEV-28437: Assertion `!eliminated' failed in Item_subselect::execSergei Petrunia2022-05-051-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (This is the assert that was added in fix for MDEV-26047) Table elimination may remove an ON expression from an outer join. However SELECT_LEX::update_used_tables() will still call item->walk(&Item::eval_not_null_tables) for eliminated expressions. If the subquery is constant and cheap Item_cond_and will attempt to evaluate it, which will trigger an assert. The fix is not to call update_used_tables() or eval_not_null_tables() for ON expressions that were eliminated.
| | | | * | Merge branch '10.2' into 10.3Sergei Golubchik2022-04-211-1/+0
| | | | |\ \ | | | | | |/
| | | | | * vcols: cannot use CONTEXT_ANALYSIS_ONLY_VCOL_EXPR on fix_fieldsSergei Golubchik2022-04-191-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | because CONTEXT_ANALYSIS_ONLY_VCOL_EXPR can be used only for, exactly, context analysys. Items fixed that way cannot be evaluated. But vcols are going to be evaluated, so they have to be fixed properly, for evaluation.
| | | * | | MDEV-26412 Server crash in Item_field::fix_outer_field for INSERT SELECTIgor Babaev2022-04-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | IF an INSERT/REPLACE SELECT statement contained an ON expression in the top level select and this expression used a subquery with a column reference that could not be resolved then an attempt to resolve this reference as an outer reference caused a crash of the server. This happened because the outer context field in the Name_resolution_context structure was not set to NULL for such references. Rather it pointed to the first element in the select_stack. Note that starting from 10.4 we cannot use the SELECT_LEX::outer_select() method when parsing a SELECT construct. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | | | | Merge 10.6 into 10.7Marko Mäkelä2022-04-061-3/+3
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge 10.5 into 10.6Marko Mäkelä2022-04-061-3/+3
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge 10.4 into 10.5Marko Mäkelä2022-04-061-3/+3
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge 10.3 into 10.4Marko Mäkelä2022-04-061-3/+3
| | | |\ \ \ | | | | |/ /
| | | | * | MDEV-28224 error: cannot initialize return object of type 'bool' with an ↵Alexander Barkov2022-04-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rvalue of type 'nullptr_t' Fixing a typo in the fix for MDEV-19804, wrong return value in a bool function: < return NULL; > return true; The problem was found because it did not compile on some platforms. Strangley, it did not have visible problems on other platforms, which did not fail to compile, although "return NULL" should compile to "return false" rather than "return true".
* | | | | | Merge 10.6 into 10.7Marko Mäkelä2022-03-301-0/+87
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge 10.5 into 10.6Marko Mäkelä2022-03-291-0/+87
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge 10.4 into 10.5Marko Mäkelä2022-03-291-1/+88
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge 10.3 into 10.4Marko Mäkelä2022-03-291-0/+84
| | | |\ \ \ | | | | |/ /
| | | | * | MDEV-19804 sql_mode=ORACLE: call procedure in packagesAlexander Barkov2022-03-251-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adding support for the fully qualified package procedure calls: BEGIN CALL db.pkg.proc(args); -- SQL/PSM call style db.pkg.proc(args); -- PL/SQL call style END;
| | | | * | MDEV-28166 sql_mode=ORACLE: fully qualified package function calls do not ↵Alexander Barkov2022-03-251-0/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | work: db.pkg.func() Also fixes MDEV-19328 sql_mode=ORACLE: Package function in VIEW
* | | | | | Merge 10.6 into 10.7Marko Mäkelä2022-03-111-1/+8
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge 10.5 into 10.6Marko Mäkelä2022-03-111-1/+8
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge 10.4 into 10.5Marko Mäkelä2022-03-111-1/+8
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge 10.3 into 10.4Marko Mäkelä2022-03-111-1/+8
| | | |\ \ \ | | | | |/ /
| | | | * | MDEV-19577 Replication does not work with innodb_autoinc_lock_mode=2Vlad Lesin2022-03-101-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first step for deprecating innodb_autoinc_lock_mode(see MDEV-27844) is: - to switch statement binlog format to ROW if binlog format is MIXED and the statement changes autoincremented fields - issue warnings if innodb_autoinc_lock_mode == 2 and binlog format is STATEMENT
* | | | | | Merge branch '10.6' into 10.7mariadb-10.7.3Sergei Golubchik2022-02-101-1/+15
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge branch '10.5 into 10.6mariadb-10.6.7Sergei Golubchik2022-02-101-1/+15
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge branch '10.4' into 10.5mariadb-10.5.15Sergei Golubchik2022-02-101-1/+15
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge branch '10.3' into 10.4mariadb-10.4.24Sergei Golubchik2022-02-101-1/+15
| | | |\ \ \ | | | | |/ /
| | | | * | Merge branch '10.2' into 10.3mariadb-10.3.34Sergei Golubchik2022-02-101-1/+15
| | | | |\ \ | | | | | |/
| | | | | * MDEV-25636: Bug report: abortion in sql/sql_parse.cc:6294mariadb-10.2.43bb-10.2-compatibilitySergei Petrunia2022-02-101-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The asserion failure was caused by this query select /*id=1*/ from t1 where col= ( select /*id=2*/ from ... where corr_cond1 union select /*id=4*/ from ... where corr_cond2) Here, - select with id=2 was correlated due to corr_cond1. - select with id=4 was initially correlated due to corr_cond2, but then the optimizer optimized away the correlation, making the select with id=4 uncorrelated. However, since select with id=2 remained correlated, the execution had to re-compute the whole UNION. When it tried to execute select with id=4, it hit an assertion (join buffer already free'd). This is because select with id=4 has freed its execution structures after it has been executed once. The select is uncorrelated, so it did not expect it would need to be executed for the second time. Fixed this by adding this logic in st_select_lex::optimize_unflattened_subqueries(): If a member of a UNION is correlated, mark all its members as correlated, so that they are prepared to be executed multiple times.
* | | | | | Merge branch '10.6' into 10.7Oleksandr Byelkin2022-02-041-3/+4
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge branch '10.5' into 10.6Oleksandr Byelkin2022-02-031-3/+4
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge branch '10.4' into 10.5Oleksandr Byelkin2022-02-011-3/+4
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge branch '10.3' into 10.4Oleksandr Byelkin2022-01-301-3/+4
| | | |\ \ \ | | | | |/ /
| | | | * | Merge branch '10.2' into 10.3mariadb-10.3.33Oleksandr Byelkin2022-01-291-3/+4
| | | | |\ \ | | | | | |/
| | | | | * MDEV-25460: Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())'Rucha Deodhar2021-12-281-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | failed in Diagnostics_area::set_ok_status in my_ok from mysql_sql_stmt_prepare Analysis: Before PREPARE is executed, binlog_format is STATEMENT. This PREPARE had SET STATEMENT which sets binlog_format to ROW. Now after PREPARE is done we reset the binlog_format (back to STATEMENT). But we have temporary table, it doesn't let changing binlog_format=ROW to binlog_format=STATEMENT and gives error which goes unreported. This unreported error eventually causes assertion failure. Fix: Change return type for LEX::restore_set_statement_var() to bool and make it return error state.