summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.11 into 11.0Sergei Petrunia2023-04-171-0/+2
|\
| * Merge 10.10 into 10.11Marko Mäkelä2023-04-141-0/+2
| |\
| | * Merge 10.9 into 10.10Marko Mäkelä2023-04-141-0/+2
| | |\
| | | * Merge 10.8 into 10.9Marko Mäkelä2023-04-141-0/+2
| | | |\
| | | | * Merge 10.6 into 10.8Marko Mäkelä2023-04-121-0/+2
| | | | |\
| | | | | * Merge 10.5 into 10.6Marko Mäkelä2023-04-111-0/+2
| | | | | |\
| | | | | | * Merge remote-tracking branch '10.4' into 10.5Oleksandr Byelkin2023-03-311-0/+2
| | | | | | |\
| | | | | | | * MDEV-30539 EXPLAIN EXTENDED: no message with queries for DML statementsIgor Babaev2023-03-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | EXPLAIN EXTENDED for an UPDATE/DELETE/INSERT/REPLACE statement did not produce the warning containing the text representation of the query obtained after the optimization phase. Such warning was produced for SELECT statements, but not for DML statements. The patch fixes this defect of EXPLAIN EXTENDED for DML statements.
| | | | | | | * MDEV-19190 Assertion `...auto_inc_initialized` failed in get_auto_incrementlrf1412022-11-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a DELETE only case. Normally this statement doesn't make inserts, but DELETE ... FOR PORTION changes it. UPDATE and INSERT initializes autoinc by calling handler::info(HA_STATUS_AUTO). Also myisam and innodb can lazily initialize it in their update_create_info overrides. The solution is to initialize autoinc during delete preparation, if period (DELETE FOR PORTION) is specified. The initial work has been done by Kento Takeuchi by his PR #2048, however this commit also holds a few technical modifications by Nikita Malyavin
* | | | | | | | Merge 10.11 into 11.0Marko Mäkelä2023-03-291-1/+1
|\ \ \ \ \ \ \ \ | |/ / / / / / /
| * | | | | | | Fix trivial spelling errorsOtto Kekalainen2023-03-241-1/+1
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - agressively -> aggressively - exising -> existing - occured -> occurred - releated -> related - seperated -> separated - sucess -> success - use use -> use All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
* | | | | | | MDEV-30256 Wrong result (missing rows) upon join with empty tableMonty2023-02-101-1/+3
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was an assignment in test_quick_select() that flagged empty tables with "Impossible where". This test was however wrong as it didn't work correctly for left join. Removed the test, but added checking of empty tables in DELETE and UPDATE to get similar EXPLAIN as before. The new tests is a bit more strict (better) than before as it catches all cases of empty tables in single table DELETE/UPDATE.
* | | | | | Merge 10.9 into 10.10Marko Mäkelä2022-12-071-0/+4
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge 10.8 into 10.9Marko Mäkelä2022-12-071-0/+4
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge 10.6 into 10.7Marko Mäkelä2022-12-071-0/+4
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge 10.5 into 10.6Marko Mäkelä2022-12-051-0/+4
| | | |\ \ \ | | | | |/ /
| | | | * | Merge 10.4 into 10.5Jan Lindström2022-11-301-0/+4
| | | | | |
| * | | | | Merge branch '10.8' into 10.9Oleksandr Byelkin2022-08-091-1/+3
| |\ \ \ \ \ | | |/ / / /
* | | | | | cleanup: consolidate binlog-related THD::*_used into one bitmapSergei Golubchik2022-08-101-1/+1
| | | | | |
* | | | | | Merge branch '10.8' into 10.9Oleksandr Byelkin2022-08-081-1/+3
|\ \ \ \ \ \ | |/ / / / / |/| / / / / | |/ / / /
| * | | | Merge branch '10.6' into 10.7Oleksandr Byelkin2022-08-081-1/+3
| |\ \ \ \ | | |/ / /
| | * | | Merge branch '10.5' into 10.6Oleksandr Byelkin2022-08-041-1/+3
| | |\ \ \ | | | |/ /
| | | * | Merge branch '10.4' into 10.5Oleksandr Byelkin2022-08-041-1/+3
| | | |\ \ | | | | |/
| | | | * Merge branch '10.3' into 10.4Oleksandr Byelkin2022-08-031-1/+3
| | | | |\
| | | | | * MDEV-27282 InnoDB: Failing assertion: !query->intersectionThirunarayanan Balathandayuthapani2022-08-031-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - query->intersection fails to get freed if the query exceeds innodb_ft_result_cache_limit - errors from init_ftfuncs were not propogated by delete command This is taken from percona/percona-server@ef2c0bcb9a34aeb06de0058d7c2a2969416b35a7
* | | | | | MDEV-25477 Auto-create breaks replication when triggering event was not ↵Aleksey Midenkov2022-05-061-6/+18
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | replicated If UPDATE/DELETE does not change data it is skipped from replication. We now force replication of such events when they trigger partition auto-creation. For ROLLBACK it is as simple as set OPTION_KEEP_LOG flag. trans_cannot_safely_rollback() does the rest. For UPDATE/DELETE .. LIMIT 0 we make additional binlog_query() calls at the early points of return. As a safety measure we also convert row format into statement if it is needed. The condition is decided by binlog_need_stmt_format(). Basically if there are some row events in cache we don't need that: table open of row event will trigger auto-creation anyway. Multi-update/delete works via mysql_select(). There is no early points of return, so binlogging is always checked by send_eof()/abort_resultset(). But we must comply with the above measure of converting into statement.
* | | | | Merge 10.6 into 10.7Marko Mäkelä2022-03-151-3/+4
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.5 into 10.6Marko Mäkelä2022-03-151-3/+4
| |\ \ \ \ | | |/ / /
| | * | | Merge 10.4 into 10.5Marko Mäkelä2022-03-151-3/+4
| | |\ \ \ | | | |/ /
| | | * | Merge 10.3 into 10.4Marko Mäkelä2022-03-151-2/+3
| | | |\ \ | | | | |/
| | | | * MDEV-18304 sql_safe_updates does not work with OR clausesSergei Golubchik2022-03-121-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | not every index-using plan sets bits in table->quick_keys. QUICK_ROR_INTERSECT_SELECT, for example, doesn't. Use the fact that select->quick is set instead. Also allow EXPLAIN to work.
* | | | | MDEV-26844: DELETE returns ROW_NUMBER=1 for every row uponbb-10.7-row_numberRucha Deodhar2021-10-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ER_TRUNCATED_WRONG_VALUE Part 1: Fix for DELETE without ORDER BY Analysis: m_current_row_for_warning doesn't increment and assumes default value which is then used by ROW_NUMBER. Fix: Increment m_current_row_for_warning for each processed row.
* | | | | MDEV-26635 ROW_NUMBER is not 0 for errors not caused because of rowsSergei Golubchik2021-10-261-0/+2
|/ / / /
* | | | Merge 10.5 into 10.6Marko Mäkelä2021-09-241-3/+7
|\ \ \ \ | |/ / /
| * | | Merge 10.4 into 10.5Marko Mäkelä2021-09-241-3/+7
| |\ \ \ | | |/ /
| | * | Merge 10.3 into 10.4Marko Mäkelä2021-09-221-3/+7
| | |\ \ | | | |/
| | | * MDEV-26545 Spider does not correctly handle UDF and stored function in where ↵Daniel Ye2021-09-221-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | conds - Handle stored function conditions correctly, with the same logic as with UDFs. - When running queries on Spider SE, by default, we do not push down WHERE conditions containing usage of UDFs/stored functions to remote data nodes, unless the user demands (by setting spider_use_pushdown_udf). - Disable direct update/delete when a udf condition is skipped.
* | | | merge 10.5 to 10.6Vladislav Vaintroub2021-07-161-1/+6
|\ \ \ \ | |/ / /
| * | | MDEV-21916: COM_STMT_BULK_EXECUTE with RETURNING insert wrong valuesOleksandr Byelkin2021-07-151-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem is that array binding uses net buffer to read parameters for each execution while each execiting with RETURNING write in the same buffer. Solution is to allocate new net buffer to avoid changing buffer we are reading from.
* | | | MDEV-25576: The statement EXPLAIN running as regular statement and as ↵Dmitry Shulga2021-06-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | prepared statement produces different results for UPDATE with subquery 10.6 cleanup
* | | | Merge 10.5 into 10.6Marko Mäkelä2021-06-011-0/+2
|\ \ \ \ | |/ / /
| * | | Merge 10.4 into 10.5Marko Mäkelä2021-06-011-0/+2
| |\ \ \ | | |/ /
| | * | Merge 10.3 into 10.4Marko Mäkelä2021-06-011-0/+2
| | |\ \ | | | |/
| | | * Merge 10.2 into 10.3Marko Mäkelä2021-06-011-0/+2
| | | |\
| | | | * MDEV-25576: The statement EXPLAIN running as regular statement and as ↵Dmitry Shulga2021-05-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | prepared statement produces different results for UPDATE with subquery Both EXPLAIN and EXPLAIN EXTENDED statements produce different results set in case it is run in normal way and in PS mode for the statements UPDATE/DELETE with subquery. The use case below reproduces the issue: MariaDB [test]> CREATE TABLE t1 (c1 INT KEY) ENGINE=MyISAM; Query OK, 0 rows affected (0,128 sec) MariaDB [test]> CREATE TABLE t2 (c2 INT) ENGINE=MyISAM; Query OK, 0 rows affected (0,023 sec) MariaDB [test]> CREATE TABLE t3 (c3 INT) ENGINE=MyISAM; Query OK, 0 rows affected (0,021 sec) MariaDB [test]> EXPLAIN EXTENDED UPDATE t3 SET c3 = -> ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 -> STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 -> ON a12.c1 = a11.c1 ) d1 ); +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ | 1 | PRIMARY | t3 | ALL | NULL | NULL | NULL | NULL | 0 | 100.00 | | | 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ 2 rows in set (0,002 sec) MariaDB [test]> PREPARE stmt FROM -> EXPLAIN EXTENDED UPDATE t3 SET c3 = -> ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 -> STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 -> ON a12.c1 = a11.c1 ) d1 ); Query OK, 0 rows affected (0,000 sec) Statement prepared MariaDB [test]> EXECUTE stmt; +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ | 1 | PRIMARY | t3 | ALL | NULL | NULL | NULL | NULL | 0 | 100.00 | | | 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | no matching row in const table | +------+-------------+-------+------+---------------+------+---------+------+------+----------+--------------------------------+ 2 rows in set (0,000 sec) The reason by that different result sets are produced is that on execution of the statement 'EXECUTE stmt' the flag SELECT_DESCRIBE not set in the data member SELECT_LEX::options for instances of SELECT_LEX that correspond to subqueries used in the UPDTAE/DELETE statements. Initially, these flags were set on parsing the statement PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET ..." but latter they were reset before starting real execution of the parsed query during handling the statement 'EXECUTE stmt'; So, to fix the issue the functions mysql_update()/mysql_delete() have been modified to set the flag SELECT_DESCRIBE forcibly in the data member SELECT_LEX::options for the primary SELECT_LEX of the UPDATE/DELETE statement.
| | | | * This patch complements the patch for MDEV-24823.Igor Babaev2021-04-231-1/+1
| | | | |
| | | | * MDEV-24823 Crash with invalid multi-table update of view in 2nd execution of SPIgor Babaev2021-04-221-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this patch mergeable derived tables / view used in a multi-table update / delete were merged before the preparation stage. When the merge of a derived table / view is performed the on expression attached to it is fixed and ANDed with the where condition of the select S containing this derived table / view. It happens after the specification of the derived table / view has been merged into S. If the ON expression refers to a non existing field an error is reported and some other mergeable derived tables / views remain unmerged. It's not a problem if the multi-table update / delete statement is standalone. Yet if it is used in a stored procedure the select with incompletely merged derived tables / views may cause a problem for the second call of the procedure. This does not happen for select queries using derived tables / views, because in this case their specifications are merged after the preparation stage at which all ON expressions are fixed. This patch makes sure that merging of the derived tables / views used in a multi-table update / delete statement is performed after the preparation stage. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | | | MDEV-24089 support oracle syntax: rownumMonty2021-05-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ROWNUM() function is for SELECT mapped to JOIN->accepted_rows, which is incremented for each accepted rows. For Filesort, update, insert, delete and load data, we map ROWNUM() to internal variables incremented when the table is changed. The connection between the row counter and Item_func_rownum is done in sql_select.cc::fix_items_after_optimize() and sql_insert.cc::fix_rownum_pointers() When ROWNUM() is used anywhere in query, the optimization to ignore ORDER BY in sub queries are disabled. This was done to get the following common Oracle query to work: select * from (select * from t1 order by a desc) as t where rownum() <= 2; MDEV-3926 "Wrong result with GROUP BY ... WITH ROLLUP" contains a discussion about this topic. LIMIT optimization is enabled when in a top level WHERE clause comparing ROWNUM() with a numerical constant using any of the following expressions: - ROWNUM() < # - ROWNUM() <= # - ROWNUM() = 1 ROWNUM() can be also be the right argument to the comparison function. LIMIT optimization is done in two cases: - For the current sub query when the ROWNUM comparison is done on the top level: SELECT * from t1 WHERE rownum() <= 2 AND t1.a > 0 - For an inner sub query, when the upper level has only a ROWNUM comparison in the WHERE clause: SELECT * from (select * from t1) as t WHERE rownum() <= 2 In Oracle mode, one can also use ROWNUM without parentheses. Other things: - Fixed bug where the optimizer tries to optimize away sub queries with RAND_TABLE_BIT set (non-deterministic queries). Now these sub queries will not be converted to joins. This bug fix was also needed to get rownum() working inside subqueries. - In remove_const() remove setting simple_order to FALSE if ROLLUP is USED. This code was disable a long time ago because of wrong assignment in the following code. Instead we set simple_order to false if RAND_TABLE_BIT was used in the SELECT list. This ensures that we don't delete ORDER BY if the result set is not deterministic, like in 'SELECT RAND() AS 'r' FROM t1 ORDER BY r'; - Updated parameters for Sort_param::init_for_filesort() to be able to provide filesort with information where the number of accepted rows should be stored - Reordered fields in class Filesort to optimize storage layout - Added new error messsage to tell that a function can't be used in HAVING - Added field 'with_rownum' to THD to mark that ROWNUM() is used in the query. Co-author: Oleksandr Byelkin <sanja@mariadb.com> LIMIT optimization for sub query
* | | | | Merge 10.5 into 10.6Marko Mäkelä2021-04-261-11/+8
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.4 into 10.5Marko Mäkelä2021-04-251-11/+8
| |\ \ \ \ | | |/ / /