A joint patch for:
- MDEV-8093 sql_yacc.yy: add %type create_field for field_spec and column_def and partially: - MDEV-8095 Split Create_field
This commit is contained in:
parent
a099686e2e
commit
00ed55c71a
18
sql/field.cc
18
sql/field.cc
@ -9603,7 +9603,7 @@ void Field_bit_as_char::sql_type(String &res) const
|
||||
Convert create_field::length from number of characters to number of bytes.
|
||||
*/
|
||||
|
||||
void Create_field::create_length_to_internal_length(void)
|
||||
void Column_definition::create_length_to_internal_length(void)
|
||||
{
|
||||
switch (sql_type) {
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
@ -9654,10 +9654,11 @@ void Create_field::create_length_to_internal_length(void)
|
||||
/**
|
||||
Init for a tmp table field. To be extended if need be.
|
||||
*/
|
||||
void Create_field::init_for_tmp_table(enum_field_types sql_type_arg,
|
||||
uint32 length_arg, uint32 decimals_arg,
|
||||
bool maybe_null, bool is_unsigned,
|
||||
uint pack_length_arg)
|
||||
void Column_definition::init_for_tmp_table(enum_field_types sql_type_arg,
|
||||
uint32 length_arg,
|
||||
uint32 decimals_arg,
|
||||
bool maybe_null, bool is_unsigned,
|
||||
uint pack_length_arg)
|
||||
{
|
||||
DBUG_ENTER("Create_field::init_for_tmp_table");
|
||||
|
||||
@ -9768,7 +9769,7 @@ static inline bool is_item_func(Item* x)
|
||||
}
|
||||
|
||||
|
||||
bool Create_field::check(THD *thd)
|
||||
bool Column_definition::check(THD *thd)
|
||||
{
|
||||
const uint conditional_type_modifiers= AUTO_INCREMENT_FLAG;
|
||||
uint sign_len, allowed_type_modifier= 0;
|
||||
@ -10425,10 +10426,11 @@ Field *make_field(TABLE_SHARE *share,
|
||||
|
||||
/** Create a field suitable for create of table. */
|
||||
|
||||
Create_field::Create_field(THD *thd, Field *old_field, Field *orig_field)
|
||||
Column_definition::Column_definition(THD *thd, Field *old_field,
|
||||
Field *orig_field)
|
||||
{
|
||||
field= old_field;
|
||||
field_name=change=old_field->field_name;
|
||||
field_name= old_field->field_name;
|
||||
length= old_field->field_length;
|
||||
flags= old_field->flags;
|
||||
unireg_check=old_field->unireg_check;
|
||||
|
40
sql/field.h
40
sql/field.h
@ -3416,16 +3416,14 @@ public:
|
||||
|
||||
|
||||
extern const LEX_STRING null_lex_str;
|
||||
|
||||
/*
|
||||
Create field class for CREATE TABLE
|
||||
*/
|
||||
|
||||
class Create_field :public Sql_alloc
|
||||
class Column_definition: public Sql_alloc
|
||||
{
|
||||
public:
|
||||
const char *field_name;
|
||||
const char *change; // If done with alter table
|
||||
const char *after; // Put column after this one
|
||||
LEX_STRING comment; // Comment for field
|
||||
Item *def, *on_update; // Default value
|
||||
enum enum_field_types sql_type;
|
||||
@ -3464,19 +3462,18 @@ public:
|
||||
*/
|
||||
Virtual_column_info *vcol_info;
|
||||
|
||||
Create_field() :change(0), after(0), comment(null_lex_str),
|
||||
def(0), on_update(0), sql_type(MYSQL_TYPE_NULL),
|
||||
flags(0), pack_length(0), key_length(0), interval(0),
|
||||
srid(0), geom_type(Field::GEOM_GEOMETRY),
|
||||
field(0), option_list(NULL), option_struct(NULL),
|
||||
create_if_not_exists(false), vcol_info(0)
|
||||
Column_definition():
|
||||
comment(null_lex_str),
|
||||
def(0), on_update(0), sql_type(MYSQL_TYPE_NULL),
|
||||
flags(0), pack_length(0), key_length(0), interval(0),
|
||||
srid(0), geom_type(Field::GEOM_GEOMETRY),
|
||||
field(0), option_list(NULL), option_struct(NULL),
|
||||
create_if_not_exists(false), vcol_info(0)
|
||||
{
|
||||
interval_list.empty();
|
||||
}
|
||||
|
||||
Create_field(THD *thd, Field *field, Field *orig_field);
|
||||
/* Used to make a clone of this object for ALTER/CREATE TABLE */
|
||||
Create_field *clone(MEM_ROOT *mem_root) const;
|
||||
Column_definition(THD *thd, Field *field, Field *orig_field);
|
||||
void create_length_to_internal_length(void);
|
||||
|
||||
/* Init for a tmp table field. To be extended if need be. */
|
||||
@ -3516,6 +3513,23 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class Create_field :public Column_definition
|
||||
{
|
||||
public:
|
||||
const char *change; // If done with alter table
|
||||
const char *after; // Put column after this one
|
||||
Create_field():
|
||||
Column_definition(), change(0), after(0)
|
||||
{ }
|
||||
Create_field(THD *thd, Field *old_field, Field *orig_field):
|
||||
Column_definition(thd, old_field, orig_field),
|
||||
change(old_field->field_name), after(0)
|
||||
{ }
|
||||
/* Used to make a clone of this object for ALTER/CREATE TABLE */
|
||||
Create_field *clone(MEM_ROOT *mem_root) const;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
A class for sending info to the client
|
||||
*/
|
||||
|
@ -886,8 +886,8 @@ bool Aggregator_distinct::setup(THD *thd)
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Create_field> field_list;
|
||||
Create_field field_def; /* field definition */
|
||||
List<Column_definition> field_list;
|
||||
Column_definition field_def; /* field definition */
|
||||
Item *arg;
|
||||
DBUG_ENTER("Aggregator_distinct::setup");
|
||||
/* It's legal to call setup() more than once when in a subquery */
|
||||
|
@ -937,7 +937,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
{
|
||||
DBUG_ENTER("table_def::create_conversion_table");
|
||||
|
||||
List<Create_field> field_list;
|
||||
List<Column_definition> field_list;
|
||||
TABLE *conv_table= NULL;
|
||||
Relay_log_info *rli= rgi->rli;
|
||||
/*
|
||||
@ -948,7 +948,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
uint const cols_to_create= MY_MIN(target_table->s->fields, size());
|
||||
for (uint col= 0 ; col < cols_to_create; ++col)
|
||||
{
|
||||
Create_field *field_def=
|
||||
Column_definition *field_def=
|
||||
(Create_field*) alloc_root(thd->mem_root, sizeof(Create_field));
|
||||
bool unsigned_flag= 0;
|
||||
if (field_list.push_back(field_def, thd->mem_root))
|
||||
|
@ -764,7 +764,7 @@ sp_head::set_stmt_end(THD *thd)
|
||||
|
||||
|
||||
static TYPELIB *
|
||||
create_typelib(MEM_ROOT *mem_root, Create_field *field_def, List<String> *src)
|
||||
create_typelib(MEM_ROOT *mem_root, Column_definition *field_def, List<String> *src)
|
||||
{
|
||||
TYPELIB *result= NULL;
|
||||
CHARSET_INFO *cs= field_def->charset;
|
||||
@ -2327,8 +2327,8 @@ sp_head::backpatch(sp_label *lab)
|
||||
}
|
||||
|
||||
/**
|
||||
Prepare an instance of Create_field for field creation (fill all necessary
|
||||
attributes).
|
||||
Prepare an instance of Column_definition for field creation
|
||||
(fill all necessary attributes).
|
||||
|
||||
@param[in] thd Thread handle
|
||||
@param[in] lex Yacc parsing context
|
||||
@ -2344,7 +2344,7 @@ sp_head::backpatch(sp_label *lab)
|
||||
bool
|
||||
sp_head::fill_field_definition(THD *thd, LEX *lex,
|
||||
enum enum_field_types field_type,
|
||||
Create_field *field_def)
|
||||
Column_definition *field_def)
|
||||
{
|
||||
uint unused1= 0;
|
||||
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
stored_procedure_type m_type;
|
||||
uint m_flags; // Boolean attributes of a stored routine
|
||||
|
||||
Create_field m_return_field_def; /**< This is used for FUNCTIONs only. */
|
||||
Column_definition m_return_field_def; /**< This is used for FUNCTIONs only. */
|
||||
|
||||
const char *m_tmp_query; ///< Temporary pointer to sub query string
|
||||
st_sp_chistics *m_chistics;
|
||||
@ -419,7 +419,7 @@ public:
|
||||
|
||||
bool fill_field_definition(THD *thd, LEX *lex,
|
||||
enum enum_field_types field_type,
|
||||
Create_field *field_def);
|
||||
Column_definition *field_def);
|
||||
|
||||
void set_info(longlong created, longlong modified,
|
||||
st_sp_chistics *chistics, ulonglong sql_mode);
|
||||
|
@ -450,7 +450,7 @@ bool sp_pcontext::find_cursor(LEX_STRING name,
|
||||
|
||||
|
||||
void sp_pcontext::retrieve_field_definitions(
|
||||
List<Create_field> *field_def_lst) const
|
||||
List<Column_definition> *field_def_lst) const
|
||||
{
|
||||
/* Put local/context fields in the result list. */
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
Item *default_value;
|
||||
|
||||
/// Full type information (field meta-data) of the SP-variable.
|
||||
Create_field field_def;
|
||||
Column_definition field_def;
|
||||
|
||||
public:
|
||||
sp_variable(LEX_STRING _name, uint _offset)
|
||||
@ -347,7 +347,7 @@ public:
|
||||
/// context and its children.
|
||||
///
|
||||
/// @param field_def_lst[out] Container to store type information.
|
||||
void retrieve_field_definitions(List<Create_field> *field_def_lst) const;
|
||||
void retrieve_field_definitions(List<Column_definition> *field_def_lst) const;
|
||||
|
||||
/// Find SP-variable by name.
|
||||
///
|
||||
|
@ -104,7 +104,7 @@ bool sp_rcontext::alloc_arrays(THD *thd)
|
||||
|
||||
bool sp_rcontext::init_var_table(THD *thd)
|
||||
{
|
||||
List<Create_field> field_def_lst;
|
||||
List<Column_definition> field_def_lst;
|
||||
|
||||
if (!m_root_parsing_ctx->max_var_index())
|
||||
return false;
|
||||
|
@ -2476,7 +2476,7 @@ public:
|
||||
|
||||
SQL_I_List<ORDER> proc_list;
|
||||
SQL_I_List<TABLE_LIST> auxiliary_table_list, save_list;
|
||||
Create_field *last_field;
|
||||
Column_definition *last_field;
|
||||
Item_sum *in_sum_func;
|
||||
udf_func udf;
|
||||
HA_CHECK_OPT check_opt; // check/repair options
|
||||
@ -2854,7 +2854,7 @@ public:
|
||||
bool is_analyze, bool *printed_anything);
|
||||
void restore_set_statement_var();
|
||||
|
||||
void init_last_field(Create_field *field, const char *name, CHARSET_INFO *cs);
|
||||
void init_last_field(Column_definition *field, const char *name, CHARSET_INFO *cs);
|
||||
void set_last_field_type(const Lex_field_type_st &type);
|
||||
bool set_bincmp(CHARSET_INFO *cs, bool bin);
|
||||
// Check if "KEY IF NOT EXISTS name" used outside of ALTER context
|
||||
|
@ -16945,12 +16945,12 @@ err:
|
||||
0 if out of memory, TABLE object in case of success
|
||||
*/
|
||||
|
||||
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list)
|
||||
TABLE *create_virtual_tmp_table(THD *thd, List<Column_definition> &field_list)
|
||||
{
|
||||
uint field_count= field_list.elements;
|
||||
uint blob_count= 0;
|
||||
Field **field;
|
||||
Create_field *cdef; /* column definition */
|
||||
Column_definition *cdef; /* column definition */
|
||||
uint record_length= 0;
|
||||
uint null_count= 0; /* number of columns which may be null */
|
||||
uint null_pack_length; /* NULL representation array length */
|
||||
@ -16978,7 +16978,7 @@ TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list)
|
||||
setup_tmp_table_column_bitmaps(table, bitmaps);
|
||||
|
||||
/* Create all fields and calculate the total length of record */
|
||||
List_iterator_fast<Create_field> it(field_list);
|
||||
List_iterator_fast<Column_definition> it(field_list);
|
||||
while ((cdef= it++))
|
||||
{
|
||||
*field= make_field(share, thd->mem_root, 0, cdef->length,
|
||||
|
@ -1861,7 +1861,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
|
||||
All methods presume that there is at least one field to change.
|
||||
*/
|
||||
|
||||
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
|
||||
TABLE *create_virtual_tmp_table(THD *thd, List<Column_definition> &field_list);
|
||||
|
||||
int test_if_item_cache_changed(List<Cached_item> &list);
|
||||
int join_init_read_record(JOIN_TAB *tab);
|
||||
|
@ -5627,7 +5627,7 @@ bool store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
|
||||
if (sp)
|
||||
{
|
||||
Field *field;
|
||||
Create_field *field_def;
|
||||
Column_definition *field_def;
|
||||
String tmp_string;
|
||||
if (routine_type == TYPE_ENUM_FUNCTION)
|
||||
{
|
||||
@ -5786,7 +5786,7 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
|
||||
TABLE_SHARE share;
|
||||
TABLE tbl;
|
||||
Field *field;
|
||||
Create_field *field_def= &sp->m_return_field_def;
|
||||
Column_definition *field_def= &sp->m_return_field_def;
|
||||
|
||||
bzero((char*) &tbl, sizeof(TABLE));
|
||||
(void) build_table_filename(path, sizeof(path), "", "", "", 0);
|
||||
|
@ -71,7 +71,7 @@ static int copy_data_between_tables(THD *thd, TABLE *from,TABLE *to,
|
||||
Alter_info::enum_enable_or_disable keys_onoff,
|
||||
Alter_table_ctx *alter_ctx);
|
||||
|
||||
static bool prepare_blob_field(THD *thd, Create_field *sql_field);
|
||||
static bool prepare_blob_field(THD *thd, Column_definition *sql_field);
|
||||
static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
|
||||
uint *, handler *, KEY **, uint *, int);
|
||||
static uint blob_length_by_type(enum_field_types type);
|
||||
@ -2875,7 +2875,7 @@ void calculate_interval_lengths(CHARSET_INFO *cs, TYPELIB *interval,
|
||||
1 Error
|
||||
*/
|
||||
|
||||
int prepare_create_field(Create_field *sql_field,
|
||||
int prepare_create_field(Column_definition *sql_field,
|
||||
uint *blob_columns,
|
||||
longlong table_flags)
|
||||
{
|
||||
@ -4235,7 +4235,7 @@ static void set_table_default_charset(THD *thd,
|
||||
In this case the error is given
|
||||
*/
|
||||
|
||||
static bool prepare_blob_field(THD *thd, Create_field *sql_field)
|
||||
static bool prepare_blob_field(THD *thd, Column_definition *sql_field)
|
||||
{
|
||||
DBUG_ENTER("prepare_blob_field");
|
||||
|
||||
@ -4294,7 +4294,7 @@ static bool prepare_blob_field(THD *thd, Create_field *sql_field)
|
||||
|
||||
*/
|
||||
|
||||
void sp_prepare_create_field(THD *thd, Create_field *sql_field)
|
||||
void sp_prepare_create_field(THD *thd, Column_definition *sql_field)
|
||||
{
|
||||
if (sql_field->sql_type == MYSQL_TYPE_SET ||
|
||||
sql_field->sql_type == MYSQL_TYPE_ENUM)
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
class Alter_info;
|
||||
class Alter_table_ctx;
|
||||
class Column_definition;
|
||||
class Create_field;
|
||||
struct TABLE_LIST;
|
||||
class THD;
|
||||
@ -249,8 +250,8 @@ bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length,
|
||||
bool quick_rm_table(THD *thd, handlerton *base, const char *db,
|
||||
const char *table_name, uint flags);
|
||||
void close_cached_table(THD *thd, TABLE *table);
|
||||
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
|
||||
int prepare_create_field(Create_field *sql_field,
|
||||
void sp_prepare_create_field(THD *thd, Column_definition *sql_field);
|
||||
int prepare_create_field(Column_definition *sql_field,
|
||||
uint *blob_columns,
|
||||
longlong table_flags);
|
||||
CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
|
||||
|
@ -853,7 +853,7 @@ static void add_key_to_list(LEX *lex, LEX_STRING *field_name,
|
||||
lex->alter_info.key_list.push_back(key, mem_root);
|
||||
}
|
||||
|
||||
void LEX::init_last_field(Create_field *field, const char *field_name,
|
||||
void LEX::init_last_field(Column_definition *field, const char *field_name,
|
||||
CHARSET_INFO *cs)
|
||||
{
|
||||
last_field= field;
|
||||
@ -928,6 +928,7 @@ bool LEX::set_bincmp(CHARSET_INFO *cs, bool bin)
|
||||
Lex_dyncol_type_st Lex_dyncol_type;
|
||||
|
||||
/* pointers */
|
||||
Create_field *create_field;
|
||||
CHARSET_INFO *charset;
|
||||
Condition_information_item *cond_info_item;
|
||||
DYNCALL_CREATE_DEF *dyncol_def;
|
||||
@ -1718,6 +1719,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
||||
%type <Lex_dyncol_type> opt_dyncol_type dyncol_type
|
||||
numeric_dyncol_type temporal_dyncol_type string_dyncol_type
|
||||
|
||||
%type <create_field> field_spec column_def
|
||||
|
||||
%type <geom_type> spatial_type
|
||||
|
||||
%type <num>
|
||||
@ -1882,7 +1885,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
||||
persistent_column_stat_spec persistent_index_stat_spec
|
||||
table_column_list table_index_list table_index_name
|
||||
check start checksum
|
||||
field_list field_list_item field_spec kill column_def key_def
|
||||
field_list field_list_item kill key_def
|
||||
keycache_list keycache_list_or_parts assign_to_keycache
|
||||
assign_to_keycache_parts
|
||||
preload_list preload_list_or_parts preload_keys preload_keys_parts
|
||||
@ -6006,13 +6009,13 @@ field_list:
|
||||
;
|
||||
|
||||
field_list_item:
|
||||
column_def
|
||||
column_def { }
|
||||
| key_def
|
||||
;
|
||||
|
||||
column_def:
|
||||
field_spec opt_check_constraint
|
||||
| field_spec references
|
||||
field_spec opt_check_constraint { $$= $1; }
|
||||
| field_spec references { $$= $1; }
|
||||
;
|
||||
|
||||
key_def:
|
||||
@ -6134,21 +6137,22 @@ field_spec:
|
||||
MYSQL_YYABORT;
|
||||
|
||||
lex->init_last_field(f, $1.str, NULL);
|
||||
$<create_field>$= f;
|
||||
}
|
||||
field_type { Lex->set_last_field_type($3); }
|
||||
field_def
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
Create_field *f= lex->last_field;
|
||||
$$= $<create_field>2;
|
||||
|
||||
if (f->check(thd))
|
||||
if ($$->check(thd))
|
||||
MYSQL_YYABORT;
|
||||
|
||||
lex->alter_info.create_list.push_back(f, thd->mem_root);
|
||||
lex->alter_info.create_list.push_back($$, thd->mem_root);
|
||||
|
||||
if (f->flags & PRI_KEY_FLAG)
|
||||
if ($$->flags & PRI_KEY_FLAG)
|
||||
add_key_to_list(lex, &$1, Key::PRIMARY, Lex->check_exists);
|
||||
else if (f->flags & UNIQUE_KEY_FLAG)
|
||||
else if ($$->flags & UNIQUE_KEY_FLAG)
|
||||
add_key_to_list(lex, &$1, Key::UNIQUE, Lex->check_exists);
|
||||
}
|
||||
;
|
||||
@ -7564,7 +7568,7 @@ alter_list_item:
|
||||
add_column column_def opt_place
|
||||
{
|
||||
Lex->create_last_non_select_table= Lex->last_table();
|
||||
Lex->last_field->after= $3;
|
||||
$2->after= $3;
|
||||
}
|
||||
| ADD key_def
|
||||
{
|
||||
@ -7581,16 +7585,16 @@ alter_list_item:
|
||||
{
|
||||
Lex->alter_info.flags|= Alter_info::ALTER_CHANGE_COLUMN;
|
||||
Lex->create_last_non_select_table= Lex->last_table();
|
||||
Lex->last_field->change= $4.str;
|
||||
Lex->last_field->after= $6;
|
||||
$5->change= $4.str;
|
||||
$5->after= $6;
|
||||
}
|
||||
| MODIFY_SYM opt_column opt_if_exists_table_element
|
||||
field_spec opt_place
|
||||
{
|
||||
Lex->alter_info.flags|= Alter_info::ALTER_CHANGE_COLUMN;
|
||||
Lex->create_last_non_select_table= Lex->last_table();
|
||||
Lex->last_field->change= Lex->last_field->field_name;
|
||||
Lex->last_field->after= $5;
|
||||
$4->change= $4->field_name;
|
||||
$4->after= $5;
|
||||
}
|
||||
| DROP opt_column opt_if_exists_table_element field_ident opt_restrict
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user