summaryrefslogtreecommitdiff
path: root/sql/sql_truncate.cc
Commit message (Collapse)AuthorAgeFilesLines
* Aria will now register it's transactionsMonty2020-05-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-22531 Remove maria::implicit_commit() MDEV-22607 Assertion `ha_info->ht() != binlog_hton' failed in MYSQL_BIN_LOG::unlog_xa_prepare From the handler point of view, Aria now looks like a transactional engine. One effect of this is that we don't need to call maria::implicit_commit() anymore. This change also forces the server to call trans_commit_stmt() after doing any read or writes to system tables. This work will also make it easier to later allow users to have system tables in other engines than Aria. To handle the case that Aria doesn't support rollback, a new handlerton flag, HTON_NO_ROLLBACK, was added to engines that has transactions without rollback (for the moment only binlog and Aria). Other things - Moved freeing of MARIA_SHARE to a separate function as the MARIA_SHARE can be still part of a transaction even if the table has closed. - Changed Aria checkpoint to use the new MARIA_SHARE free function. This fixes a possible memory leak when using S3 tables - Changed testing of binlog_hton to instead test for HTON_NO_ROLLBACK - Removed checking of has_transaction_manager() in handler.cc as we can assume that as the transaction was started by the engine, it does support transactions. - Added new class 'start_new_trans' that can be used to start indepdendent sub transactions, for example while reading mysql.proc, using help or status tables etc. - open_system_tables...() and open_proc_table_for_Read() doesn't anymore take a Open_tables_backup list. This is now handled by 'start_new_trans'. - Split thd::has_transactions() to thd::has_transactions() and thd::has_transactions_and_rollback() - Added handlerton code to free cached transactions objects. Needed by InnoDB. squash! 2ed35999f2a2d84f1c786a21ade5db716b6f1bbc
* Yet less TDC hash lookupsSergey Vojtovich2020-04-031-7/+4
| | | | | | | Let auto repair table and truncate table routines flush TABLE_SHARE directly. Part of MDEV-17882 - Cleanup refresh version
* Split tdc_remove_table()Sergey Vojtovich2020-04-031-2/+1
| | | | | | | | | | | | | | TDC_RT_REMOVE_ALL -> tdc_remove_table(). Some occurrences replaced with TDC_element::flush() (whenver TABLE_SHARE is available). TDC_RT_REMOVE_NOT_OWN[_KEEP_SHARE] -> TDC_element::flush(). These modes assume that current thread owns TABLE_SHARE reference, which means we can avoid hash lookup and flush unused TABLE instances directly. TDC_RT_REMOVE_UNUSED -> TDC_element::flush_unused(). Only [ab]used by mysql_admin_table() currently. Should be removed eventually. Part of MDEV-17882 - Cleanup refresh version
* MDEV-20051: Add new mode to wsrep_OSU_method in which Galera checks storage ↵Jan Lindström2020-02-111-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | engine of the effected table Introduced a new wsrep_strict_ddl configuration variable in which Galera checks storage engine of the effected table. If table is not InnoDB (only storage engine currently fully supporting Galera replication) DDL-statement will return error code: ER_GALERA_REPLICATION_NOT_SUPPORTED eng "DDL-statement is forbidden as table storage engine does not support Galera replication" However, when wsrep_replicate_myisam=ON we allow DDL-statements to MyISAM tables. If effected table is allowed storage engine Galera will run normal TOI. This new setting should be for now set globally on all nodes in a cluster. When this setting is set following DDL-clauses accessing tables not supporting Galera replication are refused: * CREATE TABLE (e.g. CREATE TABLE t1(a int) engine=Aria * ALTER TABLE * TRUNCATE TABLE * CREATE VIEW * CREATE TRIGGER * CREATE INDEX * DROP INDEX * RENAME TABLE * DROP TABLE Statements on PROCEDURE, EVENT, FUNCTION are allowed as effected tables are known only at execution. Furthermore, USER, ROLE, SERVER, DATABASE statements are also allowed as they do not really have effected table.
* Removed kill_delayed_threads_for_table()Sergey Vojtovich2019-11-251-1/+1
| | | | | | | | | | After 7fb9d64 it is used only by ALTER/DROP SERVER, which most probably wasn't intentional as Federated never supported delayed inserts anyway. If delayed inserts will ever become an issue with ALTER/DROP SERVER, we should kill them by acquiring X-lock instead. Part of MDEV-17882 - Cleanup refresh version
* Merge branch '10.3' into 10.4Oleksandr Byelkin2019-05-191-10/+6
|\
| * Merge 10.2 into 10.3Marko Mäkelä2019-05-141-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
| * | | Merge branch '10.2' into 10.3Oleksandr Byelkin2019-05-121-9/+5
| |\ \ \ | | |/ /
| | * | Merge branch '5.5' into 10.1Sergei Golubchik2019-04-261-9/+5
| | |\ \ | | | |/
| | | * MDEV-18923 Assertion `!lex_string_cmp(system_charset_info, ↵Sergei Golubchik2019-04-241-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | fk_info->referenced_table, &table->s->table_name)' failed in fk_truncate_illegal_if_parent don't assert the correctness of FK constraints, as it can be broken under `SET FOREIGN_KEY_CHECKS= OFF`
* | | | cleanup: replace a magic constant with a defineSergei Golubchik2019-05-181-1/+1
| | | |
* | | | generalize the error messageSergei Golubchik2019-05-181-1/+1
| | | |
* | | | MDEV-15966 Behavior for TRUNCATE versioned table is not documented and not ↵Sergei Golubchik2019-05-181-22/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | covered by tests * add error for truncation of versioned tables: `ER_TRUNCATE_ILLEGAL_VERS` * make a full table open with `tdc_aquire_share` instead of just `ha_table_exists` check test suites run: main, parts, versioning Closes #785
* | | | Galera4Brave Galera Crew2019-01-231-0/+2
| | | |
* | | | Merge 10.3 into 10.4Marko Mäkelä2018-10-051-1/+3
|\ \ \ \ | |/ / /
| * | | MDEV-17167 - InnoDB: Failing assertion: table->get_ref_count() == 0 uponmariadb-10.3.10Sergey Vojtovich2018-10-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | truncating a temporary table TRUNCATE expects only one TABLE instance (which is used by TRUNCATE itself) to be open. However this requirement wasn't enforced after "MDEV-5535: Cannot reopen temporary table". Fixed by closing unused table instances before performing TRUNCATE.
| * | | Merge branch '10.2' into 10.3Sergei Golubchik2018-09-281-1/+1
| |\ \ \ | | |/ /
| | * | MDEV-15890 Strange error message if you try to FLUSH TABLES <view> after ↵Alexey Botchkov2018-09-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | LOCK TABLES <view>. Check if the argument of the FLUSH TABLE is a VIEW and handle it accordingly.
* | | | Merge 10.3 into 10.4Marko Mäkelä2018-08-161-1/+2
|\ \ \ \ | |/ / /
| * | | Merge 10.2 into 10.3Marko Mäkelä2018-08-031-1/+2
| |\ \ \ | | |/ /
| | * | Merge branch '10.0' into bb-10.1-merge-sanjaOleksandr Byelkin2018-07-251-1/+2
| | |\ \
| | | * | MDEV-15551 Server hangs or assertion ↵Sergei Golubchik2018-07-191-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `strcmp(share->unique_file_name,filename) || share->last_version' fails in test_if_reopen or unexpected ER_LOCK_DEADLOCK only use HA_EXTRA_PREPARE_FOR_DROP when the table is going to be dropped
* | | | | MDEV-11953: support of brackets in UNION/EXCEPT/INTERSECT operationsOleksandr Byelkin2018-07-041-1/+1
|/ / / /
* | | | MDEV-15970 Crash when doing truncate on locked sequenceMichael Widenius2018-05-141-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem was that we used table->s->db_type() for accessing handlerton of opened file instead of table->file->ht Other bug fixed: - Ensure that we set error if reopen_tables() fails (This was the cause of assert)
* | | | Add likely/unlikely to speed up executionMonty2018-05-071-3/+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()
* | | | Merge 10.2 into 10.3Marko Mäkelä2018-04-241-3/+2
|\ \ \ \ | |/ / /
| * | | Merge 10.0 into 10.1Marko Mäkelä2018-04-241-3/+2
| |\ \ \ | | |/ /
| | * | Merge branch '5.5' into 10.0Sergei Golubchik2018-04-201-2/+1
| | |\ \ | | | |/
| | | * Merge branch 'mysql/5.5' into 5.5Sergei Golubchik2018-04-191-1/+2
| | | |\
| | | | * BUG#27216817: INNODB: FAILING ASSERTION:mysql-5.5.60Nisha Gopalakrishnan2018-02-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PREBUILT->TABLE->N_MYSQL_HANDLES_OPENED == 1 ANALYSIS: ========= Adding unique index to a InnoDB table which is locked as mutliple instances may trigger an InnoDB assert. When we add a primary key or an unique index, we need to drop the original table and rebuild all indexes. InnoDB expects that only the instance of the table that is being rebuilt, is open during the process. In the current scenario we have opened multiple instances of the table. This triggers an assert during table rebuild. 'Locked_tables_list' encapsulates a list of all instances of tables locked by LOCK TABLES statement. FIX: === We are now temporarily closing all the instances of the table except the one which is being altered and later reopen them via Locked_tables_list::reopen_tables().
| | * | | MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under ↵Sergei Golubchik2018-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | LOCK TABLE after ER_SAME_NAME_PARTITION ALTER TABLE ... ADD PARTITION modifies the open TABLE structure, and sets table->need_reopen=1 to reset these modifications in case of an error. But under LOCK TABLES the table isn't get reopened, despite need_reopen. Fixed by reopening need_reopen tables under LOCK TABLE.
* | | | | Changed database, tablename and alias to be LEX_CSTRINGMonty2018-01-301-19/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 "")
* | | | | s/TRUNCATE ... TO/DELETE HISTORY FROM ... BEFORE/Sergei Golubchik2017-12-191-7/+0
| | | | |
* | | | | privilege: s/delete versioning rows/delete history/Sergei Golubchik2017-12-141-1/+1
| | | | |
* | | | | System Versioning pre0.12Aleksey Midenkov2017-11-071-5/+12
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Merge remote-tracking branch 'origin/archive/2017-10-17' into 10.3
| * | | | | SQL: truncate syntax and privilege [closes #229]Eugene Kosov2017-09-081-1/+4
| | | | | |
| * | | | | SQL, Parser: system_time logic and syntax fixes [closes #237]Aleksey Midenkov2017-08-081-7/+6
| | | | | |
| * | | | | 0.6: truncate history feature [closes #96]kevg2017-05-051-2/+7
| | | | | |
* | | | | | Optimize LEX_STRING comparisonsMichael Widenius2017-08-241-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added inline lex_string_cmp() to replace my_strcase_cmp(). - Added inline lex_string_eq to first compares lengths before comparing strings
* | | | | | Enusure that my_global.h is included firstMichael Widenius2017-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added sql/mariadb.h file that should be included first by files in sql directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables that must be done before my_global.h is included) - Removed a lot of include my_global.h from include files - Removed include's of some files that my_global.h automatically includes - Removed duplicated include's of my_sys.h - Replaced include my_config.h with my_global.h
* | | | | | Changing field::field_name and Item::name to LEX_CSTRINGMonty2017-04-231-3/+3
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benefits of this patch: - Removed a lot of calls to strlen(), especially for field_string - Strings generated by parser are now const strings, less chance of accidently changing a string - Removed a lot of calls with LEX_STRING as parameter (changed to pointer) - More uniform code - Item::name_length was not kept up to date. Now fixed - Several bugs found and fixed (Access to null pointers, access of freed memory, wrong arguments to printf like functions) - Removed a lot of casts from (const char*) to (char*) Changes: - This caused some ABI changes - lex_string_set now uses LEX_CSTRING - Some fucntions are now taking const char* instead of char* - Create_field::change and after changed to LEX_CSTRING - handler::connect_string, comment and engine_name() changed to LEX_CSTRING - Checked printf() related calls to find bugs. Found and fixed several errors in old code. - A lot of changes from LEX_STRING to LEX_CSTRING, especially related to parsing and events. - Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING* - Some changes for char* to const char* - Added printf argument checking for my_snprintf() - Introduced null_clex_str, star_clex_string, temp_lex_str to simplify code - Added item_empty_name and item_used_name to be able to distingush between items that was given an empty name and items that was not given a name This is used in sql_yacc.yy to know when to give an item a name. - select table_name."*' is not anymore same as table_name.* - removed not used function Item::rename() - Added comparision of item->name_length before some calls to my_strcasecmp() to speed up comparison - Moved Item_sp_variable::make_field() from item.h to item.cc - Some minimal code changes to avoid copying to const char * - Fixed wrong error message in wsrep_mysql_parse() - Fixed wrong code in find_field_in_natural_join() where real_item() was set when it shouldn't - ER_ERROR_ON_RENAME was used with extra arguments. - Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already give the error. TODO: - Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c - Change code to not modify LEX_CSTRING for database name (as part of lower_case_table_names)
* | | | | MDEV-10139 Support for SEQUENCE objectsMonty2017-04-071-6/+9
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Working features: CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name [ INCREMENT [ BY | = ] increment ] [ MINVALUE [=] minvalue | NO MINVALUE ] [ MAXVALUE [=] maxvalue | NO MAXVALUE ] [ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ] ENGINE=xxx COMMENT=".." SELECT NEXT VALUE FOR sequence_name; SELECT NEXTVAL(sequence_name); SELECT PREVIOUS VALUE FOR sequence_name; SELECT LASTVAL(sequence_name); SHOW CREATE SEQUENCE sequence_name; SHOW CREATE TABLE sequence_name; CREATE TABLE sequence-structure ... SEQUENCE=1 ALTER TABLE sequence RENAME TO sequence2; RENAME TABLE sequence TO sequence2; DROP [TEMPORARY] SEQUENCE [IF EXISTS] sequence_names Missing features - SETVAL(value,sequence_name), to be used with replication. - Check replication, including checking that sequence tables are marked not transactional. - Check that a commit happens for NEXT VALUE that changes table data (may already work) - ALTER SEQUENCE. ANSI SQL version of setval. - Share identical sequence entries to not add things twice to table list. - testing insert/delete/update/truncate/load data - Run and fix Alibaba sequence tests (part of mysql-test/suite/sql_sequence) - Write documentation for NEXT VALUE / PREVIOUS_VALUE - NEXTVAL in DEFAULT - Ensure that NEXTVAL in DEFAULT uses database from base table - Two NEXTVAL for same row should give same answer. - Oracle syntax sequence_table.nextval, without any FOR or FROM. - Sequence tables are treated as 'not read constant tables' by SELECT; Would be better if we would have a separate list for sequence tables so that select doesn't know about them, except if refereed to with FROM. Other things done: - Improved output for safemalloc backtrack - frm_type_enum changed to Table_type - Removed lex->is_view and replaced with lex->table_type. This allows use to more easy check if item is view, sequence or table. - Added table flag HA_CAN_TABLES_WITHOUT_ROLLBACK, needed for handlers that want's to support sequences - Added handler calls: - engine_name(), to simplify getting engine name for partition and sequences - update_first_row(), to be able to do efficient sequence implementations. - Made binlog_log_row() global to be able to call it from ha_sequence.cc - Added handler variable: row_already_logged, to be able to flag that the changed row is already logging to replication log. - Added CF_DB_CHANGE and CF_SCHEMA_CHANGE flags to simplify deny_updates_if_read_only_option() - Added sp_add_cfetch() to avoid new conflicts in sql_yacc.yy - Moved code for add_table_options() out from sql_show.cc::show_create_table() - Added String::append_longlong() and used it in sql_show.cc to simplify code. - Added extra option to dd_frm_type() and ha_table_exists to indicate if the table is a sequence. Needed by DROP SQUENCE to not drop a table.
* | | | Merge tag 'mariadb-10.0.19' into 10.1Sergei Golubchik2015-06-011-2/+2
|\ \ \ \ | |/ / /
| * | | Merge branch '5.5' into 10.0Sergei Golubchik2015-05-041-2/+8
| |\ \ \ | | |/ /
| | * | Merge remote-tracking branch 'mysql/5.5' into 5.5Sergei Golubchik2015-04-271-1/+7
| | |\ \ | | | |/
| | | * Bug#19786309 - CRASH IN UNLOCK TABLES AFTER LOCKING AND TRUNCATING ↵Praveenkumar.Hulakund2015-01-141-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TEMPORARY TABLE. Attempt to truncate temporary table using Blackhole storage and locked by LOCK TABLES caused assertion failure and crashes. Blackhole is a transaction-aware engine. While creating the temporary table in transaction-aware engine, temporary table of type "TRANSACTIONAL_TMP_TABLE" is created. For such temporary tables a THR_LOCK lock is acquired by the LOCK TABLE operation. References to them are also added into MYSQL_LOCK::table[] array. Also for Blackhole engine, flag HTON_CAN_RECREATE is set. While truncating temporary tables, no locks are taken and recreate_temporary_table() is called for engines having "HTON_CAN_RECREATE" in flag. Function closefrm() is called from the recreate_temporary_table(), to close the current temporary table. In closefrm(), the lock on table expected is "F_UNLCK". In debug builds, assert condition on this fails when lock of type "F_WRLCK" is acquired by LOCK TABLE operation on temporary tables using Blackhole engine. In non-debug builds closefrm() simply freed TABLE object leaving dangling pointer to this object in MYSQL_LOCK::table[] array which might lead to crashes later. Fix: --------- To fix this issue, we now unlock and remove table from MYSQL_LOCK::table[] array before calling close_temporary_table() in recreate_temporary_table(). This is achieved by calling mysql_lock_remove() function for this table.
| | | * Bug#17942050:KILL OF TRUNCATE TABLE WILL LEAD TO BINARY LOGSujatha Sivakumar2014-04-151-13/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | WRITTEN WHILE ROWS REMAINS Problem: ======== When truncate table fails while using transactional based engines even though the operation errors out we still continue and log it to binlog. Because of this master has data but the truncate will be written to binary log which will cause inconsistency. Analysis: ======== Truncate table can happen either through drop and create of table or by deleting rows. In the second case the existing code is written in such a way that even if an error occurs the truncate statement will always be binlogged. Which is not correct. Binlogging of TRUNCATE TABLE statement should check whether truncate is executed "transactionally or not". If the table is transaction based we log the TRUNCATE TABLE only on successful completion. If table is non transactional there are possibilities that on error we could have partial changes done hence in such cases we do log in spite of errors as some of the lines might have been removed, so the statement has to be sent to slave. Fix: === Using table handler whether truncate table is being executed in transaction based mode or not is identified and statement is binlogged accordingly.
| | | * upmerge to bug#14548159Rohit Kalhans2012-09-221-15/+19
| | | |