Skip to content

Commit

Permalink
SQL: VIEW without VERS_COMMIT_TS + CTE fix [fixes #295]
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed Nov 13, 2017
1 parent 9aae0be commit 73f655d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 54 deletions.
1 change: 0 additions & 1 deletion mysql-test/suite/versioning/t/view.opt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--versioning-hide=implicit
--plugin-load=versioning
33 changes: 27 additions & 6 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -4587,6 +4587,12 @@ class Item_ref :public Item_ident
return 0;
return cleanup_processor(arg);
}
virtual bool vers_trx_id() const
{
DBUG_ASSERT(ref);
DBUG_ASSERT(*ref);
return (*ref)->vers_trx_id();
}
};


Expand Down Expand Up @@ -6047,16 +6053,19 @@ class Item_type_holder: public Item,
if (item->real_type() == Item::FIELD_ITEM)
{
Item_field *item_field= (Item_field *)item->real_item();
flags|= (item_field->field->flags &
m_flags|= (item_field->field->flags &
(VERS_SYS_START_FLAG | VERS_SYS_END_FLAG));
// TODO: additional field flag?
m_vers_trx_id= item_field->field->vers_trx_id();
}
}
public:
Item_type_holder(THD *thd, Item *item)
:Item(thd, item),
Type_handler_hybrid_field_type(item->real_type_handler()),
enum_set_typelib(0),
flags(0)
m_flags(0),
m_vers_trx_id(false)
{
DBUG_ASSERT(item->fixed);
maybe_null= item->maybe_null;
Expand All @@ -6071,7 +6080,8 @@ class Item_type_holder: public Item,
Type_handler_hybrid_field_type(handler),
Type_geometry_attributes(handler, attr),
enum_set_typelib(attr->get_typelib()),
flags(0)
m_flags(0),
m_vers_trx_id(false)
{
name= item->name;
Type_std_attributes::set(*attr);
Expand All @@ -6081,11 +6091,15 @@ class Item_type_holder: public Item,

const Type_handler *type_handler() const
{
const Type_handler *handler= Type_handler_hybrid_field_type::type_handler();
const Type_handler *handler= m_vers_trx_id ?
&type_handler_vers_trx_id :
Type_handler_hybrid_field_type::type_handler();
return handler->type_handler_for_item_field();
}
const Type_handler *real_type_handler() const
{
if (m_vers_trx_id)
return &type_handler_vers_trx_id;
return Type_handler_hybrid_field_type::type_handler();
}

Expand All @@ -6111,10 +6125,17 @@ class Item_type_holder: public Item,
}
Item* get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; }

uint flags;
private:
uint m_flags;
bool m_vers_trx_id;
public:
uint32 field_flags() const
{
return flags;
return m_flags;
}
virtual bool vers_trx_id() const
{
return m_vers_trx_id;
}
};

Expand Down
53 changes: 6 additions & 47 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -861,52 +861,11 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
if (vers_conditions)
{
vers_conditions.resolve_units(timestamps_only);
if (timestamps_only)
if (timestamps_only && (vers_conditions.unit_start == UNIT_TRX_ID ||
vers_conditions.unit_end == UNIT_TRX_ID))
{
if (vers_conditions.unit_start == UNIT_TRX_ID || vers_conditions.unit_end == UNIT_TRX_ID)
{
my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name);
DBUG_RETURN(-1);
}
}
else if (thd->variables.vers_innodb_algorithm_simple)
{
DBUG_ASSERT(table->table->s && table->table->s->db_plugin);
handlerton *hton= plugin_hton(table->table->s->db_plugin);
DBUG_ASSERT(hton);
bool convert_start= false;
bool convert_end= false;
switch (vers_conditions.type)
{
case FOR_SYSTEM_TIME_AS_OF:
if (vers_conditions.unit_start == UNIT_TIMESTAMP)
convert_start= convert_end= true;
break;
case FOR_SYSTEM_TIME_BEFORE:
if (vers_conditions.unit_start == UNIT_TIMESTAMP)
convert_end= true;
break;
case FOR_SYSTEM_TIME_FROM_TO:
case FOR_SYSTEM_TIME_BETWEEN:
if (vers_conditions.unit_start == UNIT_TIMESTAMP)
convert_end= true;
if (vers_conditions.unit_end == UNIT_TIMESTAMP)
convert_start= true;
default:
break;
}
if (convert_start)
row_start= newx Item_func_vtq_ts(
thd,
hton,
row_start,
VTQ_COMMIT_TS);
if (convert_end)
row_end= newx Item_func_vtq_ts(
thd,
hton,
row_end,
VTQ_COMMIT_TS);
my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name);
DBUG_RETURN(-1);
}
}

Expand Down Expand Up @@ -17481,9 +17440,9 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
if (type == Item::TYPE_HOLDER)
{
Item_type_holder *ith= (Item_type_holder*)item;
if (ith->flags & VERS_SYS_START_FLAG)
if (ith->field_flags() & VERS_SYS_START_FLAG)
sys_trx_start= new_field;
else if (ith->flags & VERS_SYS_END_FLAG)
else if (ith->field_flags() & VERS_SYS_END_FLAG)
sys_trx_end= new_field;
}
if (type == Item::SUM_FUNC_ITEM)
Expand Down
14 changes: 14 additions & 0 deletions sql/sql_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Type_handler_long type_handler_long;
Type_handler_int24 type_handler_int24;
Type_handler_longlong type_handler_longlong;
Type_handler_longlong type_handler_ulonglong; // Only used for CAST() for now
Type_handler_vers_trx_id type_handler_vers_trx_id;
Type_handler_float type_handler_float;
Type_handler_double type_handler_double;
Type_handler_bit type_handler_bit;
Expand Down Expand Up @@ -2065,6 +2066,19 @@ Field *Type_handler_longlong::make_table_field(const LEX_CSTRING *name,
}


Field *Type_handler_vers_trx_id::make_table_field(const LEX_CSTRING *name,
const Record_addr &addr,
const Type_all_attributes &attr,
TABLE *table) const
{
return new (table->in_use->mem_root)
Field_vers_trx_id(addr.ptr, attr.max_char_length(),
addr.null_ptr, addr.null_bit,
Field::NONE, name,
0/*zerofill*/, attr.unsigned_flag);
}


Field *Type_handler_float::make_table_field(const LEX_CSTRING *name,
const Record_addr &addr,
const Type_all_attributes &attr,
Expand Down
12 changes: 12 additions & 0 deletions sql/sql_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,17 @@ class Type_handler_longlong: public Type_handler_general_purpose_int
};


class Type_handler_vers_trx_id: public Type_handler_longlong
{
public:
virtual ~Type_handler_vers_trx_id() {}
Field *make_table_field(const LEX_CSTRING *name,
const Record_addr &addr,
const Type_all_attributes &attr,
TABLE *table) const;
};


class Type_handler_int24: public Type_handler_general_purpose_int
{
static const Name m_name_mediumint;
Expand Down Expand Up @@ -2905,6 +2916,7 @@ extern MYSQL_PLUGIN_IMPORT Type_handler_int24 type_handler_int24;
extern MYSQL_PLUGIN_IMPORT Type_handler_long type_handler_long;
extern MYSQL_PLUGIN_IMPORT Type_handler_longlong type_handler_longlong;
extern MYSQL_PLUGIN_IMPORT Type_handler_longlong type_handler_ulonglong;
extern MYSQL_PLUGIN_IMPORT Type_handler_vers_trx_id type_handler_vers_trx_id;

extern MYSQL_PLUGIN_IMPORT Type_handler_newdecimal type_handler_newdecimal;
extern MYSQL_PLUGIN_IMPORT Type_handler_olddecimal type_handler_olddecimal;
Expand Down

0 comments on commit 73f655d

Please sign in to comment.