Commit 4db9aaee authored by unknown's avatar unknown

InnoDB: Remove redundant page_no field from dict_index_t.

This completes the patch for fast TRUNCATE TABLE.


innobase/dict/dict0boot.c:
  dict_boot(): Add page_no parameter to dict_index_add_to_cache()
innobase/dict/dict0crea.c:
  Remove dict_index_t:page_no; add ind_node_t:page_no
innobase/dict/dict0dict.c:
  dict_index_add_to_cache(): Add parameter page_no
  dict_tree_create(): Add parameter page_no
innobase/dict/dict0load.c:
  dict_load_indexes(): Add page_no to dict_index_add_to_cache() call
innobase/ibuf/ibuf0ibuf.c:
  ibuf_data_init_for_space(): Move page_no to dict_index_add_to_cache()
innobase/include/dict0crea.h:
  ind_node_t: Add page_no field
innobase/include/dict0dict.h:
  dict_index_add_to_cache(): Add page_no
  dict_tree_create(): Add page_no
innobase/include/dict0mem.h:
  dict_index_t: Remove page_no, as dict_tree_t has "page" field
innobase/row/row0mysql.c:
  row_truncate_table_for_mysql(): Improve the comments
parent c277421d
......@@ -223,6 +223,7 @@ dict_boot(void)
dict_index_t* index;
dict_hdr_t* dict_hdr;
mtr_t mtr;
ibool success;
mtr_start(&mtr);
......@@ -275,20 +276,20 @@ dict_boot(void)
dict_mem_index_add_field(index, "NAME", 0, 0);
index->page_no = mtr_read_ulint(dict_hdr + DICT_HDR_TABLES,
MLOG_4BYTES, &mtr);
index->id = DICT_TABLES_ID;
ut_a(dict_index_add_to_cache(table, index));
success = dict_index_add_to_cache(table, index, mtr_read_ulint(
dict_hdr + DICT_HDR_TABLES, MLOG_4BYTES, &mtr));
ut_a(success);
/*-------------------------*/
index = dict_mem_index_create("SYS_TABLES", "ID_IND",
DICT_HDR_SPACE, DICT_UNIQUE, 1);
dict_mem_index_add_field(index, "ID", 0, 0);
index->page_no = mtr_read_ulint(dict_hdr + DICT_HDR_TABLE_IDS,
MLOG_4BYTES, &mtr);
index->id = DICT_TABLE_IDS_ID;
ut_a(dict_index_add_to_cache(table, index));
success = dict_index_add_to_cache(table, index, mtr_read_ulint(
dict_hdr + DICT_HDR_TABLE_IDS, MLOG_4BYTES, &mtr));
ut_a(success);
/*-------------------------*/
table = dict_mem_table_create("SYS_COLUMNS", DICT_HDR_SPACE, 7, FALSE);
......@@ -311,10 +312,10 @@ dict_boot(void)
dict_mem_index_add_field(index, "TABLE_ID", 0, 0);
dict_mem_index_add_field(index, "POS", 0, 0);
index->page_no = mtr_read_ulint(dict_hdr + DICT_HDR_COLUMNS,
MLOG_4BYTES, &mtr);
index->id = DICT_COLUMNS_ID;
ut_a(dict_index_add_to_cache(table, index));
success = dict_index_add_to_cache(table, index, mtr_read_ulint(
dict_hdr + DICT_HDR_COLUMNS, MLOG_4BYTES, &mtr));
ut_a(success);
/*-------------------------*/
table = dict_mem_table_create("SYS_INDEXES", DICT_HDR_SPACE, 7, FALSE);
......@@ -347,10 +348,10 @@ dict_boot(void)
dict_mem_index_add_field(index, "TABLE_ID", 0, 0);
dict_mem_index_add_field(index, "ID", 0, 0);
index->page_no = mtr_read_ulint(dict_hdr + DICT_HDR_INDEXES,
MLOG_4BYTES, &mtr);
index->id = DICT_INDEXES_ID;
ut_a(dict_index_add_to_cache(table, index));
success = dict_index_add_to_cache(table, index, mtr_read_ulint(
dict_hdr + DICT_HDR_INDEXES, MLOG_4BYTES, &mtr));
ut_a(success);
/*-------------------------*/
table = dict_mem_table_create("SYS_FIELDS", DICT_HDR_SPACE, 3, FALSE);
......@@ -368,10 +369,10 @@ dict_boot(void)
dict_mem_index_add_field(index, "INDEX_ID", 0, 0);
dict_mem_index_add_field(index, "POS", 0, 0);
index->page_no = mtr_read_ulint(dict_hdr + DICT_HDR_FIELDS,
MLOG_4BYTES, &mtr);
index->id = DICT_FIELDS_ID;
ut_a(dict_index_add_to_cache(table, index));
success = dict_index_add_to_cache(table, index, mtr_read_ulint(
dict_hdr + DICT_HDR_FIELDS, MLOG_4BYTES, &mtr));
ut_a(success);
mtr_commit(&mtr);
/*-------------------------*/
......
......@@ -544,9 +544,7 @@ dict_build_index_def_step(
table in the same tablespace */
index->space = table->space;
index->page_no = FIL_NULL;
node->page_no = FIL_NULL;
row = dict_create_sys_indexes_tuple(index, node->heap);
node->ind_row = row;
......@@ -624,18 +622,18 @@ dict_create_index_tree_step(
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
index->page_no = btr_create(index->type, index->space, index->id,
node->page_no = btr_create(index->type, index->space, index->id,
table->comp, &mtr);
/* printf("Created a new index tree in space %lu root page %lu\n",
index->space, index->page_no); */
page_rec_write_index_page_no(btr_pcur_get_rec(&pcur),
DICT_SYS_INDEXES_PAGE_NO_FIELD,
index->page_no, &mtr);
node->page_no, &mtr);
btr_pcur_close(&pcur);
mtr_commit(&mtr);
if (index->page_no == FIL_NULL) {
if (node->page_no == FIL_NULL) {
return(DB_OUT_OF_FILE_SPACE);
}
......@@ -793,7 +791,7 @@ dict_truncate_index_tree(
root_page_no = btr_create(type, space, index_id, comp, mtr);
if (index) {
index->page_no = root_page_no;
index->tree->page = root_page_no;
}
page_rec_write_index_page_no(rec,
......@@ -857,6 +855,7 @@ ind_create_graph_create(
node->index = index;
node->state = INDEX_BUILD_INDEX_DEF;
node->page_no = FIL_NULL;
node->heap = mem_heap_create(256);
node->ind_def = ins_node_create(INS_DIRECT,
......@@ -1076,7 +1075,8 @@ dict_create_index_step(
if (node->state == INDEX_ADD_TO_CACHE) {
success = dict_index_add_to_cache(node->table, node->index);
success = dict_index_add_to_cache(node->table, node->index,
node->page_no);
ut_a(success);
......
......@@ -1374,8 +1374,9 @@ dict_index_add_to_cache(
/*====================*/
/* out: TRUE if success */
dict_table_t* table, /* in: table on which the index is */
dict_index_t* index) /* in, own: index; NOTE! The index memory
dict_index_t* index, /* in, own: index; NOTE! The index memory
object is freed in this function! */
ulint page_no)/* in: root page number of the index */
{
dict_index_t* new_index;
dict_tree_t* tree;
......@@ -1461,10 +1462,9 @@ dict_index_add_to_cache(
tree = dict_index_get_tree(
UT_LIST_GET_FIRST(cluster->indexes));
new_index->tree = tree;
new_index->page_no = tree->page;
} else {
/* Create an index tree memory object for the index */
tree = dict_tree_create(new_index);
tree = dict_tree_create(new_index, page_no);
ut_ad(tree);
new_index->tree = tree;
......@@ -1749,7 +1749,6 @@ dict_index_build_internal_clust(
new_index->n_user_defined_cols = index->n_fields;
new_index->id = index->id;
new_index->page_no = index->page_no;
if (table->type != DICT_TABLE_ORDINARY) {
/* The index is mixed: copy common key prefix fields */
......@@ -1928,7 +1927,6 @@ dict_index_build_internal_non_clust(
new_index->n_user_defined_cols = index->n_fields;
new_index->id = index->id;
new_index->page_no = index->page_no;
/* Copy fields from index to new_index */
dict_index_copy(new_index, index, 0, index->n_fields);
......@@ -3565,9 +3563,10 @@ dict_tree_t*
dict_tree_create(
/*=============*/
/* out, own: created tree */
dict_index_t* index) /* in: the index for which to create: in the
dict_index_t* index, /* in: the index for which to create: in the
case of a mixed tree, this should be the
index of the cluster object */
ulint page_no)/* in: root page number of the index */
{
dict_tree_t* tree;
......@@ -3577,7 +3576,7 @@ dict_tree_create(
tree->type = index->type;
tree->space = index->space;
tree->page = index->page_no;
tree->page = page_no;
tree->id = index->id;
......
......@@ -681,12 +681,10 @@ dict_load_indexes(
} else {
index = dict_mem_index_create(table->name, name_buf,
space, type, n_fields);
index->page_no = page_no;
index->id = id;
dict_load_fields(table, index, heap);
dict_index_add_to_cache(table, index);
dict_index_add_to_cache(table, index, page_no);
}
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
......
......@@ -548,11 +548,9 @@ ibuf_data_init_for_space(
dict_mem_index_add_field(index, "PAGE_NO", 0, 0);
dict_mem_index_add_field(index, "TYPES", 0, 0);
index->page_no = FSP_IBUF_TREE_ROOT_PAGE_NO;
index->id = ut_dulint_add(DICT_IBUF_ID_MIN, space);
dict_index_add_to_cache(table, index);
dict_index_add_to_cache(table, index, FSP_IBUF_TREE_ROOT_PAGE_NO);
data->index = dict_table_get_first_index(table);
......
......@@ -153,6 +153,7 @@ struct ind_node_struct{
/*----------------------*/
/* Local storage for this graph node */
ulint state; /* node execution state */
ulint page_no;/* root page number of the index */
dict_table_t* table; /* table which owns the index */
dtuple_t* ind_row;/* index definition row built */
ulint field_no;/* next field definition to insert */
......
......@@ -508,8 +508,9 @@ dict_index_add_to_cache(
/*====================*/
/* out: TRUE if success */
dict_table_t* table, /* in: table on which the index is */
dict_index_t* index); /* in, own: index; NOTE! The index memory
dict_index_t* index, /* in, own: index; NOTE! The index memory
object is freed in this function! */
ulint page_no);/* in: root page number of the index */
/************************************************************************
Gets the number of fields in the internal representation of an index,
including fields added by the dictionary system. */
......@@ -686,9 +687,10 @@ dict_tree_t*
dict_tree_create(
/*=============*/
/* out, own: created tree */
dict_index_t* index); /* in: the index for which to create: in the
dict_index_t* index, /* in: the index for which to create: in the
case of a mixed tree, this should be the
index of the cluster object */
ulint page_no);/* in: root page number of the index */
/**************************************************************************
Frees an index tree struct. */
......
......@@ -218,7 +218,6 @@ struct dict_index_struct{
const char* table_name; /* table name */
dict_table_t* table; /* back pointer to table */
ulint space; /* space where the index tree is placed */
ulint page_no;/* page number of the index tree root */
ulint trx_id_offset;/* position of the the trx id column
in a clustered index record, if the fields
before it are known to be of a fixed size,
......
......@@ -2455,12 +2455,20 @@ queries on the table.
2) Purge and rollback: we assign a new table id for the table. Since purge and
rollback look for the table based on the table id, they see the table as
'dropped' and discard their operations.
3) Insert buffer: we remove all entries for the table in the insert
buffer tree; ... TODO
3) Insert buffer: TRUNCATE TABLE is analogous to DROP TABLE, so we do not
have to remove insert buffer records, as the insert buffer works at a low
level. If a freed page is later reallocated, the allocator will remove
the ibuf entries for it.
TODO: when we truncate *.ibd files (analogous to DISCARD TABLESPACE), we
will have to remove we remove all entries for the table in the insert
buffer tree!
4) Linear readahead and random readahead: we use the same method as in 3) to
discard ongoing operations.
discard ongoing operations. (This will only be relevant for TRUNCATE TABLE
by DISCARD TABLESPACE.)
5) FOREIGN KEY operations: if table->n_foreign_key_checks_running > 0, we
do not allow the discard. We also reserve the data dictionary latch. */
do not allow the TRUNCATE. We also reserve the data dictionary latch. */
static const char renumber_tablespace_proc[] =
"PROCEDURE RENUMBER_TABLESPACE_PROC () IS\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment