summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/share/errmsg-utf8.txt2
-rw-r--r--sql/sql_truncate.cc47
2 files changed, 27 insertions, 22 deletions
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index feb47f9af94..94737d48e64 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7931,3 +7931,5 @@ ER_PERIOD_CONSTRAINT_DROP
eng "Can't DROP CONSTRAINT `%s`. Use DROP PERIOD `%s` for this"
ER_TOO_LONG_KEYPART 42000 S1009
eng "Specified key part was too long; max key part length is %u bytes"
+ER_TRUNCATE_ILLEGAL_VERS
+ eng "Cannot truncate a versioned table"
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc
index 389276d0bcf..c0de635579a 100644
--- a/sql/sql_truncate.cc
+++ b/sql/sql_truncate.cc
@@ -275,6 +275,9 @@ Sql_cmd_truncate_table::handler_truncate(THD *thd, TABLE_LIST *table_ref,
bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref,
bool *hton_can_recreate)
{
+ handlerton *hton;
+ bool versioned;
+ bool sequence= false;
TABLE *table= NULL;
DBUG_ENTER("Sql_cmd_truncate_table::lock_table");
@@ -302,43 +305,43 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref,
table_ref->table_name.str, NULL)))
DBUG_RETURN(TRUE);
- *hton_can_recreate= ha_check_storage_engine_flag(table->file->ht,
- HTON_CAN_RECREATE);
+ versioned= table->versioned();
+ hton= table->file->ht;
table_ref->mdl_request.ticket= table->mdl_ticket;
}
else
{
- handlerton *hton;
- bool is_sequence;
-
- /* Acquire an exclusive lock. */
DBUG_ASSERT(table_ref->next_global == NULL);
if (lock_table_names(thd, table_ref, NULL,
thd->variables.lock_wait_timeout, 0))
DBUG_RETURN(TRUE);
- if (!ha_table_exists(thd, &table_ref->db, &table_ref->table_name,
- &hton, &is_sequence) ||
- hton == view_pseudo_hton)
+ TABLE_SHARE *share= tdc_acquire_share(thd, table_ref, GTS_TABLE | GTS_VIEW);
+ if (share == NULL)
+ DBUG_RETURN(TRUE);
+ DBUG_ASSERT(share != (TABLE_SHARE*)1);
+
+ versioned= share->versioned;
+ sequence= share->table_type == TABLE_TYPE_SEQUENCE;
+ hton= share->db_type();
+
+ tdc_release_share(share);
+
+ if (hton == view_pseudo_hton)
{
my_error(ER_NO_SUCH_TABLE, MYF(0), table_ref->db.str,
table_ref->table_name.str);
DBUG_RETURN(TRUE);
}
+ }
- if (!hton)
- {
- /*
- The table exists, but its storage engine is unknown, perhaps not
- loaded at the moment. We need to open and parse the frm to know the
- storage engine in question, so let's proceed with the truncation and
- try to open the table. This will produce the correct error message
- about unknown engine.
- */
- *hton_can_recreate= false;
- }
- else
- *hton_can_recreate= !is_sequence && hton->flags & HTON_CAN_RECREATE;
+ *hton_can_recreate= !sequence
+ && ha_check_storage_engine_flag(hton, HTON_CAN_RECREATE);
+
+ if (versioned)
+ {
+ my_error(ER_TRUNCATE_ILLEGAL_VERS, MYF(0));
+ DBUG_RETURN(TRUE);
}
/*