Commit 81e4b9b3 authored by Sergei Golubchik's avatar Sergei Golubchik

misc cleanups

parent 7ec3a4d7
...@@ -4191,10 +4191,10 @@ struct LEX: public Query_tables_list ...@@ -4191,10 +4191,10 @@ struct LEX: public Query_tables_list
void add_key_to_list(LEX_CSTRING *field_name, void add_key_to_list(LEX_CSTRING *field_name,
enum Key::Keytype type, bool check_exists); enum Key::Keytype type, bool check_exists);
// Add a constraint as a part of CREATE TABLE or ALTER TABLE // Add a constraint as a part of CREATE TABLE or ALTER TABLE
bool add_constraint(const LEX_CSTRING *name, Virtual_column_info *constr, bool add_constraint(const LEX_CSTRING &name, Virtual_column_info *constr,
bool if_not_exists) bool if_not_exists)
{ {
constr->name= *name; constr->name= name;
constr->flags= if_not_exists ? constr->flags= if_not_exists ?
Alter_info::CHECK_CONSTRAINT_IF_NOT_EXISTS : 0; Alter_info::CHECK_CONSTRAINT_IF_NOT_EXISTS : 0;
alter_info.check_constraint_list.push_back(constr); alter_info.check_constraint_list.push_back(constr);
...@@ -4293,7 +4293,7 @@ struct LEX: public Query_tables_list ...@@ -4293,7 +4293,7 @@ struct LEX: public Query_tables_list
info.constr->expr= lt_creator.create(thd, info.constr->expr= lt_creator.create(thd,
create_item_ident_nosp(thd, &start), create_item_ident_nosp(thd, &start),
create_item_ident_nosp(thd, &end)); create_item_ident_nosp(thd, &end));
add_constraint(&null_clex_str, info.constr, false); add_constraint(null_clex_str, info.constr, false);
return 0; return 0;
} }
......
This diff is collapsed.
...@@ -198,8 +198,8 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db, ...@@ -198,8 +198,8 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db,
int create_table_mode, TABLE_LIST *table); int create_table_mode, TABLE_LIST *table);
handler *mysql_create_frm_image(THD *thd, handler *mysql_create_frm_image(THD *thd,
const LEX_CSTRING *db, const LEX_CSTRING &db,
const LEX_CSTRING *table_name, const LEX_CSTRING &table_name,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
Alter_info *alter_info, Alter_info *alter_info,
int create_table_mode, int create_table_mode,
......
...@@ -1356,8 +1356,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, ...@@ -1356,8 +1356,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (setup_tables_and_check_access(thd, &select_lex->context, if (setup_tables_and_check_access(thd, &select_lex->context,
&select_lex->top_join_list, &select_lex->top_join_list, table_list,
table_list,
select_lex->leaf_tables, select_lex->leaf_tables,
FALSE, UPDATE_ACL, SELECT_ACL, TRUE) || FALSE, UPDATE_ACL, SELECT_ACL, TRUE) ||
setup_conds(thd, table_list, select_lex->leaf_tables, conds) || setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||
......
...@@ -6636,7 +6636,7 @@ key_def: ...@@ -6636,7 +6636,7 @@ key_def:
constraint_def: constraint_def:
opt_constraint check_constraint opt_constraint check_constraint
{ {
Lex->add_constraint(&$1, $2, FALSE); Lex->add_constraint($1, $2, FALSE);
} }
; ;
...@@ -8350,7 +8350,7 @@ alter_list_item: ...@@ -8350,7 +8350,7 @@ alter_list_item:
| ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint | ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint
{ {
Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT; Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
Lex->add_constraint(&$6, $7, TRUE); Lex->add_constraint($6, $7, TRUE);
} }
| CHANGE opt_column opt_if_exists_table_element field_ident | CHANGE opt_column opt_if_exists_table_element field_ident
field_spec opt_place field_spec opt_place
......
...@@ -6571,7 +6571,7 @@ key_def: ...@@ -6571,7 +6571,7 @@ key_def:
constraint_def: constraint_def:
opt_constraint check_constraint opt_constraint check_constraint
{ {
Lex->add_constraint(&$1, $2, FALSE); Lex->add_constraint($1, $2, FALSE);
} }
; ;
...@@ -8364,7 +8364,7 @@ alter_list_item: ...@@ -8364,7 +8364,7 @@ alter_list_item:
| ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint | ADD CONSTRAINT IF_SYM not EXISTS field_ident check_constraint
{ {
Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT; Lex->alter_info.flags|= ALTER_ADD_CHECK_CONSTRAINT;
Lex->add_constraint(&$6, $7, TRUE); Lex->add_constraint($6, $7, TRUE);
} }
| CHANGE opt_column opt_if_exists_table_element field_ident | CHANGE opt_column opt_if_exists_table_element field_ident
field_spec opt_place field_spec opt_place
......
...@@ -1366,8 +1366,8 @@ void TABLE::find_constraint_correlated_indexes() ...@@ -1366,8 +1366,8 @@ void TABLE::find_constraint_correlated_indexes()
bool TABLE_SHARE::init_period_from_extra2(period_info_t &period, bool TABLE_SHARE::init_period_from_extra2(period_info_t &period,
const uchar *data) const uchar *data)
{ {
period.start_fieldno= uint2korr(data); period.start_fieldno= read_frm_fieldno(data);
period.end_fieldno= uint2korr(data + frm_fieldno_size); period.end_fieldno= read_frm_fieldno(data + frm_fieldno_size);
return period.start_fieldno >= fields || period.end_fieldno >= fields; return period.start_fieldno >= fields || period.end_fieldno >= fields;
} }
...@@ -1419,18 +1419,16 @@ bool read_extra2(const uchar *frm_image, size_t len, extra2_fields *fields) ...@@ -1419,18 +1419,16 @@ bool read_extra2(const uchar *frm_image, size_t len, extra2_fields *fields)
fields->options.length= length; fields->options.length= length;
break; break;
case EXTRA2_DEFAULT_PART_ENGINE: case EXTRA2_DEFAULT_PART_ENGINE:
fields->engine.set((char*)extra2, length); fields->engine.set((const char*)extra2, length);
break; break;
case EXTRA2_GIS: case EXTRA2_GIS:
#ifdef HAVE_SPATIAL
if (fields->gis.str) if (fields->gis.str)
DBUG_RETURN(true); DBUG_RETURN(true);
fields->gis.str= extra2; fields->gis.str= extra2;
fields->gis.length= length; fields->gis.length= length;
#endif /*HAVE_SPATIAL*/
break; break;
case EXTRA2_PERIOD_FOR_SYSTEM_TIME: case EXTRA2_PERIOD_FOR_SYSTEM_TIME:
if (fields->system_period || length != 2 * sizeof(uint16)) if (fields->system_period || length != 2 * frm_fieldno_size)
DBUG_RETURN(true); DBUG_RETURN(true);
fields->system_period = extra2; fields->system_period = extra2;
break; break;
...@@ -3014,7 +3012,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, ...@@ -3014,7 +3012,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write,
thd->lex->create_info.tabledef_version= tabledef_version; thd->lex->create_info.tabledef_version= tabledef_version;
promote_first_timestamp_column(&thd->lex->alter_info.create_list); promote_first_timestamp_column(&thd->lex->alter_info.create_list);
file= mysql_create_frm_image(thd, &db, &table_name, file= mysql_create_frm_image(thd, db, table_name,
&thd->lex->create_info, &thd->lex->alter_info, &thd->lex->create_info, &thd->lex->alter_info,
C_ORDINARY_CREATE, &unused1, &unused2, &frm); C_ORDINARY_CREATE, &unused1, &unused2, &frm);
error|= file == 0; error|= file == 0;
......
...@@ -1783,6 +1783,11 @@ class IS_table_read_plan; ...@@ -1783,6 +1783,11 @@ class IS_table_read_plan;
/** number of bytes used by field positional indexes in frm */ /** number of bytes used by field positional indexes in frm */
constexpr uint frm_fieldno_size= 2; constexpr uint frm_fieldno_size= 2;
static inline uint16 read_frm_fieldno(const uchar *data)
{ return uint2korr(data); }
static inline void store_frm_fieldno(const uchar *data, uint16 fieldno)
{ int2store(data, fieldno); }
/** number of bytes used by identifier length in frm */ /** number of bytes used by identifier length in frm */
constexpr uint frm_ident_len_size= 2; constexpr uint frm_ident_len_size= 2;
......
...@@ -73,18 +73,18 @@ static uchar *extra2_write_len(uchar *pos, size_t len) ...@@ -73,18 +73,18 @@ static uchar *extra2_write_len(uchar *pos, size_t len)
} }
static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type, static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type,
const LEX_CSTRING *str) const LEX_CSTRING &str)
{ {
*pos++ = type; *pos++ = type;
pos= extra2_write_len(pos, str->length); pos= extra2_write_len(pos, str.length);
memcpy(pos, str->str, str->length); memcpy(pos, str.str, str.length);
return pos + str->length; return pos + str.length;
} }
static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type, static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type,
LEX_CUSTRING *str) const LEX_CUSTRING &str)
{ {
return extra2_write(pos, type, reinterpret_cast<LEX_CSTRING *>(str)); return extra2_write(pos, type, *reinterpret_cast<const LEX_CSTRING*>(&str));
} }
static uchar *extra2_write_field_properties(uchar *pos, static uchar *extra2_write_field_properties(uchar *pos,
...@@ -106,10 +106,9 @@ static uchar *extra2_write_field_properties(uchar *pos, ...@@ -106,10 +106,9 @@ static uchar *extra2_write_field_properties(uchar *pos,
return pos; return pos;
} }
static static uint16
uint16
get_fieldno_by_name(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, get_fieldno_by_name(HA_CREATE_INFO *create_info, List<Create_field> &create_fields,
const Lex_ident field_name) const Lex_ident &field_name)
{ {
List_iterator<Create_field> it(create_fields); List_iterator<Create_field> it(create_fields);
Create_field *sql_field = NULL; Create_field *sql_field = NULL;
...@@ -151,6 +150,11 @@ uchar* store_str(uchar *buf, const Lex_ident &str) ...@@ -151,6 +150,11 @@ uchar* store_str(uchar *buf, const Lex_ident &str)
return buf + str.length + frm_ident_len_size; return buf + str.length + frm_ident_len_size;
} }
static size_t extra2_size_needed(size_t len)
{
return 1 + (len > 255 ? 3 : 1) + len;
}
/** /**
Create a frm (table definition) file Create a frm (table definition) file
...@@ -166,7 +170,7 @@ uchar* store_str(uchar *buf, const Lex_ident &str) ...@@ -166,7 +170,7 @@ uchar* store_str(uchar *buf, const Lex_ident &str)
or null LEX_CUSTRING (str==0) in case of an error. or null LEX_CUSTRING (str==0) in case of an error.
*/ */
LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
List<Create_field> &create_fields, List<Create_field> &create_fields,
uint keys, KEY *key_info, handler *db_file) uint keys, KEY *key_info, handler *db_file)
...@@ -245,7 +249,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -245,7 +249,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
DBUG_PRINT("info", ("Options length: %u", options_len)); DBUG_PRINT("info", ("Options length: %u", options_len));
if (validate_comment_length(thd, &create_info->comment, TABLE_COMMENT_MAXLEN, if (validate_comment_length(thd, &create_info->comment, TABLE_COMMENT_MAXLEN,
ER_TOO_LONG_TABLE_COMMENT, table->str)) ER_TOO_LONG_TABLE_COMMENT, table.str))
DBUG_RETURN(frm); DBUG_RETURN(frm);
/* /*
If table comment is longer than TABLE_COMMENT_INLINE_MAXLEN bytes, If table comment is longer than TABLE_COMMENT_INLINE_MAXLEN bytes,
...@@ -279,31 +283,30 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -279,31 +283,30 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
prepare_frm_header(thd, reclength, fileinfo, create_info, keys, key_info); prepare_frm_header(thd, reclength, fileinfo, create_info, keys, key_info);
/* one byte for a type, one or three for a length */ /* one byte for a type, one or three for a length */
size_t extra2_size= 1 + 1 + create_info->tabledef_version.length; size_t extra2_size= extra2_size_needed(create_info->tabledef_version.length);
if (options_len) if (options_len)
extra2_size+= 1 + (options_len > 255 ? 3 : 1) + options_len; extra2_size+= extra2_size_needed(options_len);
if (part_info) if (part_info)
extra2_size+= 1 + 1 + hton_name(part_info->default_engine_type)->length; extra2_size+= extra2_size_needed(hton_name(part_info->default_engine_type)->length);
if (gis_extra2_len) if (gis_extra2_len)
extra2_size+= 1 + (gis_extra2_len > 255 ? 3 : 1) + gis_extra2_len; extra2_size+= extra2_size_needed(gis_extra2_len);
if (create_info->versioned()) if (create_info->versioned())
{ {
extra2_size+= 1 + 1 + 2 * sizeof(uint16); extra2_size+= extra2_size_needed(2 * frm_fieldno_size);
} }
if (create_info->period_info.name) if (create_info->period_info.name)
{ {
extra2_size+= 1 + (period_info_len > 255 ? 3 : 1) + period_info_len; extra2_size+= extra2_size_needed(period_info_len);
} }
bool has_extra2_field_flags_= has_extra2_field_flags(create_fields); bool has_extra2_field_flags_= has_extra2_field_flags(create_fields);
if (has_extra2_field_flags_) if (has_extra2_field_flags_)
{ {
extra2_size+= 1 + (create_fields.elements > 255 ? 3 : 1) + extra2_size+= extra2_size_needed(create_fields.elements);
create_fields.elements;
} }
key_buff_length= uint4korr(fileinfo+47); key_buff_length= uint4korr(fileinfo+47);
...@@ -325,7 +328,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -325,7 +328,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
if (frm.length > FRM_MAX_SIZE || if (frm.length > FRM_MAX_SIZE ||
create_info->expression_length > UINT_MAX32) create_info->expression_length > UINT_MAX32)
{ {
my_error(ER_TABLE_DEFINITION_TOO_BIG, MYF(0), table->str); my_error(ER_TABLE_DEFINITION_TOO_BIG, MYF(0), table.str);
DBUG_RETURN(frm); DBUG_RETURN(frm);
} }
...@@ -338,11 +341,11 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -338,11 +341,11 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
pos = frm_ptr + 64; pos = frm_ptr + 64;
compile_time_assert(EXTRA2_TABLEDEF_VERSION != '/'); compile_time_assert(EXTRA2_TABLEDEF_VERSION != '/');
pos= extra2_write(pos, EXTRA2_TABLEDEF_VERSION, pos= extra2_write(pos, EXTRA2_TABLEDEF_VERSION,
&create_info->tabledef_version); create_info->tabledef_version);
if (part_info) if (part_info)
pos= extra2_write(pos, EXTRA2_DEFAULT_PART_ENGINE, pos= extra2_write(pos, EXTRA2_DEFAULT_PART_ENGINE,
hton_name(part_info->default_engine_type)); *hton_name(part_info->default_engine_type));
if (options_len) if (options_len)
{ {
...@@ -369,10 +372,10 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -369,10 +372,10 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
pos= store_str(pos, create_info->period_info.name); pos= store_str(pos, create_info->period_info.name);
pos= store_str(pos, create_info->period_info.constr->name); pos= store_str(pos, create_info->period_info.constr->name);
int2store(pos, get_fieldno_by_name(create_info, create_fields, store_frm_fieldno(pos, get_fieldno_by_name(create_info, create_fields,
create_info->period_info.period.start)); create_info->period_info.period.start));
pos+= frm_fieldno_size; pos+= frm_fieldno_size;
int2store(pos, get_fieldno_by_name(create_info, create_fields, store_frm_fieldno(pos, get_fieldno_by_name(create_info, create_fields,
create_info->period_info.period.end)); create_info->period_info.period.end));
pos+= frm_fieldno_size; pos+= frm_fieldno_size;
} }
...@@ -380,13 +383,13 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -380,13 +383,13 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
if (create_info->versioned()) if (create_info->versioned())
{ {
*pos++= EXTRA2_PERIOD_FOR_SYSTEM_TIME; *pos++= EXTRA2_PERIOD_FOR_SYSTEM_TIME;
*pos++= 2 * sizeof(uint16); *pos++= 2 * frm_fieldno_size;
int2store(pos, get_fieldno_by_name(create_info, create_fields, store_frm_fieldno(pos, get_fieldno_by_name(create_info, create_fields,
create_info->vers_info.as_row.start)); create_info->vers_info.as_row.start));
pos+= sizeof(uint16); pos+= frm_fieldno_size;
int2store(pos, get_fieldno_by_name(create_info, create_fields, store_frm_fieldno(pos, get_fieldno_by_name(create_info, create_fields,
create_info->vers_info.as_row.end)); create_info->vers_info.as_row.end));
pos+= sizeof(uint16); pos+= frm_fieldno_size;
} }
if (has_extra2_field_flags_) if (has_extra2_field_flags_)
...@@ -402,7 +405,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, ...@@ -402,7 +405,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table,
my_printf_error(ER_CANT_CREATE_TABLE, my_printf_error(ER_CANT_CREATE_TABLE,
"Cannot create table %`s: index information is too long. " "Cannot create table %`s: index information is too long. "
"Decrease number of indexes or use shorter index names or shorter comments.", "Decrease number of indexes or use shorter index names or shorter comments.",
MYF(0), table->str); MYF(0), table.str);
goto err; goto err;
} }
......
...@@ -170,8 +170,8 @@ enum extra2_frm_value_type { ...@@ -170,8 +170,8 @@ enum extra2_frm_value_type {
EXTRA2_TABLEDEF_VERSION=0, EXTRA2_TABLEDEF_VERSION=0,
EXTRA2_DEFAULT_PART_ENGINE=1, EXTRA2_DEFAULT_PART_ENGINE=1,
EXTRA2_GIS=2, EXTRA2_GIS=2,
EXTRA2_APPLICATION_TIME_PERIOD=3,
EXTRA2_PERIOD_FOR_SYSTEM_TIME=4, EXTRA2_PERIOD_FOR_SYSTEM_TIME=4,
EXTRA2_APPLICATION_TIME_PERIOD=8,
#define EXTRA2_ENGINE_IMPORTANT 128 #define EXTRA2_ENGINE_IMPORTANT 128
...@@ -187,7 +187,7 @@ int rea_create_table(THD *thd, LEX_CUSTRING *frm, ...@@ -187,7 +187,7 @@ int rea_create_table(THD *thd, LEX_CUSTRING *frm,
const char *path, const char *db, const char *table_name, const char *path, const char *db, const char *table_name,
HA_CREATE_INFO *create_info, handler *file, HA_CREATE_INFO *create_info, handler *file,
bool no_ha_create_table); bool no_ha_create_table);
LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
HA_CREATE_INFO *create_info, HA_CREATE_INFO *create_info,
List<Create_field> &create_fields, List<Create_field> &create_fields,
uint keys, KEY *key_info, handler *db_file); uint keys, KEY *key_info, handler *db_file);
......
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