Commit ebf539dd authored by Marko Mäkelä's avatar Marko Mäkelä

Add system columns to tables before creating the table

dict_create_sys_tables_tuple(), dict_create_table_step(): Omit the
system columns (which will now exist in the dict_table_t object
already at this point).

dict_create_table_step(): Expect the callers to invoke
dict_table_add_system_columns().

pars_create_table(): Before creating the table creation execution graph,
invoke dict_table_add_system_columns().

row_create_table_for_mysql(): Expect all callers to invoke
dict_table_add_system_columns().
parent 5ffdb98f
...@@ -67,6 +67,7 @@ dict_create_sys_tables_tuple( ...@@ -67,6 +67,7 @@ dict_create_sys_tables_tuple(
ut_ad(table); ut_ad(table);
ut_ad(heap); ut_ad(heap);
ut_ad(table->n_cols >= DATA_N_SYS_COLS);
sys_tables = dict_sys->sys_tables; sys_tables = dict_sys->sys_tables;
...@@ -100,7 +101,8 @@ dict_create_sys_tables_tuple( ...@@ -100,7 +101,8 @@ dict_create_sys_tables_tuple(
/* If there is any virtual column, encode it in N_COLS */ /* If there is any virtual column, encode it in N_COLS */
mach_write_to_4(ptr, dict_table_encode_n_col( mach_write_to_4(ptr, dict_table_encode_n_col(
static_cast<ulint>(table->n_def), static_cast<ulint>(table->n_cols
- DATA_N_SYS_COLS),
static_cast<ulint>(table->n_v_def)) static_cast<ulint>(table->n_v_def))
| ((table->flags & DICT_TF_COMPACT) << 31)); | ((table->flags & DICT_TF_COMPACT) << 31));
dfield_set_data(dfield, ptr, 4); dfield_set_data(dfield, ptr, 4);
...@@ -480,21 +482,6 @@ dict_build_tablespace_for_table( ...@@ -480,21 +482,6 @@ dict_build_tablespace_for_table(
return(DB_SUCCESS); return(DB_SUCCESS);
} }
/***************************************************************//**
Builds a column definition to insert. */
static
void
dict_build_col_def_step(
/*====================*/
tab_node_t* node) /*!< in: table create node */
{
dtuple_t* row;
row = dict_create_sys_columns_tuple(node->table, node->col_no,
node->heap);
ins_node_set_new_row(node->col_def, row);
}
/** Builds a SYS_VIRTUAL row definition to insert. /** Builds a SYS_VIRTUAL row definition to insert.
@param[in] node table create node */ @param[in] node table create node */
static static
...@@ -1356,12 +1343,19 @@ dict_create_table_step( ...@@ -1356,12 +1343,19 @@ dict_create_table_step(
if (node->state == TABLE_BUILD_COL_DEF) { if (node->state == TABLE_BUILD_COL_DEF) {
if (node->col_no < (static_cast<ulint>(node->table->n_def) if (node->col_no + DATA_N_SYS_COLS
< (static_cast<ulint>(node->table->n_def)
+ static_cast<ulint>(node->table->n_v_def))) { + static_cast<ulint>(node->table->n_v_def))) {
dict_build_col_def_step(node); ulint i = node->col_no++;
if (i + DATA_N_SYS_COLS >= node->table->n_def) {
i += DATA_N_SYS_COLS;
}
node->col_no++; ins_node_set_new_row(
node->col_def,
dict_create_sys_columns_tuple(node->table, i,
node->heap));
thr->run_node = node->col_def; thr->run_node = node->col_def;
...@@ -1419,7 +1413,6 @@ dict_create_table_step( ...@@ -1419,7 +1413,6 @@ dict_create_table_step(
if (node->state == TABLE_ADD_TO_CACHE) { if (node->state == TABLE_ADD_TO_CACHE) {
DBUG_EXECUTE_IF("ib_ddl_crash_during_create", DBUG_SUICIDE();); DBUG_EXECUTE_IF("ib_ddl_crash_during_create", DBUG_SUICIDE(););
dict_table_add_system_columns(node->table, node->heap);
node->table->can_be_evicted = true; node->table->can_be_evicted = true;
node->table->add_to_cache(); node->table->add_to_cache();
......
...@@ -1747,7 +1747,7 @@ fts_create_in_mem_aux_table( ...@@ -1747,7 +1747,7 @@ fts_create_in_mem_aux_table(
@param[in] table Table that has FTS Index @param[in] table Table that has FTS Index
@param[in] fts_table_name FTS AUX table name @param[in] fts_table_name FTS AUX table name
@param[in] fts_suffix FTS AUX table suffix @param[in] fts_suffix FTS AUX table suffix
@param[in] heap heap @param[in,out] heap temporary memory heap
@return table object if created, else NULL */ @return table object if created, else NULL */
static static
dict_table_t* dict_table_t*
...@@ -1784,6 +1784,7 @@ fts_create_one_common_table( ...@@ -1784,6 +1784,7 @@ fts_create_one_common_table(
FTS_CONFIG_TABLE_VALUE_COL_LEN); FTS_CONFIG_TABLE_VALUE_COL_LEN);
} }
dict_table_add_system_columns(new_table, heap);
error = row_create_table_for_mysql(new_table, trx, error = row_create_table_for_mysql(new_table, trx,
FIL_ENCRYPTION_DEFAULT, FIL_DEFAULT_ENCRYPTION_KEY); FIL_ENCRYPTION_DEFAULT, FIL_DEFAULT_ENCRYPTION_KEY);
...@@ -1885,6 +1886,8 @@ fts_create_common_tables( ...@@ -1885,6 +1886,8 @@ fts_create_common_tables(
common_tables.push_back(common_table); common_tables.push_back(common_table);
} }
mem_heap_empty(heap);
DBUG_EXECUTE_IF("ib_fts_aux_table_error", DBUG_EXECUTE_IF("ib_fts_aux_table_error",
/* Return error after creating FTS_AUX_CONFIG table. */ /* Return error after creating FTS_AUX_CONFIG table. */
if (i == 4) { if (i == 4) {
...@@ -1944,7 +1947,7 @@ fts_create_common_tables( ...@@ -1944,7 +1947,7 @@ fts_create_common_tables(
@param[in,out] trx transaction @param[in,out] trx transaction
@param[in] index the index instance @param[in] index the index instance
@param[in] fts_table fts_table structure @param[in] fts_table fts_table structure
@param[in,out] heap memory heap @param[in,out] heap temporary memory heap
@see row_merge_create_fts_sort_index() @see row_merge_create_fts_sort_index()
@return DB_SUCCESS or error code */ @return DB_SUCCESS or error code */
static static
...@@ -2001,6 +2004,7 @@ fts_create_one_index_table( ...@@ -2001,6 +2004,7 @@ fts_create_one_index_table(
(DATA_MTYPE_MAX << 16) | DATA_UNSIGNED | DATA_NOT_NULL, (DATA_MTYPE_MAX << 16) | DATA_UNSIGNED | DATA_NOT_NULL,
FTS_INDEX_ILIST_LEN); FTS_INDEX_ILIST_LEN);
dict_table_add_system_columns(new_table, heap);
error = row_create_table_for_mysql(new_table, trx, error = row_create_table_for_mysql(new_table, trx,
FIL_ENCRYPTION_DEFAULT, FIL_DEFAULT_ENCRYPTION_KEY); FIL_ENCRYPTION_DEFAULT, FIL_DEFAULT_ENCRYPTION_KEY);
...@@ -2076,6 +2080,8 @@ fts_create_index_tables_low( ...@@ -2076,6 +2080,8 @@ fts_create_index_tables_low(
aux_idx_tables.push_back(new_table); aux_idx_tables.push_back(new_table);
} }
mem_heap_empty(heap);
DBUG_EXECUTE_IF("ib_fts_index_table_error", DBUG_EXECUTE_IF("ib_fts_index_table_error",
/* Return error after creating FTS_INDEX_5 /* Return error after creating FTS_INDEX_5
aux table. */ aux table. */
......
...@@ -11590,6 +11590,8 @@ create_table_info_t::create_table_def() ...@@ -11590,6 +11590,8 @@ create_table_info_t::create_table_def()
fts_add_doc_id_column(table, heap); fts_add_doc_id_column(table, heap);
} }
dict_table_add_system_columns(table, heap);
ut_ad(trx_state_eq(m_trx, TRX_STATE_NOT_STARTED)); ut_ad(trx_state_eq(m_trx, TRX_STATE_NOT_STARTED));
/* If temp table, then we avoid creation of entries in SYSTEM TABLES. /* If temp table, then we avoid creation of entries in SYSTEM TABLES.
...@@ -11604,19 +11606,10 @@ create_table_info_t::create_table_def() ...@@ -11604,19 +11606,10 @@ create_table_info_t::create_table_def()
err = dict_build_tablespace_for_table(table, NULL); err = dict_build_tablespace_for_table(table, NULL);
if (err == DB_SUCCESS) { if (err == DB_SUCCESS) {
/* Temp-table are maintained in memory and so
can_be_evicted is FALSE. */
mem_heap_t* temp_table_heap;
temp_table_heap = mem_heap_create(256);
dict_table_add_system_columns(table, temp_table_heap);
table->add_to_cache(); table->add_to_cache();
DBUG_EXECUTE_IF("ib_ddl_crash_during_create2", DBUG_EXECUTE_IF("ib_ddl_crash_during_create2",
DBUG_SUICIDE();); DBUG_SUICIDE(););
mem_heap_free(temp_table_heap);
} }
} else { } else {
if (err == DB_SUCCESS) { if (err == DB_SUCCESS) {
......
...@@ -5215,6 +5215,8 @@ prepare_inplace_alter_table_dict( ...@@ -5215,6 +5215,8 @@ prepare_inplace_alter_table_dict(
ctx->new_table->fts->doc_col = fts_doc_id_col; ctx->new_table->fts->doc_col = fts_doc_id_col;
} }
dict_table_add_system_columns(ctx->new_table, ctx->heap);
error = row_create_table_for_mysql( error = row_create_table_for_mysql(
ctx->new_table, ctx->trx, mode, key_id); ctx->new_table, ctx->trx, mode, key_id);
......
...@@ -1916,12 +1916,13 @@ pars_create_table( ...@@ -1916,12 +1916,13 @@ pars_create_table(
table = dict_mem_table_create( table = dict_mem_table_create(
table_sym->name, 0, n_cols, 0, flags, flags2); table_sym->name, 0, n_cols, 0, flags, flags2);
mem_heap_t* heap = pars_sym_tab_global->heap;
column = column_defs; column = column_defs;
while (column) { while (column) {
dtype = dfield_get_type(que_node_get_val(column)); dtype = dfield_get_type(que_node_get_val(column));
dict_mem_table_add_col(table, table->heap, dict_mem_table_add_col(table, heap,
column->name, dtype->mtype, column->name, dtype->mtype,
dtype->prtype, dtype->len); dtype->prtype, dtype->len);
column->resolved = TRUE; column->resolved = TRUE;
...@@ -1930,8 +1931,10 @@ pars_create_table( ...@@ -1930,8 +1931,10 @@ pars_create_table(
column = static_cast<sym_node_t*>(que_node_get_next(column)); column = static_cast<sym_node_t*>(que_node_get_next(column));
} }
node = tab_create_graph_create(table, pars_sym_tab_global->heap, dict_table_add_system_columns(table, heap);
FIL_ENCRYPTION_DEFAULT, FIL_DEFAULT_ENCRYPTION_KEY); node = tab_create_graph_create(table, heap,
FIL_ENCRYPTION_DEFAULT,
FIL_DEFAULT_ENCRYPTION_KEY);
table_sym->resolved = TRUE; table_sym->resolved = TRUE;
table_sym->token_type = SYM_TABLE; table_sym->token_type = SYM_TABLE;
......
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