Commit c595ac14 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-20865 extra2 structures moved to datadict.h

datadict.h is appropriate place for such types. These data types are
used by Extra2_info, which is added to datadict.h later.

unireg.cc is for older FRM routines. datadict.cc accepts new and
refactored routines.
parent 324d1c22
......@@ -30,6 +30,132 @@ enum Table_type
TABLE_TYPE_VIEW
};
#define INVISIBLE_MAX_BITS 3
/*
Types of values in the MariaDB extra2 frm segment.
Each value is written as
type: 1 byte
length: 1 byte (1..255) or \0 and 2 bytes.
binary value of the 'length' bytes.
Older MariaDB servers can ignore values of unknown types if
the type code is less than 128 (EXTRA2_ENGINE_IMPORTANT).
Otherwise older (but newer than 10.0.1) servers are required
to report an error.
*/
enum extra2_frm_value_type
{
EXTRA2_TABLEDEF_VERSION=0,
EXTRA2_DEFAULT_PART_ENGINE=1,
EXTRA2_GIS=2,
EXTRA2_APPLICATION_TIME_PERIOD=3,
EXTRA2_PERIOD_FOR_SYSTEM_TIME=4,
EXTRA2_INDEX_FLAGS=5,
#define EXTRA2_ENGINE_IMPORTANT 128
EXTRA2_ENGINE_TABLEOPTS=128,
EXTRA2_FIELD_FLAGS=129,
EXTRA2_FIELD_DATA_TYPE_INFO=130,
EXTRA2_PERIOD_WITHOUT_OVERLAPS=131,
};
enum extra2_field_flags
{
VERS_OPTIMIZED_UPDATE= 1 << INVISIBLE_MAX_BITS,
};
enum extra2_index_flags
{
EXTRA2_DEFAULT_INDEX_FLAGS,
EXTRA2_IGNORED_KEY
};
inline size_t extra2_read_len(const uchar **pos, const uchar *end)
{
size_t length= *(*pos)++;
if (length)
return length;
if ((*pos) + 2 >= end)
return 0;
length= uint2korr(*pos);
(*pos)+= 2;
if (length < 256 || *pos + length > end)
return 0;
return length;
}
/*
write the length as
if ( 0 < length <= 255) one byte
if (256 < length <= 65535) zero byte, then two bytes, low-endian
*/
inline
uchar *extra2_write_len(uchar *pos, size_t len)
{
DBUG_ASSERT(len);
if (len <= 255)
*pos++= (uchar)len;
else
{
/*
At the moment we support options_len up to 64K.
We can easily extend it in the future, if the need arises.
*/
DBUG_ASSERT(len <= 65535);
int2store(pos + 1, len);
pos+= 3;
}
return pos;
}
inline
uchar* extra2_write_str(uchar *pos, const LEX_CSTRING str)
{
pos= extra2_write_len(pos, str.length);
memcpy(pos, str.str, str.length);
return pos + str.length;
}
inline uchar *
extra2_write(uchar *pos, enum extra2_frm_value_type type,
const LEX_CSTRING &str)
{
*pos++ = type;
return extra2_write_str(pos, str);
}
inline uchar *
extra2_write(uchar *pos, enum extra2_frm_value_type type,
const LEX_CUSTRING &str)
{
return extra2_write(pos, type, *reinterpret_cast<const LEX_CSTRING*>(&str));
}
uchar *
extra2_write_field_properties(uchar *pos, List<Create_field> &create_fields);
struct extra2_fields
{
LEX_CUSTRING version;
LEX_CUSTRING options;
Lex_ident_engine engine;
LEX_CUSTRING gis;
LEX_CUSTRING field_flags;
LEX_CUSTRING system_period;
LEX_CUSTRING application_period;
LEX_CUSTRING field_data_type_info;
LEX_CUSTRING without_overlaps;
LEX_CUSTRING index_flags;
void reset()
{ bzero((void*)this, sizeof(*this)); }
};
/*
Take extra care when using dd_frm_type() - it only checks the .frm file,
and it won't work for any engine that supports discovery.
......
......@@ -10489,7 +10489,7 @@ static int handle_grant_table(THD *thd, const Grant_table_base& grant_table,
if (which_table != PROXIES_PRIV_TABLE)
{
DBUG_PRINT("loop",("scan fields: '%s'@'%s' '%s' '%s' '%s'",
user, host,
user_from->user.str, user_from->host.str,
get_field(thd->mem_root, table->field[1]) /*db*/,
get_field(thd->mem_root, table->field[3]) /*table*/,
get_field(thd->mem_root,
......
......@@ -72,22 +72,6 @@ bool TABLE::init_expr_arena(MEM_ROOT *mem_root)
return expr_arena == NULL;
}
struct extra2_fields
{
LEX_CUSTRING version;
LEX_CUSTRING options;
Lex_ident_engine engine;
LEX_CUSTRING gis;
LEX_CUSTRING field_flags;
LEX_CUSTRING system_period;
LEX_CUSTRING application_period;
LEX_CUSTRING field_data_type_info;
LEX_CUSTRING without_overlaps;
LEX_CUSTRING index_flags;
void reset()
{ bzero((void*)this, sizeof(*this)); }
};
static Virtual_column_info * unpack_vcol_info_from_frm(THD *,
TABLE *, String *, Virtual_column_info **, bool *);
......
......@@ -407,7 +407,6 @@ enum __attribute__((packed)) field_visibility_t {
INVISIBLE_FULL
};
#define INVISIBLE_MAX_BITS 3
#define HA_HASH_FIELD_LENGTH 8
#define HA_HASH_KEY_LENGTH_WITHOUT_NULL 8
#define HA_HASH_KEY_LENGTH_WITH_NULL 9
......
......@@ -51,36 +51,7 @@ static size_t packed_fields_length(List<Create_field> &);
static bool make_empty_rec(THD *, uchar *, uint, List<Create_field> &, uint,
ulong);
/*
write the length as
if ( 0 < length <= 255) one byte
if (256 < length <= 65535) zero byte, then two bytes, low-endian
*/
static uchar *extra2_write_len(uchar *pos, size_t len)
{
DBUG_ASSERT(len);
if (len <= 255)
*pos++= (uchar)len;
else
{
/*
At the moment we support options_len up to 64K.
We can easily extend it in the future, if the need arises.
*/
DBUG_ASSERT(len <= 65535);
int2store(pos + 1, len);
pos+= 3;
}
return pos;
}
static uchar* extra2_write_str(uchar *pos, const LEX_CSTRING &str)
{
pos= extra2_write_len(pos, str.length);
memcpy(pos, str.str, str.length);
return pos + str.length;
}
inline
static uchar* extra2_write_str(uchar *pos, const Binary_string *str)
{
pos= extra2_write_len(pos, str->length());
......@@ -88,21 +59,8 @@ static uchar* extra2_write_str(uchar *pos, const Binary_string *str)
return pos + str->length();
}
static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type,
const LEX_CSTRING &str)
{
*pos++ = type;
return extra2_write_str(pos, str);
}
static uchar *extra2_write(uchar *pos, enum extra2_frm_value_type type,
const LEX_CUSTRING &str)
{
return extra2_write(pos, type, *reinterpret_cast<const LEX_CSTRING*>(&str));
}
static uchar *extra2_write_field_properties(uchar *pos,
List<Create_field> &create_fields)
uchar *
extra2_write_field_properties(uchar *pos, List<Create_field> &create_fields)
{
List_iterator<Create_field> it(create_fields);
*pos++= EXTRA2_FIELD_FLAGS;
......@@ -120,6 +78,7 @@ static uchar *extra2_write_field_properties(uchar *pos,
return pos;
}
inline
static uchar *extra2_write_index_properties(uchar *pos, const KEY *keyinfo,
uint keys)
{
......
......@@ -162,58 +162,6 @@
#include "sql_list.h" /* List<> */
#include "field.h" /* Create_field */
/*
Types of values in the MariaDB extra2 frm segment.
Each value is written as
type: 1 byte
length: 1 byte (1..255) or \0 and 2 bytes.
binary value of the 'length' bytes.
Older MariaDB servers can ignore values of unknown types if
the type code is less than 128 (EXTRA2_ENGINE_IMPORTANT).
Otherwise older (but newer than 10.0.1) servers are required
to report an error.
*/
enum extra2_frm_value_type {
EXTRA2_TABLEDEF_VERSION=0,
EXTRA2_DEFAULT_PART_ENGINE=1,
EXTRA2_GIS=2,
EXTRA2_APPLICATION_TIME_PERIOD=3,
EXTRA2_PERIOD_FOR_SYSTEM_TIME=4,
EXTRA2_INDEX_FLAGS=5,
#define EXTRA2_ENGINE_IMPORTANT 128
EXTRA2_ENGINE_TABLEOPTS=128,
EXTRA2_FIELD_FLAGS=129,
EXTRA2_FIELD_DATA_TYPE_INFO=130,
EXTRA2_PERIOD_WITHOUT_OVERLAPS=131,
};
enum extra2_field_flags {
VERS_OPTIMIZED_UPDATE= 1 << INVISIBLE_MAX_BITS,
};
enum extra2_index_flags {
EXTRA2_DEFAULT_INDEX_FLAGS,
EXTRA2_IGNORED_KEY
};
static inline size_t extra2_read_len(const uchar **extra2, const uchar *end)
{
size_t length= *(*extra2)++;
if (length)
return length;
if ((*extra2) + 2 >= end)
return 0;
length= uint2korr(*extra2);
(*extra2)+= 2;
if (length < 256 || *extra2 + length > end)
return 0;
return length;
}
LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
HA_CREATE_INFO *create_info,
......
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