Commit 775b1c06 authored by osku's avatar osku

Add max_row_size to dict_table_t.

parent ff38fefd
...@@ -293,3 +293,36 @@ dtype_print( ...@@ -293,3 +293,36 @@ dtype_print(
fprintf(stderr, " len %lu prec %lu", (ulong) len, (ulong) type->prec); fprintf(stderr, " len %lu prec %lu", (ulong) len, (ulong) type->prec);
} }
/***************************************************************************
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 */
{
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);
}
...@@ -861,6 +861,7 @@ dict_table_add_to_cache( ...@@ -861,6 +861,7 @@ dict_table_add_to_cache(
ulint fold; ulint fold;
ulint id_fold; ulint id_fold;
ulint i; ulint i;
ulint row_len;
ut_ad(table); ut_ad(table);
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
...@@ -908,6 +909,24 @@ dict_table_add_to_cache( ...@@ -908,6 +909,24 @@ dict_table_add_to_cache(
#error "DATA_N_SYS_COLS != 4" #error "DATA_N_SYS_COLS != 4"
#endif #endif
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)));
/* If we have a single unbounded field, or several gigantic
fields, mark the maximum row size as ULINT_MAX. */
if (ut_max(col_len, row_len) >= (ULINT_MAX / 2)) {
row_len = ULINT_MAX;
break;
}
row_len += col_len;
}
table->max_row_size = row_len;
/* Look for a table with the same name: error if such exists */ /* Look for a table with the same name: error if such exists */
{ {
dict_table_t* table2; dict_table_t* table2;
......
...@@ -82,6 +82,8 @@ dict_mem_table_create( ...@@ -82,6 +82,8 @@ dict_mem_table_create(
table->stat_modified_counter = 0; table->stat_modified_counter = 0;
table->max_row_size = 0;
mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX); mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
table->autoinc_inited = FALSE; table->autoinc_inited = FALSE;
......
...@@ -330,6 +330,16 @@ dtype_get_min_size( ...@@ -330,6 +330,16 @@ dtype_get_min_size(
/* out: minimum size */ /* out: minimum size */
const dtype_t* type); /* in: type */ const dtype_t* type); /* in: type */
/*************************************************************************** /***************************************************************************
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 */
/***************************************************************************
Returns a stored SQL NULL size for a type. For fixed length types it is Returns a stored SQL NULL size for a type. For fixed length types it is
the fixed length of the type, otherwise 0. */ the fixed length of the type, otherwise 0. */
UNIV_INLINE UNIV_INLINE
......
...@@ -341,6 +341,12 @@ struct dict_table_struct{ ...@@ -341,6 +341,12 @@ struct dict_table_struct{
had an IX lock on */ had an IX lock on */
UT_LIST_BASE_NODE_T(lock_t) UT_LIST_BASE_NODE_T(lock_t)
locks; /* list of locks on the table */ locks; /* list of locks on the table */
ulint max_row_size;
/* maximum size of a single row in the
table, not guaranteed to be especially
accurate. it's ULINT_MAX if there are
unbounded variable-width fields. initialized
in dict_table_add_to_cache. */
/*----------------------*/ /*----------------------*/
ibool does_not_fit_in_memory; ibool does_not_fit_in_memory;
/* this field is used to specify in simulations /* this field is used to specify in simulations
......
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