SQL: store versioning field flags in EXTRA2

This commit is contained in:
Kosov Eugene 2016-10-26 14:32:41 +03:00 committed by Aleksey Midenkov
parent e094228631
commit 7d815be198
9 changed files with 69 additions and 26 deletions

View file

@ -190,9 +190,9 @@ enum enum_indicator_type
#define GENERATED_ROW_END_FLAG (1 << 28) /* autogenerated column declared with
`generated always at row end`
(see II.a SQL Standard).*/
#define WITHOUT_SYSTEM_VERSIONING_FLAG (1 << 29) /* column that doesn't support
system versioning when table
itself supports it*/
#define VERS_OPTIMIZED_UPDATE_FLAG (1 << 29) /* column that doesn't support
system versioning when table
itself supports it*/
#define HIDDEN_FLAG (1 << 31) /* hide from SELECT * */
#define REFRESH_GRANT (1ULL << 0) /* Refresh grant tables */

View file

@ -1424,7 +1424,7 @@ public:
bool is_versioning_disabled()
{
return flags & WITHOUT_SYSTEM_VERSIONING_FLAG;
return flags & VERS_OPTIMIZED_UPDATE_FLAG;
}
/* Mark a field as auto-generated row start column. */
@ -1444,13 +1444,13 @@ public:
/* Disable a field versioning for a versioned table. */
void disable_versioning()
{
flags |= WITHOUT_SYSTEM_VERSIONING_FLAG;
flags |= VERS_OPTIMIZED_UPDATE_FLAG;
}
/* Inherit a field versioning status from the table. */
void inherit_versioning()
{
flags &= ~WITHOUT_SYSTEM_VERSIONING_FLAG;
flags &= ~VERS_OPTIMIZED_UPDATE_FLAG;
}
/*
@ -4281,8 +4281,6 @@ bool check_expression(Virtual_column_info *vcol, const char *name,
#define FIELDFLAG_BITFIELD 512U // mangled with decimals!
#define FIELDFLAG_BLOB 1024U // mangled with decimals!
#define FIELDFLAG_GEOM 2048U // mangled with decimals!
// Do not show field in SELECT *. Hope GEOM field is never hidden.
#define FIELDFLAG_HIDDEN 2048U
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096U /* use Field_bit_as_char */
#define FIELDFLAG_LONG_DECIMAL 8192U
@ -4313,7 +4311,5 @@ bool check_expression(Virtual_column_info *vcol, const char *name,
#define f_no_default(x) ((x) & FIELDFLAG_NO_DEFAULT)
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
#define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)
#define f_without_system_versioning(x) ((x) & FIELDFLAG_WITHOUT_SYSTEM_VERSIONING)
#define f_hidden(x) ((x) & FIELDFLAG_HIDDEN)
#endif /* FIELD_INCLUDED */

View file

@ -6616,10 +6616,10 @@ bool Vers_parse_info::add_versioning_info(
if (f->versioning == Column_definition::VERSIONING_NOT_SET &&
without_system_versioning_by_default)
f->flags|= WITHOUT_SYSTEM_VERSIONING_FLAG;
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG;
else if (f->versioning == Column_definition::WITHOUT_VERSIONING)
f->flags|= WITHOUT_SYSTEM_VERSIONING_FLAG;
f->flags|= VERS_OPTIMIZED_UPDATE_FLAG;
}
// If user specified some of these he must specify the others too. Do nothing.

View file

@ -2989,10 +2989,6 @@ bool Column_definition::prepare_create_field(uint *blob_columns,
pack_flag|= FIELDFLAG_MAYBE_NULL;
if (flags & NO_DEFAULT_VALUE_FLAG)
pack_flag|= FIELDFLAG_NO_DEFAULT;
if (flags & WITHOUT_SYSTEM_VERSIONING_FLAG)
pack_flag|= FIELDFLAG_WITHOUT_SYSTEM_VERSIONING;
if (flags & HIDDEN_FLAG)
pack_flag|= FIELDFLAG_HIDDEN;
DBUG_RETURN(false);
}

View file

@ -161,7 +161,7 @@ static bool check_has_vers_fields(List<Item> &items)
while (Item *item= it++)
{
if (Item_field *item_field= item->field_for_view_update())
if (!(item_field->field->flags & WITHOUT_SYSTEM_VERSIONING_FLAG))
if (!(item_field->field->flags & VERS_OPTIMIZED_UPDATE_FLAG))
return true;
}
return false;

View file

@ -1197,7 +1197,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
uint len;
uint ext_key_parts= 0;
plugin_ref se_plugin= 0;
const uchar *system_period = 0;
const uchar *system_period= 0;
const uchar *extra2_field_flags= 0;
size_t extra2_field_flags_length= 0;
MEM_ROOT *old_root= thd->mem_root;
Virtual_column_info **table_check_constraints;
@ -1297,6 +1299,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
goto err;
system_period = extra2;
break;
case EXTRA2_FIELD_FLAGS:
if (extra2_field_flags)
goto err;
extra2_field_flags= extra2;
extra2_field_flags_length= length;
break;
default:
/* abort frm parsing if it's an unknown but important extra2 value */
if (type >= EXTRA2_ENGINE_IMPORTANT)
@ -1615,6 +1623,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
disk_buff= frm_image + pos + FRM_FORMINFO_SIZE;
share->fields= uint2korr(forminfo+258);
if (extra2_field_flags && extra2_field_flags_length != share->fields)
goto err;
pos= uint2korr(forminfo+260); /* Length of all screens */
n_length= uint2korr(forminfo+268);
interval_count= uint2korr(forminfo+270);
@ -1987,6 +1997,14 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
reg_field->field_index= i;
reg_field->comment=comment;
reg_field->vcol_info= vcol_info;
if (extra2_field_flags)
{
uchar flags= *extra2_field_flags++;
if (flags & VERS_OPTIMIZED_UPDATE)
reg_field->disable_versioning();
if (flags & HIDDEN)
reg_field->flags|= HIDDEN_FLAG;
}
if (field_type == MYSQL_TYPE_BIT && !f_bit_as_char(pack_flag))
{
null_bits_are_used= 1;
@ -2017,12 +2035,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (f_no_default(pack_flag))
reg_field->flags|= NO_DEFAULT_VALUE_FLAG;
if (f_without_system_versioning(pack_flag))
reg_field->flags|= WITHOUT_SYSTEM_VERSIONING_FLAG;
if (f_hidden(pack_flag))
reg_field->flags|= HIDDEN_FLAG;
if (reg_field->unireg_check == Field::NEXT_NUMBER)
share->found_next_number_field= field_ptr;

View file

@ -120,6 +120,16 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b
return 0;
}
bool has_extra2_field_flags(List<Create_field> &create_fields)
{
List_iterator<Create_field> it(create_fields);
while (Create_field *f= it++)
{
if (f->flags & (VERS_OPTIMIZED_UPDATE_FLAG | HIDDEN_FLAG))
return true;
}
return false;
}
/**
Create a frm (table definition) file
@ -258,6 +268,13 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table,
extra2_size+= 1 + 1 + 2 * sizeof(uint16);
}
bool has_extra2_field_flags_= has_extra2_field_flags(create_fields);
if (has_extra2_field_flags_)
{
extra2_size+=
1 + (create_fields.elements <= 255 ? 1 : 3) + create_fields.elements;
}
key_buff_length= uint4korr(fileinfo+47);
frm.length= FRM_HEADER_SIZE; // fileinfo;
@ -323,6 +340,22 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table,
pos+= sizeof(uint16);
}
if (has_extra2_field_flags_)
{
*pos++= EXTRA2_FIELD_FLAGS;
pos= extra2_write_len(pos, create_fields.elements);
List_iterator<Create_field> it(create_fields);
while (Create_field *field= it++)
{
uchar flags= 0;
if (field->flags & VERS_OPTIMIZED_UPDATE_FLAG)
flags|= VERS_OPTIMIZED_UPDATE;
if (field->flags & HIDDEN_FLAG)
flags|= HIDDEN;
*pos++= flags;
}
}
int4store(pos, filepos); // end of the extra2 segment
pos+= 4;

View file

@ -173,12 +173,18 @@ enum extra2_frm_value_type {
EXTRA2_DEFAULT_PART_ENGINE=1,
EXTRA2_GIS=2,
EXTRA2_PERIOD_FOR_SYSTEM_TIME=4,
EXTRA2_FIELD_FLAGS=8,
#define EXTRA2_ENGINE_IMPORTANT 128
EXTRA2_ENGINE_TABLEOPTS=128,
};
enum extra2_field_flags {
VERS_OPTIMIZED_UPDATE=1,
HIDDEN=2,
};
int rea_create_table(THD *thd, LEX_CUSTRING *frm,
const char *path, const char *db, const char *table_name,
HA_CREATE_INFO *create_info, handler *file,

View file

@ -9203,7 +9203,7 @@ calc_row_difference(
if (!prebuilt->upd_node->versioned &&
DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_VERSIONED) &&
!(field->flags & WITHOUT_SYSTEM_VERSIONING_FLAG))
!(field->flags & VERS_OPTIMIZED_UPDATE_FLAG))
{
prebuilt->upd_node->versioned = true;
}
@ -9315,7 +9315,7 @@ calc_row_difference(
if (!prebuilt->upd_node->versioned &&
DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_VERSIONED) &&
!(field->flags & WITHOUT_SYSTEM_VERSIONING_FLAG))
!(field->flags & VERS_OPTIMIZED_UPDATE_FLAG))
{
prebuilt->upd_node->versioned = true;
}