Commit 53f8a9ff authored by osku's avatar osku

Add dict_table_get_col_name() in preparation for getting rid of

dict_col_t::name, and use it instead of col->name everywhere.
parent a78e2113
......@@ -129,6 +129,7 @@ dict_create_sys_columns_tuple(
dict_col_t* column;
dfield_t* dfield;
byte* ptr;
const char* col_name;
ut_ad(table && heap);
......@@ -155,7 +156,8 @@ dict_create_sys_columns_tuple(
/* 4: NAME ---------------------------*/
dfield = dtuple_get_nth_field(entry, 2);
dfield_set_data(dfield, column->name, ut_strlen(column->name));
col_name = dict_table_get_col_name(table, i);
dfield_set_data(dfield, col_name, ut_strlen(col_name));
/* 5: MTYPE --------------------------*/
dfield = dtuple_get_nth_field(entry, 3);
......
......@@ -143,6 +143,7 @@ dict_index_copy(
/*============*/
dict_index_t* index1, /* in: index to copy to */
dict_index_t* index2, /* in: index to copy from */
dict_table_t* table, /* in: table */
ulint start, /* in: first position to copy */
ulint end); /* in: last position to copy */
/***********************************************************************
......@@ -191,6 +192,7 @@ static
void
dict_col_print_low(
/*===============*/
dict_table_t* table, /* in: table */
dict_col_t* col); /* in: column */
/**************************************************************************
Prints an index data. */
......@@ -373,6 +375,25 @@ dict_table_get_index_noninline(
return(dict_table_get_index(table, name));
}
/**************************************************************************
Returns a column's name. */
const char*
dict_table_get_col_name(
/*====================*/
/* out: column name. NOTE: not guaranteed to
stay valid if table is modified in any way
(columns added, etc.). */
dict_table_t* table, /* in: table */
ulint i) /* in: column number */
{
ut_ad(table);
ut_ad(i < table->n_def);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
return(dict_table_get_nth_col(table, i)->name);
}
/************************************************************************
Initializes the autoinc counter. It is not an error to initialize an already
initialized counter. */
......@@ -1474,10 +1495,9 @@ dict_index_find_cols(
dict_field_t* field = dict_index_get_nth_field(index, i);
for (j = 0; j < table->n_cols; j++) {
dict_col_t* col = dict_table_get_nth_col(table, j);
if (!strcmp(col->name, field->name)) {
field->col = col;
if (!strcmp(dict_table_get_col_name(table, j),
field->name)) {
field->col = dict_table_get_nth_col(table, j);
goto found;
}
......@@ -1498,12 +1518,16 @@ void
dict_index_add_col(
/*===============*/
dict_index_t* index, /* in: index */
dict_table_t* table, /* in: table */
dict_col_t* col, /* in: column */
ulint prefix_len) /* in: column prefix length */
{
dict_field_t* field;
const char* col_name;
col_name = dict_table_get_col_name(table, dict_col_get_no(col));
dict_mem_index_add_field(index, col->name, prefix_len);
dict_mem_index_add_field(index, col_name, prefix_len);
field = dict_index_get_nth_field(index, index->n_def - 1);
......@@ -1535,6 +1559,7 @@ dict_index_copy(
/*============*/
dict_index_t* index1, /* in: index to copy to */
dict_index_t* index2, /* in: index to copy from */
dict_table_t* table, /* in: table */
ulint start, /* in: first position to copy */
ulint end) /* in: last position to copy */
{
......@@ -1546,7 +1571,8 @@ dict_index_copy(
for (i = start; i < end; i++) {
field = dict_index_get_nth_field(index2, i);
dict_index_add_col(index1, field->col, field->prefix_len);
dict_index_add_col(index1, table, field->col,
field->prefix_len);
}
}
......@@ -1647,7 +1673,7 @@ dict_index_build_internal_clust(
new_index->id = index->id;
/* Copy the fields of index */
dict_index_copy(new_index, index, 0, index->n_fields);
dict_index_copy(new_index, index, table, 0, index->n_fields);
if (UNIV_UNLIKELY(index->type & DICT_UNIVERSAL)) {
/* No fixed number of fields determines an entry uniquely */
......@@ -1682,19 +1708,21 @@ dict_index_build_internal_clust(
#endif
if (!(index->type & DICT_UNIQUE)) {
dict_index_add_col(new_index,
dict_table_get_sys_col
(table, DATA_ROW_ID), 0);
dict_index_add_col(new_index, table,
dict_table_get_sys_col(
table, DATA_ROW_ID),
0);
trx_id_pos++;
}
dict_index_add_col(new_index,
dict_table_get_sys_col
(table, DATA_TRX_ID), 0);
dict_index_add_col(new_index, table,
dict_table_get_sys_col(table, DATA_TRX_ID),
0);
dict_index_add_col(new_index,
dict_table_get_sys_col
(table, DATA_ROLL_PTR), 0);
dict_index_add_col(new_index, table,
dict_table_get_sys_col(table,
DATA_ROLL_PTR),
0);
for (i = 0; i < trx_id_pos; i++) {
......@@ -1745,7 +1773,7 @@ dict_index_build_internal_clust(
ut_ad(col->type.mtype != DATA_SYS);
if (!indexed[col->ind]) {
dict_index_add_col(new_index, col, 0);
dict_index_add_col(new_index, table, col, 0);
}
}
......@@ -1805,7 +1833,7 @@ dict_index_build_internal_non_clust(
new_index->id = index->id;
/* Copy fields from index to new_index */
dict_index_copy(new_index, index, 0, index->n_fields);
dict_index_copy(new_index, index, table, 0, index->n_fields);
/* Remember the table columns already contained in new_index */
indexed = mem_alloc(table->n_cols * sizeof *indexed);
......@@ -1833,7 +1861,7 @@ dict_index_build_internal_non_clust(
field = dict_index_get_nth_field(clust_index, i);
if (!indexed[field->col->ind]) {
dict_index_add_col(new_index, field->col,
dict_index_add_col(new_index, table, field->col,
field->prefix_len);
}
}
......@@ -1976,6 +2004,7 @@ dict_foreign_find_index(
only has an effect if types_idx != NULL */
{
dict_index_t* index;
dict_field_t* field;
const char* col_name;
ulint i;
......@@ -1985,10 +2014,12 @@ dict_foreign_find_index(
if (dict_index_get_n_fields(index) >= n_cols) {
for (i = 0; i < n_cols; i++) {
col_name = dict_index_get_nth_field(index, i)
->col->name;
if (dict_index_get_nth_field(index, i)
->prefix_len != 0) {
field = dict_index_get_nth_field(index, i);
col_name = dict_table_get_col_name(
table, dict_col_get_no(field->col));
if (field->prefix_len != 0) {
/* We do not accept column prefix
indexes here */
......@@ -2400,7 +2431,6 @@ dict_scan_col(
const char** name) /* out,own: the column name; NULL if no name
was scannable */
{
dict_col_t* col;
ulint i;
*success = FALSE;
......@@ -2418,14 +2448,15 @@ dict_scan_col(
} else {
for (i = 0; i < dict_table_get_n_cols(table); i++) {
col = dict_table_get_nth_col(table, i);
const char* col_name = dict_table_get_col_name(
table, i);
if (0 == innobase_strcasecmp(col->name, *name)) {
if (0 == innobase_strcasecmp(col_name, *name)) {
/* Found */
*success = TRUE;
*column = col;
strcpy((char*) *name, col->name);
*column = dict_table_get_nth_col(table, i);
strcpy((char*) *name, col_name);
break;
}
......@@ -3022,8 +3053,10 @@ col_loop1:
foreign->foreign_col_names = mem_heap_alloc(foreign->heap,
i * sizeof(void*));
for (i = 0; i < foreign->n_fields; i++) {
foreign->foreign_col_names[i] = mem_heap_strdup
(foreign->heap, columns[i]->name);
foreign->foreign_col_names[i] = mem_heap_strdup(
foreign->heap,
dict_table_get_col_name(table,
dict_col_get_no(columns[i])));
}
ptr = dict_scan_table_name(cs, ptr, &referenced_table, name,
......@@ -3935,7 +3968,7 @@ dict_table_print_low(
(ulong) table->stat_n_rows);
for (i = 0; i + 1 < (ulint) table->n_cols; i++) {
dict_col_print_low(dict_table_get_nth_col(table, i));
dict_col_print_low(table, dict_table_get_nth_col(table, i));
fputs("; ", stderr);
}
......@@ -3969,6 +4002,7 @@ static
void
dict_col_print_low(
/*===============*/
dict_table_t* table, /* in: table */
dict_col_t* col) /* in: column */
{
dtype_t* type;
......@@ -3978,7 +4012,8 @@ dict_col_print_low(
#endif /* UNIV_SYNC_DEBUG */
type = dict_col_get_type(col);
fprintf(stderr, "%s: ", col->name);
fprintf(stderr, "%s: ", dict_table_get_col_name(table,
dict_col_get_no(col)));
dtype_print(type);
}
......
......@@ -26,6 +26,25 @@ Created 4/24/1996 Heikki Tuuri
#include "srv0start.h"
#include "srv0srv.h"
/********************************************************************
Returns TRUE if index's i'th column's name is 'name' .*/
static
ibool
name_of_col_is(
/*===========*/
/* out: */
dict_table_t* table, /* in: table */
dict_index_t* index, /* in: index */
ulint i, /* in: */
const char* name) /* in: name to compare to */
{
ulint tmp = dict_col_get_no(dict_field_get_col(
dict_index_get_nth_field(
index, i)));
return(strcmp(name, dict_table_get_col_name(table, tmp)) == 0);
}
/************************************************************************
Finds the first table name in the given database. */
......@@ -371,8 +390,7 @@ dict_load_columns(
ut_ad(len == 4);
ut_a(i == mach_read_from_4(field));
ut_a(!strcmp("NAME", dict_field_get_col
(dict_index_get_nth_field(sys_index, 4))->name));
ut_a(name_of_col_is(sys_columns, sys_index, 4, "NAME"));
field = rec_get_nth_field_old(rec, 4, &len);
name = mem_heap_strdupl(heap, (char*) field, len);
......@@ -407,8 +425,7 @@ dict_load_columns(
field = rec_get_nth_field_old(rec, 7, &len);
col_len = mach_read_from_4(field);
ut_a(!strcmp("PREC", dict_field_get_col
(dict_index_get_nth_field(sys_index, 8))->name));
ut_a(name_of_col_is(sys_columns, sys_index, 8, "PREC"));
dict_mem_table_add_col(table, name, mtype, prtype, col_len);
btr_pcur_move_to_next_user_rec(&pcur, &mtr);
......@@ -521,8 +538,7 @@ dict_load_fields(
prefix_len = 0;
}
ut_a(!strcmp("COL_NAME", dict_field_get_col
(dict_index_get_nth_field(sys_index, 4))->name));
ut_a(name_of_col_is(sys_fields, sys_index, 4, "COL_NAME"));
field = rec_get_nth_field_old(rec, 4, &len);
......@@ -626,8 +642,7 @@ dict_load_indexes(
ut_ad(len == 8);
id = mach_read_from_8(field);
ut_a(!strcmp("NAME", dict_field_get_col
(dict_index_get_nth_field(sys_index, 4))->name));
ut_a(name_of_col_is(sys_indexes, sys_index, 4, "NAME"));
field = rec_get_nth_field_old(rec, 4, &name_len);
name_buf = mem_heap_strdupl(heap, (char*) field, name_len);
......@@ -641,8 +656,7 @@ dict_load_indexes(
field = rec_get_nth_field_old(rec, 7, &len);
space = mach_read_from_4(field);
ut_a(!strcmp("PAGE_NO", dict_field_get_col
(dict_index_get_nth_field(sys_index, 8))->name));
ut_a(name_of_col_is(sys_indexes, sys_index, 8, "PAGE_NO"));
field = rec_get_nth_field_old(rec, 8, &len);
page_no = mach_read_from_4(field);
......@@ -780,8 +794,7 @@ err_exit:
goto err_exit;
}
ut_a(!strcmp("SPACE", dict_field_get_col
(dict_index_get_nth_field(sys_index, 9))->name));
ut_a(name_of_col_is(sys_tables, sys_index, 9, "SPACE"));
field = rec_get_nth_field_old(rec, 9, &len);
space = mach_read_from_4(field);
......@@ -814,8 +827,7 @@ err_exit:
}
}
ut_a(!strcmp("N_COLS", dict_field_get_col
(dict_index_get_nth_field(sys_index, 4))->name));
ut_a(name_of_col_is(sys_tables, sys_index, 4, "N_COLS"));
field = rec_get_nth_field_old(rec, 4, &len);
n_cols = mach_read_from_4(field);
......@@ -832,8 +844,7 @@ err_exit:
table->ibd_file_missing = ibd_file_missing;
ut_a(!strcmp("ID", dict_field_get_col
(dict_index_get_nth_field(sys_index, 3))->name));
ut_a(name_of_col_is(sys_tables, sys_index, 3, "ID"));
field = rec_get_nth_field_old(rec, 3, &len);
table->id = mach_read_from_8(field);
......
......@@ -1146,7 +1146,7 @@ ibuf_dummy_index_add_col(
dtype_get_mtype(type),
dtype_get_prtype(type),
dtype_get_len(type));
dict_index_add_col(index,
dict_index_add_col(index, index->table,
dict_table_get_nth_col(index->table, i), len);
}
/************************************************************************
......@@ -1164,6 +1164,11 @@ ibuf_dummy_index_free(
dict_mem_table_free(table);
}
void
dict_index_print_low(
/*=================*/
dict_index_t* index); /* in: index */
/*************************************************************************
Builds the entry to insert into a non-clustered index when we have the
corresponding record in an ibuf index. */
......
......@@ -363,6 +363,17 @@ dict_table_get_index_noninline(
dict_table_t* table, /* in: table */
const char* name); /* in: index name */
/**************************************************************************
Returns a column's name. */
const char*
dict_table_get_col_name(
/*====================*/
/* out: column name. NOTE: not guaranteed to
stay valid if table is modified in any way
(columns added, etc.). */
dict_table_t* table, /* in: table */
ulint i); /* in: column number */
/**************************************************************************
Prints a table definition. */
void
......@@ -702,6 +713,7 @@ void
dict_index_add_col(
/*===============*/
dict_index_t* index, /* in: index */
dict_table_t* table, /* in: table */
dict_col_t* col, /* in: column */
ulint prefix_len); /* in: column prefix length */
/***********************************************************************
......
......@@ -547,8 +547,10 @@ mlog_parse_index(
? DATA_BINARY : DATA_FIXBINARY,
len & 0x8000 ? DATA_NOT_NULL : 0,
len & 0x7fff);
dict_index_add_col
(ind, dict_table_get_nth_col(table, i), 0);
dict_index_add_col(ind, table,
dict_table_get_nth_col(table, i),
0);
}
ptr += 2;
}
......
......@@ -450,7 +450,6 @@ pars_resolve_exp_columns(
sym_node_t* sym_node;
dict_table_t* table;
sym_node_t* t_node;
dict_col_t* col;
ulint n_cols;
ulint i;
......@@ -490,10 +489,12 @@ pars_resolve_exp_columns(
n_cols = dict_table_get_n_cols(table);
for (i = 0; i < n_cols; i++) {
col = dict_table_get_nth_col(table, i);
dict_col_t* col = dict_table_get_nth_col(table, i);
const char* col_name = dict_table_get_col_name(
table, i);
if ((sym_node->name_len == ut_strlen(col->name))
&& (0 == ut_memcmp(sym_node->name, col->name,
if ((sym_node->name_len == ut_strlen(col_name))
&& (0 == ut_memcmp(sym_node->name, col_name,
sym_node->name_len))) {
/* Found */
sym_node->resolved = TRUE;
......@@ -592,7 +593,6 @@ pars_select_all_columns(
sym_node_t* col_node;
sym_node_t* table_node;
dict_table_t* table;
dict_col_t* col;
ulint i;
select_node->select_list = NULL;
......@@ -603,15 +603,15 @@ pars_select_all_columns(
table = table_node->table;
for (i = 0; i < dict_table_get_n_user_cols(table); i++) {
col = dict_table_get_nth_col(table, i);
const char* col_name = dict_table_get_col_name(
table, i);
col_node = sym_tab_add_id(pars_sym_tab_global,
(byte*)col->name,
ut_strlen(col->name));
select_node->select_list
= que_node_list_add_last
(select_node->select_list, col_node);
(byte*)col_name,
ut_strlen(col_name));
select_node->select_list = que_node_list_add_last(
select_node->select_list, col_node);
}
table_node = que_node_get_next(table_node);
......
......@@ -1782,9 +1782,8 @@ row_create_table_for_mysql(
/* Check that no reserved column names are used. */
for (i = 0; i < dict_table_get_n_user_cols(table); i++) {
dict_col_t* col = dict_table_get_nth_col(table, i);
if (dict_col_name_is_reserved(col->name)) {
if (dict_col_name_is_reserved(
dict_table_get_col_name(table, i))) {
dict_mem_table_free(table);
trx_commit_for_mysql(trx);
......
......@@ -903,7 +903,7 @@ srv_init(void)
srv_sys->dummy_ind1 = dict_mem_index_create
("SYS_DUMMY1", "SYS_DUMMY1", DICT_HDR_SPACE, 0, 1);
dict_index_add_col(srv_sys->dummy_ind1,
dict_index_add_col(srv_sys->dummy_ind1, table,
dict_table_get_nth_col(table, 0), 0);
srv_sys->dummy_ind1->table = table;
/* create dummy table and index for new-style infimum and supremum */
......@@ -913,7 +913,7 @@ srv_init(void)
DATA_ENGLISH | DATA_NOT_NULL, 8);
srv_sys->dummy_ind2 = dict_mem_index_create
("SYS_DUMMY2", "SYS_DUMMY2", DICT_HDR_SPACE, 0, 1);
dict_index_add_col(srv_sys->dummy_ind2,
dict_index_add_col(srv_sys->dummy_ind2, table,
dict_table_get_nth_col(table, 0), 0);
srv_sys->dummy_ind2->table = 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