summaryrefslogtreecommitdiff
path: root/innobase/dict
diff options
context:
space:
mode:
authorunknown <marko@hundin.mysql.fi>2005-01-11 16:28:07 +0200
committerunknown <marko@hundin.mysql.fi>2005-01-11 16:28:07 +0200
commitff4507a9dec635b1fa879d3fd62b5adf05be6235 (patch)
treef65410ac2958d249442b5341ea37a653007677dc /innobase/dict
parent0b7895b9b14981926c34fbd833aed0d9235da68a (diff)
downloadmariadb-git-ff4507a9dec635b1fa879d3fd62b5adf05be6235.tar.gz
InnoDB: Implement fast TRUNCATE TABLE (Bug #7150)
innobase/dict/dict0boot.c: Added DICT_SYS_INDEXES_TYPE_FIELD innobase/dict/dict0crea.c: Added dict_truncate_index_tree() innobase/include/dict0boot.h: Added DICT_SYS_INDEXES_TYPE_FIELD innobase/include/dict0crea.h: Added dict_truncate_index_tree() innobase/include/row0mysql.h: Added row_truncate_table_for_mysql() innobase/row/row0mysql.c: Added row_truncate_table_for_mysql() sql/ha_innodb.cc: Added ha_innobase::delete_all_rows() in order to implement fast TRUNCATE TABLE sql/ha_innodb.h: Added ha_innobase::delete_all_rows() in order to implement fast TRUNCATE TABLE
Diffstat (limited to 'innobase/dict')
-rw-r--r--innobase/dict/dict0boot.c3
-rw-r--r--innobase/dict/dict0crea.c95
2 files changed, 98 insertions, 0 deletions
diff --git a/innobase/dict/dict0boot.c b/innobase/dict/dict0boot.c
index e500b92252f..883c5464319 100644
--- a/innobase/dict/dict0boot.c
+++ b/innobase/dict/dict0boot.c
@@ -333,6 +333,9 @@ dict_boot(void)
#if DICT_SYS_INDEXES_SPACE_NO_FIELD != 5 + 2
#error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 5 + 2"
#endif
+#if DICT_SYS_INDEXES_TYPE_FIELD != 4 + 2
+#error "DICT_SYS_INDEXES_TYPE_FIELD != 4 + 2"
+#endif
table->id = DICT_INDEXES_ID;
dict_table_add_to_cache(table);
diff --git a/innobase/dict/dict0crea.c b/innobase/dict/dict0crea.c
index 747a99ebdc9..e744ffda7a6 100644
--- a/innobase/dict/dict0crea.c
+++ b/innobase/dict/dict0crea.c
@@ -706,6 +706,101 @@ dict_drop_index_tree(
DICT_SYS_INDEXES_PAGE_NO_FIELD, FIL_NULL, mtr);
}
+/***********************************************************************
+Truncates the index tree associated with a row in SYS_INDEXES table. */
+
+void
+dict_truncate_index_tree(
+/*=====================*/
+ dict_table_t* table, /* in: the table the index belongs to */
+ rec_t* rec, /* in: record in the clustered index of
+ SYS_INDEXES table */
+ mtr_t* mtr) /* in: mtr having the latch
+ on the record page */
+{
+ ulint root_page_no;
+ ulint space;
+ ulint type;
+ dulint index_id;
+ byte* ptr;
+ ulint len;
+ ibool comp;
+ dict_index_t* index;
+
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
+
+ ut_a(!dict_sys->sys_indexes->comp);
+ ptr = rec_get_nth_field_old(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len);
+
+ ut_ad(len == 4);
+
+ root_page_no = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
+
+ if (root_page_no == FIL_NULL) {
+ /* The tree has been freed. */
+
+ return;
+ }
+
+ ptr = rec_get_nth_field_old(rec,
+ DICT_SYS_INDEXES_SPACE_NO_FIELD, &len);
+
+ ut_ad(len == 4);
+
+ space = mtr_read_ulint(ptr, MLOG_4BYTES, mtr);
+
+ if (!fil_tablespace_exists_in_mem(space)) {
+ /* It is a single table tablespace and the .ibd file is
+ missing: do nothing */
+
+ return;
+ }
+
+ ptr = rec_get_nth_field_old(rec,
+ DICT_SYS_INDEXES_TYPE_FIELD, &len);
+ ut_ad(len == 4);
+ type = mach_read_from_4(ptr);
+
+ ptr = rec_get_nth_field_old(rec, 1, &len);
+ ut_ad(len == 8);
+ index_id = mach_read_from_8(ptr);
+
+ /* We free all the pages but the root page first; this operation
+ may span several mini-transactions */
+
+ btr_free_but_not_root(space, root_page_no);
+
+ /* Then we free the root page in the same mini-transaction where
+ we create the b-tree and write its new root page number to the
+ appropriate field in the SYS_INDEXES record: this mini-transaction
+ marks the B-tree totally truncated */
+
+ comp = page_is_comp(btr_page_get(
+ space, root_page_no, RW_X_LATCH, mtr));
+
+ btr_free_root(space, root_page_no, mtr);
+
+ /* Find the index corresponding to this SYS_INDEXES record. */
+ for (index = UT_LIST_GET_FIRST(table->indexes);
+ index;
+ index = UT_LIST_GET_NEXT(indexes, index)) {
+ if (!ut_dulint_cmp(index->id, index_id)) {
+ break;
+ }
+ }
+
+ root_page_no = btr_create(type, space, index_id, comp, mtr);
+ if (index) {
+ index->page_no = root_page_no;
+ }
+
+ page_rec_write_index_page_no(rec,
+ DICT_SYS_INDEXES_PAGE_NO_FIELD,
+ root_page_no, mtr);
+}
+
/*************************************************************************
Creates a table create graph. */