| 1 | #ifndef SQL_TRUNCATE_INCLUDED |
| 2 | #define SQL_TRUNCATE_INCLUDED |
| 3 | /* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; version 2 of the License. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 17 | |
| 18 | class THD; |
| 19 | struct TABLE_LIST; |
| 20 | |
| 21 | /** |
| 22 | Sql_cmd_truncate_table represents the TRUNCATE statement. |
| 23 | */ |
| 24 | class Sql_cmd_truncate_table : public Sql_cmd |
| 25 | { |
| 26 | private: |
| 27 | /* Set if a lock must be downgraded after truncate is done. */ |
| 28 | MDL_ticket *m_ticket_downgrade; |
| 29 | |
| 30 | public: |
| 31 | /** |
| 32 | Constructor, used to represent a TRUNCATE statement. |
| 33 | */ |
| 34 | Sql_cmd_truncate_table() |
| 35 | {} |
| 36 | |
| 37 | virtual ~Sql_cmd_truncate_table() |
| 38 | {} |
| 39 | |
| 40 | /** |
| 41 | Execute a TRUNCATE statement at runtime. |
| 42 | @param thd the current thread. |
| 43 | @return false on success. |
| 44 | */ |
| 45 | bool execute(THD *thd); |
| 46 | |
| 47 | virtual enum_sql_command sql_command_code() const |
| 48 | { |
| 49 | return SQLCOM_TRUNCATE; |
| 50 | } |
| 51 | |
| 52 | protected: |
| 53 | enum truncate_result{ |
| 54 | TRUNCATE_OK=0, |
| 55 | TRUNCATE_FAILED_BUT_BINLOG, |
| 56 | TRUNCATE_FAILED_SKIP_BINLOG |
| 57 | }; |
| 58 | |
| 59 | /** Handle locking a base table for truncate. */ |
| 60 | bool lock_table(THD *, TABLE_LIST *, bool *); |
| 61 | |
| 62 | /** Truncate table via the handler method. */ |
| 63 | enum truncate_result handler_truncate(THD *, TABLE_LIST *, bool); |
| 64 | |
| 65 | /** |
| 66 | Optimized delete of all rows by doing a full regenerate of the table. |
| 67 | Depending on the storage engine, it can be accomplished through a |
| 68 | drop and recreate or via the handler truncate method. |
| 69 | */ |
| 70 | bool truncate_table(THD *, TABLE_LIST *); |
| 71 | }; |
| 72 | |
| 73 | #endif |
| 74 | |