Commit 79644bdb authored by marko's avatar marko

dict_col_t: Copy the fields of "dtype_t type" directly to this structure,

so that all integer fields can be packed into 64 bits.  (Bug #20877)

dtype_t: Change the type of all bit-fields to unsigned.

dict_table_get_nth_col(), dict_table_get_sys_col_noninline(),
dict_table_get_sys_col(), dict_field_get_col(): Return const
dict_col_t*, so that changes to dict_col_t can be detected more
easily.  Add const to many dict_col_t* declarations.

dict_index_get_nth_type(): Replace with dict_index_get_nth_col().

dict_col_get_type(): Replace with dict_col_copy_type().

dict_col_get_min_size(), dict_col_get_max_size(), dict_col_get_fixed_size(),
dict_col_get_sql_null_size(): New functions.

dtype_get_at_most_n_mbchars(): Replace the parameter dtype
with the parameters prtype, mbminlen, mbmaxlen.

dtype_get_pad_char(), cmp_data_data(), cmp_data_data_slow(),
cmp_whole_field(): Replace the dtype_t* parameter with the ulint
parameters mtype, prtype.

dtype_copy(): Add a const qualifier to type2 (the one being copied from).

dtype_set_mblen(): Replaced with dtype_get_mblen().

dtype_get_fixed_size_low(), dtype_get_min_size_low(),
dtype_get_fixed_max_low(): Replace dtype_get_fixed_size(),
dtype_get_min_size(), and dtype_get_max_size().  These are used by the
dict_col_get_{fixed,min,max}_size() functions.

cmp_types_are_equal(): Replace with cmp_cols_are_equal().

dict_table_get_col_name(): Add a const qualifier parameter to the
parameter "table".

dtype_binary, dtype_binary_val: Remove.

dtype_is_fixed_size(): Remove.
parent 0b25b850
......@@ -2564,8 +2564,8 @@ btr_index_rec_validate(
offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, &heap);
for (i = 0; i < n; i++) {
dtype_t* type = dict_index_get_nth_type(index, i);
ulint fixed_size = dtype_get_fixed_size(type);
ulint fixed_size = dict_col_get_fixed_size(
dict_index_get_nth_col(index, i));
rec_get_nth_field(rec, offsets, i, &len);
......@@ -2584,8 +2584,7 @@ btr_index_rec_validate(
fprintf(stderr,
"InnoDB: field %lu len is %lu,"
" should be %lu\n",
(ulong) i, (ulong) len,
(ulong) dtype_get_fixed_size(type));
(ulong) i, (ulong) len, (ulong) fixed_size);
if (dump_on_error) {
buf_page_print(page);
......
......@@ -40,9 +40,6 @@ charset-collation code for them. */
ulint data_mysql_default_charset_coll = 99999999;
dtype_t dtype_binary_val = {DATA_BINARY, 0, 0, 0, 0};
dtype_t* dtype_binary = &dtype_binary_val;
/*************************************************************************
Determine how many bytes the first n characters of the given string occupy.
If the string is shorter than n characters, returns the number of bytes
......@@ -53,7 +50,11 @@ dtype_get_at_most_n_mbchars(
/*========================*/
/* out: length of the prefix,
in bytes */
const dtype_t* dtype, /* in: data type */
ulint prtype, /* in: precise type */
ulint mbminlen, /* in: minimum length of a
multi-byte character */
ulint mbmaxlen, /* in: maximum length of a
multi-byte character */
ulint prefix_len, /* in: length of the requested
prefix, in characters, multiplied by
dtype_get_mbmaxlen(dtype) */
......@@ -63,12 +64,12 @@ dtype_get_at_most_n_mbchars(
{
#ifndef UNIV_HOTBACKUP
ut_a(data_len != UNIV_SQL_NULL);
ut_ad(!dtype->mbmaxlen || !(prefix_len % dtype->mbmaxlen));
ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));
if (dtype->mbminlen != dtype->mbmaxlen) {
ut_a(!(prefix_len % dtype->mbmaxlen));
return(innobase_get_at_most_n_mbchars
(dtype_get_charset_coll(dtype->prtype),
if (mbminlen != mbmaxlen) {
ut_a(!(prefix_len % mbmaxlen));
return(innobase_get_at_most_n_mbchars(
dtype_get_charset_coll(prtype),
prefix_len, data_len, str));
}
......@@ -291,36 +292,3 @@ dtype_print(
fprintf(stderr, " len %lu", (ulong) len);
}
/***************************************************************************
Returns the maximum size of a data type. Note: types in system tables may be
incomplete and return incorrect information. */
ulint
dtype_get_max_size(
/*===============*/
/* out: maximum size (ULINT_MAX for
unbounded types) */
const dtype_t* type) /* in: type */
{
switch (type->mtype) {
case DATA_SYS:
case DATA_CHAR:
case DATA_FIXBINARY:
case DATA_INT:
case DATA_FLOAT:
case DATA_DOUBLE:
case DATA_MYSQL:
case DATA_VARCHAR:
case DATA_BINARY:
case DATA_DECIMAL:
case DATA_VARMYSQL:
return(type->len);
case DATA_BLOB:
return(ULINT_MAX);
default:
ut_error;
}
return(ULINT_MAX);
}
......@@ -124,11 +124,11 @@ dict_create_sys_columns_tuple(
mem_heap_t* heap) /* in: memory heap from which the memory for
the built tuple is allocated */
{
dict_table_t* sys_columns;
dtuple_t* entry;
dict_col_t* column;
dfield_t* dfield;
byte* ptr;
dict_table_t* sys_columns;
dtuple_t* entry;
const dict_col_t* column;
dfield_t* dfield;
byte* ptr;
const char* col_name;
ut_ad(table && heap);
......@@ -162,21 +162,21 @@ dict_create_sys_columns_tuple(
dfield = dtuple_get_nth_field(entry, 3);
ptr = mem_heap_alloc(heap, 4);
mach_write_to_4(ptr, (column->type).mtype);
mach_write_to_4(ptr, column->mtype);
dfield_set_data(dfield, ptr, 4);
/* 6: PRTYPE -------------------------*/
dfield = dtuple_get_nth_field(entry, 4);
ptr = mem_heap_alloc(heap, 4);
mach_write_to_4(ptr, (column->type).prtype);
mach_write_to_4(ptr, column->prtype);
dfield_set_data(dfield, ptr, 4);
/* 7: LEN ----------------------------*/
dfield = dtuple_get_nth_field(entry, 5);
ptr = mem_heap_alloc(heap, 4);
mach_write_to_4(ptr, (column->type).len);
mach_write_to_4(ptr, column->len);
dfield_set_data(dfield, ptr, 4);
/* 8: PREC ---------------------------*/
......@@ -224,8 +224,7 @@ dict_build_table_def_step(
row_len = 0;
for (i = 0; i < table->n_def; i++) {
row_len += dtype_get_min_size(dict_col_get_type
(&table->cols[i]));
row_len += dict_col_get_min_size(&table->cols[i]);
}
if (row_len > BTR_PAGE_MAX_REC_SIZE) {
return(DB_TOO_BIG_RECORD);
......
......@@ -192,8 +192,8 @@ static
void
dict_col_print_low(
/*===============*/
dict_table_t* table, /* in: table */
dict_col_t* col); /* in: column */
const dict_table_t* table, /* in: table */
const dict_col_t* col); /* in: column */
/**************************************************************************
Prints an index data. */
static
......@@ -325,15 +325,27 @@ dict_table_decrement_handle_count(
mutex_exit(&(dict_sys->mutex));
}
/*************************************************************************
Gets the column data type. */
void
dict_col_copy_type_noninline(
/*=========================*/
const dict_col_t* col, /* in: column */
dtype_t* type) /* out: data type */
{
return(dict_col_copy_type(col, type));
}
/************************************************************************
Gets the nth column of a table. */
dict_col_t*
const dict_col_t*
dict_table_get_nth_col_noninline(
/*=============================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint pos) /* in: position of column */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint pos) /* in: position of column */
{
return(dict_table_get_nth_col(table, pos));
}
......@@ -381,11 +393,12 @@ 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 */
/* out: column name. NOTE: not
guaranteed to stay valid if
table is modified in any way
(columns added, etc.). */
const dict_table_t* table, /* in: table */
ulint i) /* in: column number */
{
ut_ad(table);
ut_ad(i < table->n_def);
......@@ -536,10 +549,10 @@ dict_index_get_nth_col_pos(
dict_index_t* index, /* in: index */
ulint n) /* in: column number */
{
dict_field_t* field;
dict_col_t* col;
ulint pos;
ulint n_fields;
const dict_field_t* field;
const dict_col_t* col;
ulint pos;
ulint n_fields;
ut_ad(index);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
......@@ -576,10 +589,10 @@ dict_index_contains_col_or_prefix(
dict_index_t* index, /* in: index */
ulint n) /* in: column number */
{
dict_field_t* field;
dict_col_t* col;
ulint pos;
ulint n_fields;
const dict_field_t* field;
const dict_col_t* col;
ulint pos;
ulint n_fields;
ut_ad(index);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
......@@ -723,11 +736,11 @@ dict_table_col_in_clustered_key(
dict_table_t* table, /* in: table */
ulint n) /* in: column number */
{
dict_index_t* index;
dict_field_t* field;
dict_col_t* col;
ulint pos;
ulint n_fields;
dict_index_t* index;
const dict_field_t* field;
const dict_col_t* col;
ulint pos;
ulint n_fields;
ut_ad(table);
......@@ -901,8 +914,8 @@ dict_table_add_to_cache(
row_len = 0;
for (i = 0; i < table->n_def; i++) {
ulint col_len = dtype_get_max_size
(dict_col_get_type(dict_table_get_nth_col(table, i)));
ulint col_len = dict_col_get_max_size(
dict_table_get_nth_col(table, i));
row_len += col_len;
......@@ -1349,7 +1362,6 @@ dict_index_add_to_cache(
ulint page_no)/* in: root page number of the index */
{
dict_index_t* new_index;
dict_field_t* field;
ulint n_ord;
ulint i;
......@@ -1412,9 +1424,7 @@ dict_index_add_to_cache(
for (i = 0; i < n_ord; i++) {
field = dict_index_get_nth_field(new_index, i);
dict_field_get_col(field)->ord_part = 1;
dict_index_get_nth_field(new_index, i)->col->ord_part = 1;
}
new_index->page = page_no;
......@@ -1497,7 +1507,8 @@ dict_index_find_cols(
for (j = 0; j < table->n_cols; j++) {
if (!strcmp(dict_table_get_col_name(table, j),
field->name)) {
field->col = dict_table_get_nth_col(table, j);
field->col = (dict_col_t*)
dict_table_get_nth_col(table, j);
goto found;
}
......@@ -1532,7 +1543,7 @@ dict_index_add_col(
field = dict_index_get_nth_field(index, index->n_def - 1);
field->col = col;
field->fixed_len = dtype_get_fixed_size(&col->type);
field->fixed_len = dict_col_get_fixed_size(col);
if (prefix_len && field->fixed_len > prefix_len) {
field->fixed_len = prefix_len;
......@@ -1546,7 +1557,7 @@ dict_index_add_col(
field->fixed_len = 0;
}
if (!(dtype_get_prtype(&col->type) & DATA_NOT_NULL)) {
if (!(col->prtype & DATA_NOT_NULL)) {
index->n_nullable++;
}
}
......@@ -1597,12 +1608,10 @@ dict_index_copy_types(
for (i = 0; i < n_fields; i++) {
dict_field_t* ifield;
dtype_t* dfield_type;
dtype_t* type;
ifield = dict_index_get_nth_field(index, i);
dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
type = dict_col_get_type(dict_field_get_col(ifield));
*dfield_type = *type;
dict_col_copy_type(dict_field_get_col(ifield), dfield_type);
if (UNIV_UNLIKELY(ifield->prefix_len)) {
dfield_type->len = ifield->prefix_len;
}
......@@ -1619,15 +1628,13 @@ dict_table_copy_types(
dict_table_t* table) /* in: index */
{
dtype_t* dfield_type;
dtype_t* type;
ulint i;
for (i = 0; i < dtuple_get_n_fields(tuple); i++) {
dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
type = dict_col_get_type(dict_table_get_nth_col(table, i));
*dfield_type = *type;
dict_col_copy_type(dict_table_get_nth_col(table, i),
dfield_type);
}
}
......@@ -1646,7 +1653,6 @@ dict_index_build_internal_clust(
{
dict_index_t* new_index;
dict_field_t* field;
dict_col_t* col;
ulint fixed_size;
ulint trx_id_pos;
ulint i;
......@@ -1708,26 +1714,26 @@ dict_index_build_internal_clust(
#endif
if (!(index->type & DICT_UNIQUE)) {
dict_index_add_col(new_index, table,
dict_index_add_col(new_index, table, (dict_col_t*)
dict_table_get_sys_col(
table, DATA_ROW_ID),
0);
trx_id_pos++;
}
dict_index_add_col(new_index, table,
dict_index_add_col(new_index, table, (dict_col_t*)
dict_table_get_sys_col(table, DATA_TRX_ID),
0);
dict_index_add_col(new_index, table,
dict_index_add_col(new_index, table, (dict_col_t*)
dict_table_get_sys_col(table,
DATA_ROLL_PTR),
0);
for (i = 0; i < trx_id_pos; i++) {
fixed_size = dtype_get_fixed_size
(dict_index_get_nth_type(new_index, i));
fixed_size = dict_col_get_fixed_size(
dict_index_get_nth_col(new_index, i));
if (fixed_size == 0) {
new_index->trx_id_offset = 0;
......@@ -1769,8 +1775,9 @@ dict_index_build_internal_clust(
there */
for (i = 0; i + DATA_N_SYS_COLS < (ulint) table->n_cols; i++) {
col = dict_table_get_nth_col(table, i);
ut_ad(col->type.mtype != DATA_SYS);
dict_col_t* col = (dict_col_t*)
dict_table_get_nth_col(table, i);
ut_ad(col->mtype != DATA_SYS);
if (!indexed[col->ind]) {
dict_index_add_col(new_index, table, col, 0);
......@@ -2031,10 +2038,11 @@ dict_foreign_find_index(
break;
}
if (types_idx && !cmp_types_are_equal
(dict_index_get_nth_type(index, i),
dict_index_get_nth_type(types_idx, i),
check_charsets)) {
if (types_idx && !cmp_cols_are_equal(
dict_index_get_nth_col(index, i),
dict_index_get_nth_col(types_idx,
i),
check_charsets)) {
break;
}
......@@ -2421,15 +2429,15 @@ static
const char*
dict_scan_col(
/*==========*/
/* out: scanned to */
struct charset_info_st* cs,/* in: the character set of ptr */
const char* ptr, /* in: scanned to */
ibool* success,/* out: TRUE if success */
dict_table_t* table, /* in: table in which the column is */
dict_col_t** column, /* out: pointer to column if success */
mem_heap_t* heap, /* in: heap where to allocate the name */
const char** name) /* out,own: the column name; NULL if no name
was scannable */
/* out: scanned to */
struct charset_info_st* cs, /* in: the character set of ptr */
const char* ptr, /* in: scanned to */
ibool* success,/* out: TRUE if success */
dict_table_t* table, /* in: table in which the column is */
const dict_col_t** column, /* out: pointer to column if success */
mem_heap_t* heap, /* in: heap where to allocate */
const char** name) /* out,own: the column name;
NULL if no name was scannable */
{
ulint i;
......@@ -2794,7 +2802,7 @@ dict_create_foreign_constraints_low(
ibool is_on_delete;
ulint n_on_deletes;
ulint n_on_updates;
dict_col_t* columns[500];
const dict_col_t*columns[500];
const char* column_names[500];
const char* referenced_table_name;
......@@ -3216,8 +3224,7 @@ dict_create_foreign_constraints_low(
}
for (j = 0; j < foreign->n_fields; j++) {
if ((dict_index_get_nth_type
(foreign->foreign_index, j)->prtype)
if ((dict_index_get_nth_col(foreign->foreign_index, j)->prtype)
& DATA_NOT_NULL) {
/* It is not sensible to define SET NULL
......@@ -3732,15 +3739,17 @@ dict_index_calc_min_rec_len(
ulint nullable = 0;
sum = REC_N_NEW_EXTRA_BYTES;
for (i = 0; i < dict_index_get_n_fields(index); i++) {
dtype_t*t = dict_index_get_nth_type(index, i);
ulint size = dtype_get_fixed_size(t);
const dict_col_t* col
= dict_index_get_nth_col(index, i);
ulint size = dict_col_get_fixed_size(col);
sum += size;
if (!size) {
size = dtype_get_len(t);
size = col->len;
sum += size < 128 ? 1 : 2;
}
if (!(dtype_get_prtype(t) & DATA_NOT_NULL))
if (!(col->prtype & DATA_NOT_NULL)) {
nullable++;
}
}
/* round the NULL flags up to full bytes */
......@@ -3750,7 +3759,8 @@ dict_index_calc_min_rec_len(
}
for (i = 0; i < dict_index_get_n_fields(index); i++) {
sum += dtype_get_fixed_size(dict_index_get_nth_type(index, i));
sum += dict_col_get_fixed_size(
dict_index_get_nth_col(index, i));
}
if (sum > 127) {
......@@ -4002,20 +4012,20 @@ static
void
dict_col_print_low(
/*===============*/
dict_table_t* table, /* in: table */
dict_col_t* col) /* in: column */
const dict_table_t* table, /* in: table */
const dict_col_t* col) /* in: column */
{
dtype_t* type;
dtype_t type;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
#endif /* UNIV_SYNC_DEBUG */
type = dict_col_get_type(col);
dict_col_copy_type(col, &type);
fprintf(stderr, "%s: ", dict_table_get_col_name(table,
dict_col_get_no(col)));
dtype_print(type);
dtype_print(&type);
}
/**************************************************************************
......
......@@ -1295,7 +1295,8 @@ dict_load_foreigns(
following call does the comparison in the latin1_swedish_ci
charset-collation, in a case-insensitive way. */
if (0 != cmp_data_data(dfield_get_type(dfield),
if (0 != cmp_data_data(dfield_get_type(dfield)->mtype,
dfield_get_type(dfield)->prtype,
dfield_get_data(dfield), dfield_get_len(dfield),
field, len)) {
......
......@@ -123,22 +123,28 @@ dict_mem_table_add_col(
ulint len) /* in: precision */
{
dict_col_t* col;
dtype_t* type;
ulint mbminlen;
ulint mbmaxlen;
ut_ad(table && name);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
table->n_def++;
col = dict_table_get_nth_col(table, table->n_def - 1);
col = (dict_col_t*) dict_table_get_nth_col(table, table->n_def - 1);
col->ind = table->n_def - 1;
col->name = mem_heap_strdup(table->heap, name);
col->ord_part = 0;
type = dict_col_get_type(col);
col->mtype = mtype;
col->prtype = prtype;
col->len = len;
dtype_set(type, mtype, prtype, len);
dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen);
col->mbminlen = mbminlen;
col->mbmaxlen = mbmaxlen;
}
/**************************************************************************
......
......@@ -3195,7 +3195,7 @@ build_template(
mysql_prefix_len = templ->mysql_col_offset
+ templ->mysql_col_len;
}
templ->type = index->table->cols[i].type.mtype;
templ->type = index->table->cols[i].mtype;
templ->mysql_type = (ulint)field->type();
if (templ->mysql_type == DATA_MYSQL_TRUE_VARCHAR) {
......@@ -3204,10 +3204,10 @@ build_template(
}
templ->charset = dtype_get_charset_coll_noninline(
index->table->cols[i].type.prtype);
templ->mbminlen = index->table->cols[i].type.mbminlen;
templ->mbmaxlen = index->table->cols[i].type.mbmaxlen;
templ->is_unsigned = index->table->cols[i].type.prtype
index->table->cols[i].prtype);
templ->mbminlen = index->table->cols[i].mbminlen;
templ->mbmaxlen = index->table->cols[i].mbmaxlen;
templ->is_unsigned = index->table->cols[i].prtype
& DATA_UNSIGNED;
if (templ->type == DATA_BLOB) {
prebuilt->templ_contains_blob = TRUE;
......@@ -3528,7 +3528,7 @@ calc_row_difference(
field_mysql_type = field->type();
col_type = prebuilt->table->cols[i].type.mtype;
col_type = prebuilt->table->cols[i].mtype;
switch (col_type) {
......@@ -3583,7 +3583,8 @@ calc_row_difference(
/* Let us use a dummy dfield to make the conversion
from the MySQL column format to the InnoDB format */
dfield.type = (prebuilt->table->cols + i)->type;
dict_col_copy_type_noninline(prebuilt->table->cols + i,
&dfield.type);
if (n_len != UNIV_SQL_NULL) {
buf = row_mysql_store_col_in_innobase_format(
......
......@@ -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, index->table,
dict_index_add_col(index, index->table, (dict_col_t*)
dict_table_get_nth_col(index->table, i), len);
}
/************************************************************************
......
......@@ -18,10 +18,6 @@ extern ulint data_mysql_default_charset_coll;
/* SQL data type struct */
typedef struct dtype_struct dtype_t;
/* This variable is initialized as the standard binary variable length
data type */
extern dtype_t* dtype_binary;
/*-------------------------------------------*/
/* The 'MAIN TYPE' of a column */
#define DATA_VARCHAR 1 /* character varying of the
......@@ -172,7 +168,11 @@ dtype_get_at_most_n_mbchars(
/*========================*/
/* out: length of the prefix,
in bytes */
const dtype_t* dtype, /* in: data type */
ulint prtype, /* in: precise type */
ulint mbminlen, /* in: minimum length of a
multi-byte character */
ulint mbmaxlen, /* in: maximum length of a
multi-byte character */
ulint prefix_len, /* in: length of the requested
prefix, in characters, multiplied by
dtype_get_mbmaxlen(dtype) */
......@@ -228,7 +228,7 @@ void
dtype_copy(
/*=======*/
dtype_t* type1, /* in: type struct to copy to */
dtype_t* type2); /* in: type struct to copy from */
const dtype_t* type2); /* in: type struct to copy from */
/*************************************************************************
Gets the SQL main data type. */
UNIV_INLINE
......@@ -244,6 +244,18 @@ dtype_get_prtype(
/*=============*/
dtype_t* type);
/*************************************************************************
Compute the mbminlen and mbmaxlen members of a data type structure. */
UNIV_INLINE
void
dtype_get_mblen(
/*============*/
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type (and collation) */
ulint* mbminlen, /* out: minimum length of a
multi-byte character */
ulint* mbmaxlen); /* out: maximum length of a
multi-byte character */
/*************************************************************************
Gets the MySQL charset-collation code for MySQL string types. */
ulint
......@@ -300,50 +312,52 @@ dtype_get_pad_char(
/*===============*/
/* out: padding character code, or
ULINT_UNDEFINED if no padding specified */
const dtype_t* type); /* in: type */
ulint mtype, /* in: main type */
ulint prtype); /* in: precise type */
/***************************************************************************
Returns the size of a fixed size data type, 0 if not a fixed size type. */
UNIV_INLINE
ulint
dtype_get_fixed_size(
/*=================*/
dtype_get_fixed_size_low(
/*=====================*/
/* out: fixed size, or 0 */
dtype_t* type); /* in: type */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
ulint len, /* in: length */
ulint mbminlen, /* in: minimum length of a multibyte char */
ulint mbmaxlen); /* in: maximum length of a multibyte char */
/***************************************************************************
Returns the minimum size of a data type. */
UNIV_INLINE
ulint
dtype_get_min_size(
/*===============*/
dtype_get_min_size_low(
/*===================*/
/* out: minimum size */
const dtype_t* type); /* in: type */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
ulint len, /* in: length */
ulint mbminlen, /* in: minimum length of a multibyte char */
ulint mbmaxlen); /* in: maximum length of a multibyte char */
/***************************************************************************
Returns the maximum size of a data type. Note: types in system tables may be
incomplete and return incorrect information. */
UNIV_INLINE
ulint
dtype_get_max_size(
/*===============*/
/* out: maximum size (ULINT_MAX for
unbounded types) */
const dtype_t* type); /* in: type */
dtype_get_max_size_low(
/*===================*/
/* out: maximum size */
ulint mtype, /* in: main type */
ulint len); /* in: length */
/***************************************************************************
Returns a stored SQL NULL size for a type. For fixed length types it is
the fixed length of the type, otherwise 0. */
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a type.
For fixed length types it is the fixed length of the type, otherwise 0. */
UNIV_INLINE
ulint
dtype_get_sql_null_size(
/*====================*/
/* out: SQL null storage size */
dtype_t* type); /* in: type */
/***************************************************************************
Returns TRUE if a type is of a fixed size. */
UNIV_INLINE
ibool
dtype_is_fixed_size(
/*================*/
/* out: TRUE if fixed size */
dtype_t* type); /* in: type */
/* out: SQL null storage size
in ROW_FORMAT=REDUNDANT */
const dtype_t* type); /* in: type */
/**************************************************************************
Reads to a type the stored information which determines its alphabetical
ordering and the storage size of an SQL NULL value. */
......@@ -403,24 +417,30 @@ dtype_new_read_for_order_and_null_size()
sym_tab_add_null_lit() */
struct dtype_struct{
ulint mtype:8; /* main data type */
ulint prtype:24; /* precise type; MySQL data type, charset code,
flags to indicate nullability, signedness,
whether this is a binary string, whether this
is a true VARCHAR where MySQL uses 2 bytes to
store the length */
unsigned mtype:8; /* main data type */
unsigned prtype:24; /* precise type; MySQL data
type, charset code, flags to
indicate nullability,
signedness, whether this is a
binary string, whether this is
a true VARCHAR where MySQL
uses 2 bytes to store the length */
/* the remaining fields do not affect alphabetical ordering: */
ulint mbminlen:2; /* minimum length of a character, in bytes */
ulint mbmaxlen:3; /* maximum length of a character, in bytes */
ulint len:16; /* length; for MySQL data this is
field->pack_length(), except that for a
>= 5.0.3 type true VARCHAR this is the
maximum byte length of the string data
(in addition to the string, MySQL uses 1 or
2 bytes to store the string length) */
unsigned len:16; /* length; for MySQL data this
is field->pack_length(),
except that for a >= 5.0.3
type true VARCHAR this is the
maximum byte length of the
string data (in addition to
the string, MySQL uses 1 or 2
bytes to store the string length) */
unsigned mbminlen:2; /* minimum length of a
character, in bytes */
unsigned mbmaxlen:3; /* maximum length of a
character, in bytes */
};
#ifndef UNIV_NONINL
......
......@@ -48,39 +48,52 @@ dtype_get_mysql_type(
}
/*************************************************************************
Sets the mbminlen and mbmaxlen members of a data type structure. */
Compute the mbminlen and mbmaxlen members of a data type structure. */
UNIV_INLINE
void
dtype_set_mblen(
dtype_get_mblen(
/*============*/
dtype_t* type) /* in/out: type struct */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type (and collation) */
ulint* mbminlen, /* out: minimum length of a
multi-byte character */
ulint* mbmaxlen) /* out: maximum length of a
multi-byte character */
{
ut_ad(type);
if (dtype_is_string_type(type->mtype)) {
if (dtype_is_string_type(mtype)) {
#ifndef UNIV_HOTBACKUP
ulint mbminlen, mbmaxlen;
innobase_get_cset_width(dtype_get_charset_coll(type->prtype),
&mbminlen, &mbmaxlen);
ut_ad(mbminlen <= mbmaxlen);
type->mbminlen = mbminlen;
type->mbmaxlen = mbmaxlen;
innobase_get_cset_width(dtype_get_charset_coll(prtype),
mbminlen, mbmaxlen);
ut_ad(*mbminlen <= *mbmaxlen);
ut_ad(*mbminlen <= 2); /* cf. the bit-field in dtype_t */
ut_ad(*mbmaxlen < 1 << 3); /* cf. the bit-field in dtype_t */
#else /* !UNIV_HOTBACKUP */
#ifdef notdefined
printf("ibbackup: DEBUG: type->mtype=%lu, type->prtype=%lu\n",
type->mtype, type->prtype);
#endif
ut_a(type->mtype <= DATA_BINARY);
#ifdef notdefined
ut_a(type->prtype == (DATA_BINARY | DATA_NOT_NULL));
#endif
type->mbminlen = type->mbmaxlen = 1;
ut_a(mtype <= DATA_BINARY);
*mbminlen = *mbmaxlen = 1;
#endif /* !UNIV_HOTBACKUP */
} else {
type->mbminlen = type->mbmaxlen = 0;
*mbminlen = *mbmaxlen = 0;
}
}
/*************************************************************************
Compute the mbminlen and mbmaxlen members of a data type structure. */
UNIV_INLINE
void
dtype_set_mblen(
/*============*/
dtype_t* type) /* in/out: type */
{
ulint mbminlen;
ulint mbmaxlen;
dtype_get_mblen(type->mtype, type->prtype, &mbminlen, &mbmaxlen);
type->mbminlen = mbminlen;
type->mbmaxlen = mbmaxlen;
ut_ad(dtype_validate(type));
}
/*************************************************************************
Sets a data type structure. */
UNIV_INLINE
......@@ -100,7 +113,6 @@ dtype_set(
type->len = len;
dtype_set_mblen(type);
ut_ad(dtype_validate(type));
}
/*************************************************************************
......@@ -110,7 +122,7 @@ void
dtype_copy(
/*=======*/
dtype_t* type1, /* in: type struct to copy to */
dtype_t* type2) /* in: type struct to copy from */
const dtype_t* type2) /* in: type struct to copy from */
{
*type1 = *type2;
......@@ -184,19 +196,20 @@ dtype_get_mbmaxlen(
}
/*************************************************************************
Gets the padding character code for the type. */
Gets the padding character code for a type. */
UNIV_INLINE
ulint
dtype_get_pad_char(
/*===============*/
/* out: padding character code, or
ULINT_UNDEFINED if no padding specified */
const dtype_t* type) /* in: type */
ulint mtype, /* in: main type */
ulint prtype) /* in: precise type */
{
switch (type->mtype) {
switch (mtype) {
case DATA_FIXBINARY:
case DATA_BINARY:
if (UNIV_UNLIKELY(dtype_get_charset_coll(type->prtype)
if (UNIV_UNLIKELY(dtype_get_charset_coll(prtype)
== DATA_MYSQL_BINARY_CHARSET_COLL)) {
/* Starting from 5.0.18, do not pad
VARBINARY or BINARY columns. */
......@@ -212,7 +225,7 @@ dtype_get_pad_char(
return(0x20);
case DATA_BLOB:
if ((type->prtype & DATA_BINARY_TYPE) == 0) {
if (!(prtype & DATA_BINARY_TYPE)) {
return(0x20);
}
/* Fall through */
......@@ -278,7 +291,9 @@ dtype_read_for_order_and_null_size(
dtype_t* type, /* in: type struct */
byte* buf) /* in: buffer for stored type order info */
{
ut_ad(4 == DATA_ORDER_NULL_TYPE_BUF_SIZE);
#if 4 != DATA_ORDER_NULL_TYPE_BUF_SIZE
# error "4 != DATA_ORDER_NULL_TYPE_BUF_SIZE"
#endif
type->mtype = buf[0] & 63;
type->prtype = buf[1];
......@@ -350,27 +365,27 @@ dtype_new_read_for_order_and_null_size(
Returns the size of a fixed size data type, 0 if not a fixed size type. */
UNIV_INLINE
ulint
dtype_get_fixed_size(
/*=================*/
dtype_get_fixed_size_low(
/*=====================*/
/* out: fixed size, or 0 */
dtype_t* type) /* in: type */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
ulint len, /* in: length */
ulint mbminlen, /* in: minimum length of a multibyte char */
ulint mbmaxlen) /* in: maximum length of a multibyte char */
{
ulint mtype;
mtype = dtype_get_mtype(type);
switch (mtype) {
case DATA_SYS:
#ifdef UNIV_DEBUG
switch (type->prtype & DATA_MYSQL_TYPE_MASK) {
switch (prtype & DATA_MYSQL_TYPE_MASK) {
case DATA_ROW_ID:
ut_ad(type->len == DATA_ROW_ID_LEN);
ut_ad(len == DATA_ROW_ID_LEN);
break;
case DATA_TRX_ID:
ut_ad(type->len == DATA_TRX_ID_LEN);
ut_ad(len == DATA_TRX_ID_LEN);
break;
case DATA_ROLL_PTR:
ut_ad(type->len == DATA_ROLL_PTR_LEN);
ut_ad(len == DATA_ROLL_PTR_LEN);
break;
default:
ut_ad(0);
......@@ -382,32 +397,32 @@ dtype_get_fixed_size(
case DATA_INT:
case DATA_FLOAT:
case DATA_DOUBLE:
return(dtype_get_len(type));
return(len);
case DATA_MYSQL:
if (type->prtype & DATA_BINARY_TYPE) {
return(dtype_get_len(type));
if (prtype & DATA_BINARY_TYPE) {
return(len);
} else {
#ifdef UNIV_HOTBACKUP
if (type->mbminlen == type->mbmaxlen) {
return(dtype_get_len(type));
if (mbminlen == mbmaxlen) {
return(len);
}
#else /* UNIV_HOTBACKUP */
/* We play it safe here and ask MySQL for
mbminlen and mbmaxlen. Although
type->mbminlen and type->mbmaxlen are
initialized if and only if type->prtype
mbminlen and mbmaxlen are
initialized if and only if prtype
is (in one of the 3 functions in this file),
it could be that none of these functions
has been called. */
ulint mbminlen, mbmaxlen;
ulint i_mbminlen, i_mbmaxlen;
innobase_get_cset_width
(dtype_get_charset_coll(type->prtype),
&mbminlen, &mbmaxlen);
(dtype_get_charset_coll(prtype),
&i_mbminlen, &i_mbmaxlen);
if (UNIV_UNLIKELY(type->mbminlen != mbminlen)
|| UNIV_UNLIKELY(type->mbmaxlen != mbmaxlen)) {
if (UNIV_UNLIKELY(mbminlen != i_mbminlen)
|| UNIV_UNLIKELY(mbmaxlen != i_mbmaxlen)) {
ut_print_timestamp(stderr);
fprintf(stderr, " InnoDB: "
......@@ -415,13 +430,13 @@ dtype_get_fixed_size(
"mbmaxlen=%lu, "
"type->mbminlen=%lu, "
"type->mbmaxlen=%lu\n",
(ulong) i_mbminlen,
(ulong) i_mbmaxlen,
(ulong) mbminlen,
(ulong) mbmaxlen,
(ulong) type->mbminlen,
(ulong) type->mbmaxlen);
(ulong) mbmaxlen);
}
if (mbminlen == mbmaxlen) {
return(dtype_get_len(type));
return(len);
}
#endif /* !UNIV_HOTBACKUP */
}
......@@ -443,23 +458,27 @@ dtype_get_fixed_size(
Returns the minimum size of a data type. */
UNIV_INLINE
ulint
dtype_get_min_size(
/*===============*/
dtype_get_min_size_low(
/*===================*/
/* out: minimum size */
const dtype_t* type) /* in: type */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
ulint len, /* in: length */
ulint mbminlen, /* in: minimum length of a multibyte char */
ulint mbmaxlen) /* in: maximum length of a multibyte char */
{
switch (type->mtype) {
switch (mtype) {
case DATA_SYS:
#ifdef UNIV_DEBUG
switch (type->prtype & DATA_MYSQL_TYPE_MASK) {
switch (prtype & DATA_MYSQL_TYPE_MASK) {
case DATA_ROW_ID:
ut_ad(type->len == DATA_ROW_ID_LEN);
ut_ad(len == DATA_ROW_ID_LEN);
break;
case DATA_TRX_ID:
ut_ad(type->len == DATA_TRX_ID_LEN);
ut_ad(len == DATA_TRX_ID_LEN);
break;
case DATA_ROLL_PTR:
ut_ad(type->len == DATA_ROLL_PTR_LEN);
ut_ad(len == DATA_ROLL_PTR_LEN);
break;
default:
ut_ad(0);
......@@ -471,58 +490,73 @@ dtype_get_min_size(
case DATA_INT:
case DATA_FLOAT:
case DATA_DOUBLE:
return(type->len);
return(len);
case DATA_MYSQL:
if ((type->prtype & DATA_BINARY_TYPE)
|| type->mbminlen == type->mbmaxlen) {
return(type->len);
if ((prtype & DATA_BINARY_TYPE) || mbminlen == mbmaxlen) {
return(len);
}
/* this is a variable-length character set */
ut_a(type->mbminlen > 0);
ut_a(type->mbmaxlen > type->mbminlen);
ut_a(type->len % type->mbmaxlen == 0);
return(type->len * type->mbminlen / type->mbmaxlen);
ut_a(mbminlen > 0);
ut_a(mbmaxlen > mbminlen);
ut_a(len % mbmaxlen == 0);
return(len * mbminlen / mbmaxlen);
case DATA_VARCHAR:
case DATA_BINARY:
case DATA_DECIMAL:
case DATA_VARMYSQL:
case DATA_BLOB:
return(0);
default: ut_error;
default:
ut_error;
}
return(0);
}
/***************************************************************************
Returns a stored SQL NULL size for a type. For fixed length types it is
the fixed length of the type, otherwise 0. */
Returns the maximum size of a data type. Note: types in system tables may be
incomplete and return incorrect information. */
UNIV_INLINE
ulint
dtype_get_sql_null_size(
/*====================*/
/* out: SQL null storage size */
dtype_t* type) /* in: type */
dtype_get_max_size_low(
/*===================*/
/* out: maximum size */
ulint mtype, /* in: main type */
ulint len) /* in: length */
{
return(dtype_get_fixed_size(type));
switch (mtype) {
case DATA_SYS:
case DATA_CHAR:
case DATA_FIXBINARY:
case DATA_INT:
case DATA_FLOAT:
case DATA_DOUBLE:
case DATA_MYSQL:
case DATA_VARCHAR:
case DATA_BINARY:
case DATA_DECIMAL:
case DATA_VARMYSQL:
return(len);
case DATA_BLOB:
break;
default:
ut_error;
}
return(ULINT_MAX);
}
/***************************************************************************
Returns TRUE if a type is of a fixed size. */
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a type.
For fixed length types it is the fixed length of the type, otherwise 0. */
UNIV_INLINE
ibool
dtype_is_fixed_size(
/*================*/
/* out: TRUE if fixed size */
dtype_t* type) /* in: type */
ulint
dtype_get_sql_null_size(
/*====================*/
/* out: SQL null storage size
in ROW_FORMAT=REDUNDANT */
const dtype_t* type) /* in: type */
{
ulint size;
size = dtype_get_fixed_size(type);
if (size) {
return(TRUE);
}
return(FALSE);
return(dtype_get_fixed_size_low(type->mtype, type->prtype, type->len,
type->mbminlen, type->mbmaxlen) > 0);
}
......@@ -79,17 +79,61 @@ dict_load_space_id_list(void);
/*************************************************************************
Gets the column data type. */
UNIV_INLINE
dtype_t*
dict_col_get_type(
/*==============*/
dict_col_t* col);
void
dict_col_copy_type(
/*===============*/
const dict_col_t* col, /* in: column */
dtype_t* type); /* out: data type */
/*************************************************************************
Gets the column data type. */
void
dict_col_copy_type_noninline(
/*=========================*/
const dict_col_t* col, /* in: column */
dtype_t* type); /* out: data type */
/***************************************************************************
Returns the minimum size of the column. */
UNIV_INLINE
ulint
dict_col_get_min_size(
/*==================*/
/* out: minimum size */
const dict_col_t* col); /* in: column */
/***************************************************************************
Returns the maximum size of the column. */
UNIV_INLINE
ulint
dict_col_get_max_size(
/*==================*/
/* out: maximum size */
const dict_col_t* col); /* in: column */
/***************************************************************************
Returns the size of a fixed size column, 0 if not a fixed size column. */
UNIV_INLINE
ulint
dict_col_get_fixed_size(
/*====================*/
/* out: fixed size, or 0 */
const dict_col_t* col); /* in: column */
/***************************************************************************
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
For fixed length types it is the fixed length of the type, otherwise 0. */
UNIV_INLINE
ulint
dict_col_get_sql_null_size(
/*=======================*/
/* out: SQL null storage size
in ROW_FORMAT=REDUNDANT */
const dict_col_t* col); /* in: column */
/*************************************************************************
Gets the column number. */
UNIV_INLINE
ulint
dict_col_get_no(
/*============*/
dict_col_t* col);
const dict_col_t* col);
/*************************************************************************
Gets the column position in the clustered index. */
UNIV_INLINE
......@@ -368,11 +412,12 @@ 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 */
/* out: column name. NOTE: not
guaranteed to stay valid if
table is modified in any way
(columns added, etc.). */
const dict_table_t* table, /* in: table */
ulint i); /* in: column number */
/**************************************************************************
Prints a table definition. */
......@@ -488,30 +533,30 @@ dict_table_get_n_cols(
/************************************************************************
Gets the nth column of a table. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_table_get_nth_col(
/*===================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint pos); /* in: position of column */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint pos); /* in: position of column */
/************************************************************************
Gets the nth column of a table. */
dict_col_t*
const dict_col_t*
dict_table_get_nth_col_noninline(
/*=============================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint pos); /* in: position of column */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint pos); /* in: position of column */
/************************************************************************
Gets the given system column of a table. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_table_get_sys_col(
/*===================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint sys); /* in: DATA_ROW_ID, ... */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint sys); /* in: DATA_ROW_ID, ... */
/************************************************************************
Gets the given system column number of a table. */
UNIV_INLINE
......@@ -633,23 +678,23 @@ dict_index_get_nth_field(
dict_index_t* index, /* in: index */
ulint pos); /* in: position of field */
/************************************************************************
Gets pointer to the nth field data type in an index. */
Gets pointer to the nth column in an index. */
UNIV_INLINE
dtype_t*
dict_index_get_nth_type(
/*====================*/
/* out: data type */
dict_index_t* index, /* in: index */
ulint pos); /* in: position of the field */
const dict_col_t*
dict_index_get_nth_col(
/*===================*/
/* out: column */
const dict_index_t* index, /* in: index */
ulint pos); /* in: position of the field */
/************************************************************************
Gets the column number of the nth field in an index. */
UNIV_INLINE
ulint
dict_index_get_nth_col_no(
/*======================*/
/* out: column number */
dict_index_t* index, /* in: index */
ulint pos); /* in: position of the field */
/* out: column number */
const dict_index_t* index, /* in: index */
ulint pos); /* in: position of the field */
/************************************************************************
Looks for column n in an index. */
......@@ -728,10 +773,10 @@ dict_index_copy_types(
/*************************************************************************
Gets the field column. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_field_get_col(
/*===============*/
dict_field_t* field);
const dict_field_t* field);
/**************************************************************************
In an index tree, finds the index corresponding to a record in the tree. */
......
......@@ -10,18 +10,73 @@ Created 1/8/1996 Heikki Tuuri
#include "trx0undo.h"
#include "trx0sys.h"
#include "rem0types.h"
#include "data0type.h"
/*************************************************************************
Gets the column data type. */
UNIV_INLINE
dtype_t*
dict_col_get_type(
/*==============*/
dict_col_t* col)
void
dict_col_copy_type(
/*===============*/
const dict_col_t* col, /* in: column */
dtype_t* type) /* out: data type */
{
ut_ad(col);
ut_ad(col && type);
type->mtype = col->mtype;
type->prtype = col->prtype;
type->len = col->len;
type->mbminlen = col->mbminlen;
type->mbmaxlen = col->mbmaxlen;
}
return(&col->type);
/***************************************************************************
Returns the minimum size of the column. */
UNIV_INLINE
ulint
dict_col_get_min_size(
/*==================*/
/* out: minimum size */
const dict_col_t* col) /* in: column */
{
return(dtype_get_min_size_low(col->mtype, col->prtype, col->len,
col->mbminlen, col->mbmaxlen));
}
/***************************************************************************
Returns the maximum size of the column. */
UNIV_INLINE
ulint
dict_col_get_max_size(
/*==================*/
/* out: maximum size */
const dict_col_t* col) /* in: column */
{
return(dtype_get_max_size_low(col->mtype, col->len));
}
/***************************************************************************
Returns the size of a fixed size column, 0 if not a fixed size column. */
UNIV_INLINE
ulint
dict_col_get_fixed_size(
/*====================*/
/* out: fixed size, or 0 */
const dict_col_t* col) /* in: column */
{
return(dtype_get_fixed_size_low(col->mtype, col->prtype, col->len,
col->mbminlen, col->mbmaxlen));
}
/***************************************************************************
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a column.
For fixed length types it is the fixed length of the type, otherwise 0. */
UNIV_INLINE
ulint
dict_col_get_sql_null_size(
/*=======================*/
/* out: SQL null storage size
in ROW_FORMAT=REDUNDANT */
const dict_col_t* col) /* in: column */
{
return(dict_col_get_fixed_size(col));
}
/*************************************************************************
......@@ -30,7 +85,7 @@ UNIV_INLINE
ulint
dict_col_get_no(
/*============*/
dict_col_t* col)
const dict_col_t* col)
{
ut_ad(col);
......@@ -145,12 +200,12 @@ dict_table_get_n_cols(
/************************************************************************
Gets the nth column of a table. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_table_get_nth_col(
/*===================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint pos) /* in: position of column */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint pos) /* in: position of column */
{
ut_ad(table);
ut_ad(pos < table->n_def);
......@@ -162,14 +217,14 @@ dict_table_get_nth_col(
/************************************************************************
Gets the given system column of a table. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_table_get_sys_col(
/*===================*/
/* out: pointer to column object */
dict_table_t* table, /* in: table */
ulint sys) /* in: DATA_ROW_ID, ... */
/* out: pointer to column object */
const dict_table_t* table, /* in: table */
ulint sys) /* in: DATA_ROW_ID, ... */
{
dict_col_t* col;
const dict_col_t* col;
ut_ad(table);
ut_ad(sys < DATA_N_SYS_COLS);
......@@ -177,8 +232,8 @@ dict_table_get_sys_col(
col = dict_table_get_nth_col(table, table->n_cols
- DATA_N_SYS_COLS + sys);
ut_ad(col->type.mtype == DATA_SYS);
ut_ad(col->type.prtype == (sys | DATA_NOT_NULL));
ut_ad(col->mtype == DATA_SYS);
ut_ad(col->prtype == (sys | DATA_NOT_NULL));
return(col);
}
......@@ -324,30 +379,28 @@ dict_index_get_sys_col_pos(
dict_index_t* index, /* in: index */
ulint type) /* in: DATA_ROW_ID, ... */
{
dict_col_t* col;
ut_ad(index);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
ut_ad(!(index->type & DICT_UNIVERSAL));
col = dict_table_get_sys_col(index->table, type);
if (index->type & DICT_CLUSTERED) {
return(dict_col_get_clust_pos(col, index));
return(dict_col_get_clust_pos(
dict_table_get_sys_col(index->table, type),
index));
}
return(dict_index_get_nth_col_pos
(index, dict_table_get_sys_col_no(index->table, type)));
return(dict_index_get_nth_col_pos(
index, dict_table_get_sys_col_no(index->table, type)));
}
/*************************************************************************
Gets the field column. */
UNIV_INLINE
dict_col_t*
const dict_col_t*
dict_field_get_col(
/*===============*/
dict_field_t* field)
const dict_field_t* field)
{
ut_ad(field);
......@@ -355,17 +408,17 @@ dict_field_get_col(
}
/************************************************************************
Gets pointer to the nth field data type in an index. */
Gets pointer to the nth column in an index. */
UNIV_INLINE
dtype_t*
dict_index_get_nth_type(
/*====================*/
/* out: data type */
dict_index_t* index, /* in: index */
ulint pos) /* in: position of the field */
const dict_col_t*
dict_index_get_nth_col(
/*===================*/
/* out: column */
const dict_index_t* index, /* in: index */
ulint pos) /* in: position of the field */
{
return(dict_col_get_type(dict_field_get_col
(dict_index_get_nth_field(index, pos))));
return(dict_field_get_col(dict_index_get_nth_field((dict_index_t*)
index, pos)));
}
/************************************************************************
......@@ -374,12 +427,11 @@ UNIV_INLINE
ulint
dict_index_get_nth_col_no(
/*======================*/
/* out: column number */
dict_index_t* index, /* in: index */
ulint pos) /* in: position of the field */
/* out: column number */
const dict_index_t* index, /* in: index */
ulint pos) /* in: position of the field */
{
return(dict_col_get_no(dict_field_get_col
(dict_index_get_nth_field(index, pos))));
return(dict_col_get_no(dict_index_get_nth_col(index, pos)));
}
/*************************************************************************
......
......@@ -121,12 +121,43 @@ dict_mem_foreign_create(void);
/* Data structure for a column in a table */
struct dict_col_struct{
ulint ind:10; /* table column position (they are numbered
starting from 0) */
ulint ord_part:1;/* nonzero if this column appears
in ordering fields of an index */
const char* name; /* name */
dtype_t type; /* data type */
/*----------------------*/
/* The following are copied from dtype_t,
so that all bit-fields can be packed tightly. */
unsigned mtype:8; /* main data type */
unsigned prtype:24; /* precise type; MySQL data
type, charset code, flags to
indicate nullability,
signedness, whether this is a
binary string, whether this is
a true VARCHAR where MySQL
uses 2 bytes to store the length */
/* the remaining fields do not affect alphabetical ordering: */
unsigned len:16; /* length; for MySQL data this
is field->pack_length(),
except that for a >= 5.0.3
type true VARCHAR this is the
maximum byte length of the
string data (in addition to
the string, MySQL uses 1 or 2
bytes to store the string length) */
unsigned mbminlen:2; /* minimum length of a
character, in bytes */
unsigned mbmaxlen:3; /* maximum length of a
character, in bytes */
/*----------------------*/
/* End of definitions copied from dtype_t */
unsigned ind:10; /* table column position
(starting from 0) */
unsigned ord_part:1; /* nonzero if this column
appears in the ordering fields
of an index */
const char* name; /* name */
};
/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column
......
......@@ -16,16 +16,17 @@ Created 7/1/1994 Heikki Tuuri
#include "rem0rec.h"
/*****************************************************************
Returns TRUE if two types are equal for comparison purposes. */
Returns TRUE if two columns are equal for comparison purposes. */
ibool
cmp_types_are_equal(
/*================*/
/* out: TRUE if the types are considered
equal in comparisons */
dtype_t* type1, /* in: type 1 */
dtype_t* type2, /* in: type 2 */
ibool check_charsets); /* in: whether to check charsets */
cmp_cols_are_equal(
/*===============*/
/* out: TRUE if the columns are
considered equal in comparisons */
const dict_col_t* col1, /* in: column 1 */
const dict_col_t* col2, /* in: column 2 */
ibool check_charsets);
/* in: whether to check charsets */
/*****************************************************************
This function is used to compare two data fields for which we know the
data type. */
......@@ -35,7 +36,8 @@ cmp_data_data(
/*==========*/
/* out: 1, 0, -1, if data1 is greater, equal,
less than data2, respectively */
dtype_t* cur_type,/* in: data type of the fields */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
byte* data1, /* in: data field (== a pointer to a memory
buffer) */
ulint len1, /* in: data field length or UNIV_SQL_NULL */
......@@ -51,7 +53,8 @@ cmp_data_data_slow(
/*===============*/
/* out: 1, 0, -1, if data1 is greater, equal,
less than data2, respectively */
dtype_t* cur_type,/* in: data type of the fields */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
byte* data1, /* in: data field (== a pointer to a memory
buffer) */
ulint len1, /* in: data field length or UNIV_SQL_NULL */
......
......@@ -15,7 +15,8 @@ cmp_data_data(
/*==========*/
/* out: 1, 0, -1, if data1 is greater, equal,
less than data2, respectively */
dtype_t* cur_type,/* in: data type of the fields */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
byte* data1, /* in: data field (== a pointer to a memory
buffer) */
ulint len1, /* in: data field length or UNIV_SQL_NULL */
......@@ -23,7 +24,7 @@ cmp_data_data(
buffer) */
ulint len2) /* in: data field length or UNIV_SQL_NULL */
{
return(cmp_data_data_slow(cur_type, data1, len1, data2, len2));
return(cmp_data_data_slow(mtype, prtype, data1, len1, data2, len2));
}
/*****************************************************************
......@@ -38,12 +39,17 @@ cmp_dfield_dfield(
dfield_t* dfield1,/* in: data field; must have type field set */
dfield_t* dfield2)/* in: data field */
{
const dtype_t* type;
ut_ad(dfield_check_typed(dfield1));
return(cmp_data_data
(dfield_get_type(dfield1),
dfield_get_data(dfield1), dfield_get_len(dfield1),
dfield_get_data(dfield2), dfield_get_len(dfield2)));
type = dfield_get_type(dfield1);
return(cmp_data_data(type->mtype, type->prtype,
dfield_get_data(dfield1),
dfield_get_len(dfield1),
dfield_get_data(dfield2),
dfield_get_len(dfield2)));
}
/*****************************************************************
......
......@@ -93,8 +93,8 @@ upd_field_set_field_no(
(ulong) dict_index_get_n_fields(index));
}
dtype_copy(dfield_get_type(&(upd_field->new_val)),
dict_index_get_nth_type(index, field_no));
dict_col_copy_type(dict_index_get_nth_col(index, field_no),
dfield_get_type(&(upd_field->new_val)));
}
/*************************************************************************
......
......@@ -445,21 +445,21 @@ mlog_open_and_write_index(
dict_index_get_n_unique_in_tree(index));
log_ptr += 2;
for (i = 0; i < n; i++) {
dict_field_t* field;
dtype_t* type;
ulint len;
dict_field_t* field;
const dict_col_t* col;
ulint len;
field = dict_index_get_nth_field(index, i);
type = dict_col_get_type(dict_field_get_col(field));
col = dict_field_get_col(field);
len = field->fixed_len;
ut_ad(len < 0x7fff);
if (len == 0
&& (dtype_get_len(type) > 255
|| dtype_get_mtype(type) == DATA_BLOB)) {
&& (col->len > 255 || col->mtype == DATA_BLOB)) {
/* variable-length field
with maximum length > 255 */
len = 0x7fff;
}
if (dtype_get_prtype(type) & DATA_NOT_NULL) {
if (col->prtype & DATA_NOT_NULL) {
len |= 0x8000;
}
if (log_ptr + 2 > log_end) {
......@@ -548,7 +548,7 @@ mlog_parse_index(
len & 0x8000 ? DATA_NOT_NULL : 0,
len & 0x7fff);
dict_index_add_col(ind, table,
dict_index_add_col(ind, table, (dict_col_t*)
dict_table_get_nth_col(table, i),
0);
}
......
......@@ -489,9 +489,10 @@ pars_resolve_exp_columns(
n_cols = dict_table_get_n_cols(table);
for (i = 0; i < n_cols; i++) {
dict_col_t* col = dict_table_get_nth_col(table, i);
const char* col_name = dict_table_get_col_name(
table, i);
const 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,
......@@ -503,8 +504,10 @@ pars_resolve_exp_columns(
sym_node->col_no = i;
sym_node->prefetch_buf = NULL;
dfield_set_type(&(sym_node->common.val),
dict_col_get_type(col));
dict_col_copy_type(
col,
dfield_get_type(&sym_node
->common.val));
return;
}
......@@ -920,8 +923,9 @@ pars_process_assign_list(
clust_index, NULL);
upd_field->exp = assign_node->val;
if (!dtype_is_fixed_size(dict_index_get_nth_type
(clust_index, upd_field->field_no))) {
if (!dict_col_get_fixed_size(
dict_index_get_nth_col(clust_index,
upd_field->field_no))) {
changes_field_size = 0;
}
......
......@@ -92,47 +92,48 @@ cmp_collate(
}
/*****************************************************************
Returns TRUE if two types are equal for comparison purposes. */
Returns TRUE if two columns are equal for comparison purposes. */
ibool
cmp_types_are_equal(
/*================*/
/* out: TRUE if the types are considered
equal in comparisons */
dtype_t* type1, /* in: type 1 */
dtype_t* type2, /* in: type 2 */
ibool check_charsets) /* in: whether to check charsets */
cmp_cols_are_equal(
/*===============*/
/* out: TRUE if the columns are
considered equal in comparisons */
const dict_col_t* col1, /* in: column 1 */
const dict_col_t* col2, /* in: column 2 */
ibool check_charsets)
/* in: whether to check charsets */
{
if (dtype_is_non_binary_string_type(type1->mtype, type1->prtype)
&& dtype_is_non_binary_string_type(type2->mtype, type2->prtype)) {
if (dtype_is_non_binary_string_type(col1->mtype, col1->prtype)
&& dtype_is_non_binary_string_type(col2->mtype, col2->prtype)) {
/* Both are non-binary string types: they can be compared if
and only if the charset-collation is the same */
if (check_charsets) {
return(dtype_get_charset_coll(type1->prtype)
== dtype_get_charset_coll(type2->prtype));
return(dtype_get_charset_coll(col1->prtype)
== dtype_get_charset_coll(col2->prtype));
} else {
return(TRUE);
}
}
if (dtype_is_binary_string_type(type1->mtype, type1->prtype)
&& dtype_is_binary_string_type(type2->mtype, type2->prtype)) {
if (dtype_is_binary_string_type(col1->mtype, col1->prtype)
&& dtype_is_binary_string_type(col2->mtype, col2->prtype)) {
/* Both are binary string types: they can be compared */
return(TRUE);
}
if (type1->mtype != type2->mtype) {
if (col1->mtype != col2->mtype) {
return(FALSE);
}
if (type1->mtype == DATA_INT
&& (type1->prtype & DATA_UNSIGNED)
!= (type2->prtype & DATA_UNSIGNED)) {
if (col1->mtype == DATA_INT
&& (col1->prtype & DATA_UNSIGNED)
!= (col2->prtype & DATA_UNSIGNED)) {
/* The storage format of an unsigned integer is different
from a signed integer: in a signed integer we OR
......@@ -141,12 +142,7 @@ cmp_types_are_equal(
return(FALSE);
}
if (type1->mtype == DATA_INT && type1->len != type2->len) {
return(FALSE);
}
return(TRUE);
return(col1->mtype != DATA_INT || col1->len == col2->len);
}
#ifndef UNIV_HOTBACKUP
......@@ -159,7 +155,8 @@ cmp_whole_field(
/*============*/
/* out: 1, 0, -1, if a is greater,
equal, less than b, respectively */
dtype_t* type, /* in: data type */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
unsigned char* a, /* in: data field */
unsigned int a_length, /* in: data field length,
not UNIV_SQL_NULL */
......@@ -172,11 +169,8 @@ cmp_whole_field(
double d_1;
double d_2;
int swap_flag = 1;
ulint data_type;
data_type = type->mtype;
switch (data_type) {
switch (mtype) {
case DATA_DECIMAL:
/* Remove preceding spaces */
......@@ -253,11 +247,8 @@ cmp_whole_field(
}
return(0);
case DATA_VARMYSQL:
case DATA_MYSQL:
case DATA_BLOB:
if (data_type == DATA_BLOB
&& 0 != (type->prtype & DATA_BINARY_TYPE)) {
if (prtype & DATA_BINARY_TYPE) {
ut_print_timestamp(stderr);
fprintf(stderr,
......@@ -265,15 +256,17 @@ cmp_whole_field(
" with a character set sensitive\n"
"InnoDB: comparison!\n");
}
/* fall through */
case DATA_VARMYSQL:
case DATA_MYSQL:
return(innobase_mysql_cmp
((int)(type->prtype & DATA_MYSQL_TYPE_MASK),
(uint)dtype_get_charset_coll(type->prtype),
((int)(prtype & DATA_MYSQL_TYPE_MASK),
(uint)dtype_get_charset_coll(prtype),
a, a_length, b, b_length));
default:
fprintf(stderr,
"InnoDB: unknown type number %lu\n",
(ulong) data_type);
(ulong) mtype);
ut_error;
}
......@@ -290,7 +283,8 @@ cmp_data_data_slow(
/*===============*/
/* out: 1, 0, -1, if data1 is greater, equal,
less than data2, respectively */
dtype_t* cur_type,/* in: data type of the fields */
ulint mtype, /* in: main type */
ulint prtype, /* in: precise type */
byte* data1, /* in: data field (== a pointer to a memory
buffer) */
ulint len1, /* in: data field length or UNIV_SQL_NULL */
......@@ -303,8 +297,6 @@ cmp_data_data_slow(
ulint data2_byte;
ulint cur_bytes;
ut_ad(dtype_validate(cur_type));
if (len1 == UNIV_SQL_NULL || len2 == UNIV_SQL_NULL) {
if (len1 == len2) {
......@@ -322,13 +314,13 @@ cmp_data_data_slow(
return(1);
}
if (cur_type->mtype >= DATA_FLOAT
|| (cur_type->mtype == DATA_BLOB
&& 0 == (cur_type->prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(cur_type->prtype)
if (mtype >= DATA_FLOAT
|| (mtype == DATA_BLOB
&& 0 == (prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(prtype)
!= DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
return(cmp_whole_field(cur_type,
return(cmp_whole_field(mtype, prtype,
data1, (unsigned) len1,
data2, (unsigned) len2));
}
......@@ -344,7 +336,7 @@ cmp_data_data_slow(
return(0);
}
data1_byte = dtype_get_pad_char(cur_type);
data1_byte = dtype_get_pad_char(mtype, prtype);
if (data1_byte == ULINT_UNDEFINED) {
......@@ -355,7 +347,7 @@ cmp_data_data_slow(
}
if (len2 <= cur_bytes) {
data2_byte = dtype_get_pad_char(cur_type);
data2_byte = dtype_get_pad_char(mtype, prtype);
if (data2_byte == ULINT_UNDEFINED) {
......@@ -372,9 +364,9 @@ cmp_data_data_slow(
goto next_byte;
}
if (cur_type->mtype <= DATA_CHAR
|| (cur_type->mtype == DATA_BLOB
&& 0 == (cur_type->prtype & DATA_BINARY_TYPE))) {
if (mtype <= DATA_CHAR
|| (mtype == DATA_BLOB
&& 0 == (prtype & DATA_BINARY_TYPE))) {
data1_byte = cmp_collate(data1_byte);
data2_byte = cmp_collate(data2_byte);
......@@ -435,8 +427,6 @@ cmp_dtuple_rec_with_match(
value for current comparison */
{
#ifndef UNIV_HOTBACKUP
dtype_t* cur_type; /* pointer to type of the current
field in dtuple */
dfield_t* dtuple_field; /* current field in logical record */
ulint dtuple_f_len; /* the length of the current field
in the logical record */
......@@ -483,8 +473,17 @@ cmp_dtuple_rec_with_match(
while (cur_field < dtuple_get_n_fields_cmp(dtuple)) {
ulint mtype;
ulint prtype;
dtuple_field = dtuple_get_nth_field(dtuple, cur_field);
cur_type = dfield_get_type(dtuple_field);
{
const dtype_t* type
= dfield_get_type(dtuple_field);
mtype = type->mtype;
prtype = type->prtype;
}
dtuple_f_len = dfield_get_len(dtuple_field);
......@@ -524,13 +523,13 @@ cmp_dtuple_rec_with_match(
}
}
if (cur_type->mtype >= DATA_FLOAT
|| (cur_type->mtype == DATA_BLOB
&& 0 == (cur_type->prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(cur_type->prtype)
if (mtype >= DATA_FLOAT
|| (mtype == DATA_BLOB
&& 0 == (prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(prtype)
!= DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
ret = cmp_whole_field(cur_type,
ret = cmp_whole_field(mtype, prtype,
dfield_get_data(dtuple_field),
(unsigned) dtuple_f_len,
rec_b_ptr, (unsigned) rec_f_len);
......@@ -558,7 +557,7 @@ cmp_dtuple_rec_with_match(
goto next_field;
}
rec_byte = dtype_get_pad_char(cur_type);
rec_byte = dtype_get_pad_char(mtype, prtype);
if (rec_byte == ULINT_UNDEFINED) {
ret = 1;
......@@ -570,7 +569,8 @@ cmp_dtuple_rec_with_match(
}
if (UNIV_UNLIKELY(dtuple_f_len <= cur_bytes)) {
dtuple_byte = dtype_get_pad_char(cur_type);
dtuple_byte = dtype_get_pad_char(mtype,
prtype);
if (dtuple_byte == ULINT_UNDEFINED) {
ret = -1;
......@@ -589,9 +589,9 @@ cmp_dtuple_rec_with_match(
goto next_byte;
}
if (cur_type->mtype <= DATA_CHAR
|| (cur_type->mtype == DATA_BLOB
&& !(cur_type->prtype & DATA_BINARY_TYPE))) {
if (mtype <= DATA_CHAR
|| (mtype == DATA_BLOB
&& !(prtype & DATA_BINARY_TYPE))) {
rec_byte = cmp_collate(rec_byte);
dtuple_byte = cmp_collate(dtuple_byte);
......@@ -730,8 +730,6 @@ cmp_rec_rec_with_match(
the value for the current comparison */
{
#ifndef UNIV_HOTBACKUP
dtype_t* cur_type; /* pointer to type struct of the
current field in index */
ulint rec1_n_fields; /* the number of fields in rec */
ulint rec1_f_len; /* length of current field in rec */
byte* rec1_b_ptr; /* pointer to the current byte in rec field */
......@@ -764,12 +762,19 @@ cmp_rec_rec_with_match(
while ((cur_field < rec1_n_fields) && (cur_field < rec2_n_fields)) {
if (index->type & DICT_UNIVERSAL) {
cur_type = dtype_binary;
ulint mtype;
ulint prtype;
if (UNIV_UNLIKELY(index->type & DICT_UNIVERSAL)) {
/* This is for the insert buffer B-tree. */
mtype = DATA_BINARY;
prtype = 0;
} else {
cur_type = dict_col_get_type
(dict_field_get_col(dict_index_get_nth_field
(index, cur_field)));
const dict_col_t* col
= dict_index_get_nth_col(index, cur_field);
mtype = col->mtype;
prtype = col->prtype;
}
rec1_b_ptr = rec_get_nth_field(rec1, offsets1,
......@@ -834,13 +839,13 @@ cmp_rec_rec_with_match(
}
}
if (cur_type->mtype >= DATA_FLOAT
|| (cur_type->mtype == DATA_BLOB
&& 0 == (cur_type->prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(cur_type->prtype)
if (mtype >= DATA_FLOAT
|| (mtype == DATA_BLOB
&& 0 == (prtype & DATA_BINARY_TYPE)
&& dtype_get_charset_coll(prtype)
!= DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL)) {
ret = cmp_whole_field(cur_type,
ret = cmp_whole_field(mtype, prtype,
rec1_b_ptr,
(unsigned) rec1_f_len,
rec2_b_ptr,
......@@ -867,7 +872,7 @@ cmp_rec_rec_with_match(
goto next_field;
}
rec2_byte = dtype_get_pad_char(cur_type);
rec2_byte = dtype_get_pad_char(mtype, prtype);
if (rec2_byte == ULINT_UNDEFINED) {
ret = 1;
......@@ -879,7 +884,7 @@ cmp_rec_rec_with_match(
}
if (rec1_f_len <= cur_bytes) {
rec1_byte = dtype_get_pad_char(cur_type);
rec1_byte = dtype_get_pad_char(mtype, prtype);
if (rec1_byte == ULINT_UNDEFINED) {
ret = -1;
......@@ -898,9 +903,9 @@ cmp_rec_rec_with_match(
goto next_byte;
}
if (cur_type->mtype <= DATA_CHAR
|| (cur_type->mtype == DATA_BLOB
&& !(cur_type->prtype & DATA_BINARY_TYPE))) {
if (mtype <= DATA_CHAR
|| (mtype == DATA_BLOB
&& !(prtype & DATA_BINARY_TYPE))) {
rec1_byte = cmp_collate(rec1_byte);
rec2_byte = cmp_collate(rec2_byte);
......@@ -972,8 +977,6 @@ cmp_debug_dtuple_rec_with_match(
returns, contains the value for current
comparison */
{
dtype_t* cur_type; /* pointer to type of the current
field in dtuple */
dfield_t* dtuple_field; /* current field in logical record */
ulint dtuple_f_len; /* the length of the current field
in the logical record */
......@@ -1014,9 +1017,17 @@ cmp_debug_dtuple_rec_with_match(
while (cur_field < dtuple_get_n_fields_cmp(dtuple)) {
ulint mtype;
ulint prtype;
dtuple_field = dtuple_get_nth_field(dtuple, cur_field);
{
const dtype_t* type
= dfield_get_type(dtuple_field);
cur_type = dfield_get_type(dtuple_field);
mtype = type->mtype;
prtype = type->prtype;
}
dtuple_f_data = dfield_get_data(dtuple_field);
dtuple_f_len = dfield_get_len(dtuple_field);
......@@ -1032,7 +1043,7 @@ cmp_debug_dtuple_rec_with_match(
goto order_resolved;
}
ret = cmp_data_data(cur_type, dtuple_f_data, dtuple_f_len,
ret = cmp_data_data(mtype, prtype, dtuple_f_data, dtuple_f_len,
rec_f_data, rec_f_len);
if (ret != 0) {
goto order_resolved;
......
......@@ -202,8 +202,7 @@ rec_init_offsets(
}
field = dict_index_get_nth_field(index, i);
if (!(dtype_get_prtype(dict_col_get_type
(dict_field_get_col(field)))
if (!(dict_field_get_col(field)->prtype
& DATA_NOT_NULL)) {
/* nullable field => read the null flag */
......@@ -226,11 +225,11 @@ rec_init_offsets(
if (UNIV_UNLIKELY(!field->fixed_len)) {
/* Variable-length field: read the length */
dtype_t* type = dict_col_get_type
(dict_field_get_col(field));
const dict_col_t* col
= dict_field_get_col(field);
len = *lens--;
if (UNIV_UNLIKELY(dtype_get_len(type) > 255)
|| UNIV_UNLIKELY(dtype_get_mtype(type)
if (UNIV_UNLIKELY(col->len > 255)
|| UNIV_UNLIKELY(col->mtype
== DATA_BLOB)) {
if (len & 0x80) {
/* 1exxxxxxx xxxxxxxx */
......@@ -442,8 +441,6 @@ rec_get_converted_size_new(
{
ulint size = REC_N_NEW_EXTRA_BYTES
+ (index->n_nullable + 7) / 8;
dict_field_t* field;
dtype_t* type;
ulint i;
ulint n_fields;
ut_ad(index && dtuple);
......@@ -471,25 +468,27 @@ rec_get_converted_size_new(
/* read the lengths of fields 0..n */
for (i = 0; i < n_fields; i++) {
ulint len = dtuple_get_nth_field(dtuple, i)->len;
dict_field_t* field;
ulint len;
const dict_col_t* col;
field = dict_index_get_nth_field(index, i);
type = dict_col_get_type(dict_field_get_col(field));
ut_ad(len != UNIV_SQL_NULL
|| !(dtype_get_prtype(type) & DATA_NOT_NULL));
len = dtuple_get_nth_field(dtuple, i)->len;
col = dict_field_get_col(field);
ut_ad(len != UNIV_SQL_NULL || !(col->prtype & DATA_NOT_NULL));
if (len == UNIV_SQL_NULL) {
/* No length is stored for NULL fields. */
continue;
}
ut_ad(len <= dtype_get_len(type)
|| dtype_get_mtype(type) == DATA_BLOB);
ut_ad(len <= col->len || col->mtype == DATA_BLOB);
ut_ad(!field->fixed_len || len == field->fixed_len);
if (field->fixed_len) {
} else if (len < 128
|| (dtype_get_len(type) < 256
&& dtype_get_mtype(type) != DATA_BLOB)) {
|| (col->len < 256 && col->mtype != DATA_BLOB)) {
size++;
} else {
size += 2;
......@@ -588,8 +587,6 @@ rec_set_nth_field_extern_bit_new(
{
byte* nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
byte* lens = nulls - (index->n_nullable + 7) / 8;
dict_field_t* field;
dtype_t* type;
ulint i;
ulint n_fields;
ulint null_mask = 1;
......@@ -603,9 +600,13 @@ rec_set_nth_field_extern_bit_new(
/* read the lengths of fields 0..n */
for (i = 0; i < n_fields; i++) {
const dict_field_t* field;
const dict_col_t* col;
field = dict_index_get_nth_field(index, i);
type = dict_col_get_type(dict_field_get_col(field));
if (!(dtype_get_prtype(type) & DATA_NOT_NULL)) {
col = dict_field_get_col(field);
if (!(col->prtype & DATA_NOT_NULL)) {
if (UNIV_UNLIKELY(!(byte) null_mask)) {
nulls--;
null_mask = 1;
......@@ -629,8 +630,7 @@ rec_set_nth_field_extern_bit_new(
continue;
}
lens--;
if (dtype_get_len(type) > 255
|| dtype_get_mtype(type) == DATA_BLOB) {
if (col->len > 255 || col->mtype == DATA_BLOB) {
ulint len = lens[1];
if (len & 0x80) { /* 1exxxxxx: 2-byte length */
if (i == ith) {
......@@ -640,9 +640,10 @@ rec_set_nth_field_extern_bit_new(
/* toggle the extern bit */
len ^= 0x40;
if (mtr) {
mlog_write_ulint
(lens + 1, len,
MLOG_1BYTE, mtr);
mlog_write_ulint(lens + 1,
len,
MLOG_1BYTE,
mtr);
} else {
lens[1] = (byte) len;
}
......@@ -1137,8 +1138,6 @@ rec_copy_prefix_to_buf(
{
byte* nulls;
byte* lens;
dict_field_t* field;
dtype_t* type;
ulint i;
ulint prefix_len;
ulint null_mask;
......@@ -1180,9 +1179,13 @@ rec_copy_prefix_to_buf(
/* read the lengths of fields 0..n */
for (i = 0; i < n_fields; i++) {
const dict_field_t* field;
const dict_col_t* col;
field = dict_index_get_nth_field(index, i);
type = dict_col_get_type(dict_field_get_col(field));
if (!(dtype_get_prtype(type) & DATA_NOT_NULL)) {
col = dict_field_get_col(field);
if (!(col->prtype & DATA_NOT_NULL)) {
/* nullable field => read the null flag */
if (UNIV_UNLIKELY(!(byte) null_mask)) {
nulls--;
......@@ -1201,8 +1204,7 @@ rec_copy_prefix_to_buf(
prefix_len += field->fixed_len;
} else {
ulint len = *lens--;
if (dtype_get_len(type) > 255
|| dtype_get_mtype(type) == DATA_BLOB) {
if (col->len > 255 || col->mtype == DATA_BLOB) {
if (len & 0x80) {
/* 1exxxxxx */
len &= 0x3f;
......
......@@ -135,12 +135,12 @@ row_ins_alloc_sys_fields(
/*=====================*/
ins_node_t* node) /* in: insert node */
{
dtuple_t* row;
dict_table_t* table;
mem_heap_t* heap;
dict_col_t* col;
dfield_t* dfield;
byte* ptr;
dtuple_t* row;
dict_table_t* table;
mem_heap_t* heap;
const dict_col_t* col;
dfield_t* dfield;
byte* ptr;
row = node->row;
table = node->table;
......@@ -445,7 +445,6 @@ row_ins_cascade_calc_update_vec(
upd_field_t* parent_ufield;
ulint n_fields_updated;
ulint parent_field_no;
dtype_t* type;
ulint i;
ulint j;
......@@ -479,7 +478,10 @@ row_ins_cascade_calc_update_vec(
if (parent_ufield->field_no == parent_field_no) {
ulint min_size;
ulint min_size;
const dict_col_t* col;
col = dict_index_get_nth_col(index, i);
/* A field in the parent index record is
updated. Let us make the update vector
......@@ -488,20 +490,17 @@ row_ins_cascade_calc_update_vec(
ufield = update->fields + n_fields_updated;
ufield->field_no
= dict_table_get_nth_col_pos
(table,
dict_index_get_nth_col_no(index, i));
= dict_table_get_nth_col_pos(
table, dict_col_get_no(col));
ufield->exp = NULL;
ufield->new_val = parent_ufield->new_val;
type = dict_index_get_nth_type(index, i);
/* Do not allow a NOT NULL column to be
updated as NULL */
if (ufield->new_val.len == UNIV_SQL_NULL
&& (type->prtype & DATA_NOT_NULL)) {
&& (col->prtype & DATA_NOT_NULL)) {
return(ULINT_UNDEFINED);
}
......@@ -510,9 +509,12 @@ row_ins_cascade_calc_update_vec(
column, do not allow the update */
if (ufield->new_val.len != UNIV_SQL_NULL
&& dtype_get_at_most_n_mbchars
(type, dtype_get_len(type),
ufield->new_val.len, ufield->new_val.data)
&& dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen, col->mbmaxlen,
col->len,
ufield->new_val.len,
ufield->new_val.data)
< ufield->new_val.len) {
return(ULINT_UNDEFINED);
......@@ -523,7 +525,7 @@ row_ins_cascade_calc_update_vec(
need to pad with spaces the new value of the
child column */
min_size = dtype_get_min_size(type);
min_size = dict_col_get_min_size(col);
if (min_size
&& ufield->new_val.len != UNIV_SQL_NULL
......@@ -544,14 +546,13 @@ row_ins_cascade_calc_update_vec(
parent_ufield->new_val.data,
parent_ufield->new_val.len);
switch (UNIV_EXPECT(dtype_get_mbminlen
(type), 1)) {
switch (UNIV_EXPECT(col->mbminlen,1)) {
default:
ut_error;
case 1:
if (UNIV_UNLIKELY
(dtype_get_charset_coll
(dtype_get_prtype(type))
(dtype_get_charset_coll(
col->prtype)
== DATA_MYSQL_BINARY_CHARSET_COLL)) {
/* Do not pad BINARY
columns. */
......@@ -2211,7 +2212,6 @@ row_ins_index_entry_set_vals(
dfield_t* row_field;
ulint n_fields;
ulint i;
dtype_t* cur_type;
ut_ad(entry && row);
......@@ -2227,12 +2227,13 @@ row_ins_index_entry_set_vals(
if (ind_field->prefix_len > 0
&& dfield_get_len(row_field) != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(ind_field));
const dict_col_t* col
= dict_field_get_col(ind_field);
field->len = dtype_get_at_most_n_mbchars
(cur_type, ind_field->prefix_len,
dfield_get_len(row_field), row_field->data);
field->len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
ind_field->prefix_len,
row_field->len, row_field->data);
} else {
field->len = row_field->len;
}
......
......@@ -1607,16 +1607,11 @@ row_table_got_default_clust_index(
/*==============================*/
dict_table_t* table)
{
dict_index_t* clust_index;
const dict_index_t* clust_index;
clust_index = dict_table_get_first_index(table);
if (dtype_get_mtype(dict_index_get_nth_type(clust_index, 0))
== DATA_SYS) {
return(TRUE);
}
return(FALSE);
return(dict_index_get_nth_col(clust_index, 0)->mtype == DATA_SYS);
}
/*************************************************************************
......
......@@ -114,10 +114,8 @@ row_build_index_entry(
dict_field_t* ind_field;
dfield_t* dfield;
dfield_t* dfield2;
dict_col_t* col;
ulint i;
ulint storage_len;
dtype_t* cur_type;
ut_ad(row && index && heap);
ut_ad(dtuple_check_typed(row));
......@@ -134,7 +132,7 @@ row_build_index_entry(
for (i = 0; i < entry_len; i++) {
ind_field = dict_index_get_nth_field(index, i);
col = ind_field->col;
const dict_col_t* col = ind_field->col;
dfield = dtuple_get_nth_field(entry, i);
......@@ -146,14 +144,12 @@ row_build_index_entry(
if (ind_field->prefix_len) {
if (dfield_get_len(dfield2) != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(ind_field));
storage_len = dtype_get_at_most_n_mbchars
(cur_type,
ind_field->prefix_len,
dfield_get_len(dfield2),
dfield2->data);
storage_len = dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen, col->mbmaxlen,
ind_field->prefix_len,
dfield_get_len(dfield2),
dfield2->data);
dfield_set_len(dfield, storage_len);
}
......@@ -197,7 +193,6 @@ row_build(
dtuple_t* row;
dict_table_t* table;
dict_field_t* ind_field;
dict_col_t* col;
dfield_t* dfield;
ulint n_fields;
byte* field;
......@@ -244,7 +239,9 @@ row_build(
if (ind_field->prefix_len == 0) {
col = dict_field_get_col(ind_field);
const dict_col_t* col
= dict_field_get_col(ind_field);
dfield = dtuple_get_nth_field(row,
dict_col_get_no(col));
field = rec_get_nth_field(rec, offsets, i, &len);
......@@ -427,11 +424,16 @@ row_build_row_ref(
if (clust_col_prefix_len > 0) {
if (len != UNIV_SQL_NULL) {
const dtype_t* dtype
= dfield_get_type(dfield);
dfield_set_len(dfield,
dtype_get_at_most_n_mbchars
(dfield_get_type(dfield),
clust_col_prefix_len, len,
(char*) field));
dtype_get_at_most_n_mbchars(
dtype->prtype,
dtype->mbminlen,
dtype->mbmaxlen,
clust_col_prefix_len,
len, (char*) field));
}
}
}
......@@ -524,11 +526,16 @@ row_build_row_ref_in_tuple(
if (clust_col_prefix_len > 0) {
if (len != UNIV_SQL_NULL) {
const dtype_t* dtype
= dfield_get_type(dfield);
dfield_set_len(dfield,
dtype_get_at_most_n_mbchars
(dfield_get_type(dfield),
clust_col_prefix_len, len,
(char*) field));
dtype_get_at_most_n_mbchars(
dtype->prtype,
dtype->mbminlen,
dtype->mbmaxlen,
clust_col_prefix_len,
len, (char*) field));
}
}
}
......@@ -555,13 +562,8 @@ row_build_row_ref_from_row(
directly into data of this row */
{
dict_index_t* clust_index;
dict_field_t* field;
dfield_t* dfield;
dfield_t* dfield2;
dict_col_t* col;
ulint ref_len;
ulint i;
dtype_t* cur_type;
ut_ad(ref && table && row);
......@@ -572,6 +574,11 @@ row_build_row_ref_from_row(
ut_ad(ref_len == dtuple_get_n_fields(ref));
for (i = 0; i < ref_len; i++) {
const dict_col_t* col;
dict_field_t* field;
dfield_t* dfield;
dfield_t* dfield2;
dfield = dtuple_get_nth_field(ref, i);
field = dict_index_get_nth_field(clust_index, i);
......@@ -585,12 +592,9 @@ row_build_row_ref_from_row(
if (field->prefix_len > 0
&& dfield->len != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(field));
dfield->len = dtype_get_at_most_n_mbchars
(cur_type, field->prefix_len,
dfield->len, dfield->data);
dfield->len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
field->prefix_len, dfield->len, dfield->data);
}
}
......
......@@ -69,15 +69,12 @@ row_sel_sec_rec_is_for_clust_rec(
rec_t* clust_rec, /* in: clustered index record */
dict_index_t* clust_index) /* in: clustered index */
{
dict_field_t* ifield;
dict_col_t* col;
byte* sec_field;
ulint sec_len;
byte* clust_field;
ulint clust_len;
ulint n;
ulint i;
dtype_t* cur_type;
mem_heap_t* heap = NULL;
ulint clust_offsets_[REC_OFFS_NORMAL_SIZE];
ulint sec_offsets_[REC_OFFS_SMALL_SIZE];
......@@ -96,27 +93,26 @@ row_sel_sec_rec_is_for_clust_rec(
n = dict_index_get_n_ordering_defined_by_user(sec_index);
for (i = 0; i < n; i++) {
const dict_field_t* ifield;
const dict_col_t* col;
ifield = dict_index_get_nth_field(sec_index, i);
col = dict_field_get_col(ifield);
clust_field = rec_get_nth_field
(clust_rec, clust_offs,
dict_col_get_clust_pos(col, clust_index),
&clust_len);
clust_field = rec_get_nth_field(
clust_rec, clust_offs,
dict_col_get_clust_pos(col, clust_index), &clust_len);
sec_field = rec_get_nth_field(sec_rec, sec_offs, i, &sec_len);
if (ifield->prefix_len > 0
&& clust_len != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(ifield));
if (ifield->prefix_len > 0 && clust_len != UNIV_SQL_NULL) {
clust_len = dtype_get_at_most_n_mbchars
(cur_type, ifield->prefix_len,
clust_len, (char*) clust_field);
clust_len = dtype_get_at_most_n_mbchars(
col->prtype, col->mbminlen, col->mbmaxlen,
ifield->prefix_len,
clust_len, (char*) clust_field);
}
if (0 != cmp_data_data(dict_col_get_type(col),
if (0 != cmp_data_data(col->mtype, col->prtype,
clust_field, clust_len,
sec_field, sec_len)) {
is_equal = FALSE;
......@@ -2247,8 +2243,7 @@ row_sel_convert_mysql_key_to_innobase(
while (key_ptr < key_end) {
ut_a(dict_col_get_type(field->col)->mtype
== dfield_get_type(dfield)->mtype);
ut_a(field->col->mtype == dfield_get_type(dfield)->mtype);
data_offset = 0;
is_null = FALSE;
......
......@@ -388,9 +388,9 @@ row_upd_changes_field_size_or_external(
this fix also to 4.0. The merge to 5.0 will be made
manually immediately after we commit this to 4.1. */
new_len = dtype_get_sql_null_size
(dict_index_get_nth_type(index,
upd_field->field_no));
new_len = dict_col_get_sql_null_size(
dict_index_get_nth_col(index,
upd_field->field_no));
}
old_len = rec_offs_nth_size(offsets, upd_field->field_no);
......@@ -884,7 +884,6 @@ row_upd_index_replace_new_col_vals_index_pos(
ulint j;
ulint i;
ulint n_fields;
dtype_t* cur_type;
ut_ad(index);
......@@ -922,13 +921,17 @@ row_upd_index_replace_new_col_vals_index_pos(
if (field->prefix_len > 0
&& new_val->len != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(field));
const dict_col_t* col
= dict_field_get_col(field);
dfield->len
= dtype_get_at_most_n_mbchars
(cur_type, field->prefix_len,
new_val->len, new_val->data);
= dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
new_val->len,
new_val->data);
}
}
}
......@@ -957,7 +960,6 @@ row_upd_index_replace_new_col_vals(
dfield_t* new_val;
ulint j;
ulint i;
dtype_t* cur_type;
dict_index_t* clust_index;
ut_ad(index);
......@@ -995,13 +997,17 @@ row_upd_index_replace_new_col_vals(
if (field->prefix_len > 0
&& new_val->len != UNIV_SQL_NULL) {
cur_type = dict_col_get_type
(dict_field_get_col(field));
const dict_col_t* col
= dict_field_get_col(field);
dfield->len
= dtype_get_at_most_n_mbchars
(cur_type, field->prefix_len,
new_val->len, new_val->data);
= dtype_get_at_most_n_mbchars(
col->prtype,
col->mbminlen,
col->mbmaxlen,
field->prefix_len,
new_val->len,
new_val->data);
}
}
}
......@@ -1044,14 +1050,15 @@ row_upd_changes_ord_field_binary(
for (i = 0; i < n_unique; i++) {
dict_field_t* ind_field
= dict_index_get_nth_field(index, i);
dict_col_t* col
= dict_field_get_col(ind_field);
ulint col_pos
= dict_col_get_clust_pos(col, clust_index);
ulint col_no
= dict_col_get_no(col);
const dict_field_t* ind_field;
const dict_col_t* col;
ulint col_pos;
ulint col_no;
ind_field = dict_index_get_nth_field(index, i);
col = dict_field_get_col(ind_field);
col_pos = dict_col_get_clust_pos(col, clust_index);
col_no = dict_col_get_no(col);
for (j = 0; j < n_upd_fields; j++) {
......@@ -1137,12 +1144,13 @@ row_upd_changes_first_fields_binary(
for (i = 0; i < n; i++) {
dict_field_t* ind_field
= dict_index_get_nth_field(index, i);
dict_col_t* col
= dict_field_get_col(ind_field);
ulint col_pos
= dict_col_get_clust_pos(col, clust_index);
const dict_field_t* ind_field;
const dict_col_t* col;
ulint col_pos;
ind_field = dict_index_get_nth_field(index, i);
col = dict_field_get_col(ind_field);
col_pos = dict_col_get_clust_pos(col, clust_index);
ut_a(ind_field->prefix_len == 0);
......
......@@ -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, table,
dict_index_add_col(srv_sys->dummy_ind1, table, (dict_col_t*)
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, table,
dict_index_add_col(srv_sys->dummy_ind2, table, (dict_col_t*)
dict_table_get_nth_col(table, 0), 0);
srv_sys->dummy_ind2->table = table;
......
......@@ -413,7 +413,6 @@ trx_undo_page_report_modify(
{
dict_table_t* table;
upd_field_t* upd_field;
dict_col_t* col;
ulint first_free;
byte* ptr;
ulint len;
......@@ -627,7 +626,8 @@ trx_undo_page_report_modify(
for (col_no = 0; col_no < dict_table_get_n_cols(table);
col_no++) {
col = dict_table_get_nth_col(table, col_no);
const dict_col_t* col
= dict_table_get_nth_col(table, col_no);
if (col->ord_part > 0) {
......
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