Skip to content

Commit

Permalink
"AS OF" clean in Type_handler
Browse files Browse the repository at this point in the history
This patch does the following:

1. Makes Field_vers_trx_id::type_handler() return
  &type_handler_vers_trx_id rather than &type_handler_longlong.
  Fixes Item_func::convert_const_compared_to_int_field() to
  test field_item->type_handler() against &type_handler_vers_trx_id,
  instead of testing field_item->vers_trx_id().

2. Removes VERS_TRX_ID related code from
  Type_handler_hybrid_field_type::aggregate_for_comparison(),
  because "BIGINT UNSIGNED GENERATED ALWAYS AS ROW {START|END}"
  columns behave just like a BIGINT in a regular comparison,
  i.e. when not inside AS OF.

3. Removes
   - Type_handler_hybrid_field_type::m_vers_trx_id;
   - Type_handler_hybrid_field_type::m_flags;
  because a "BIGINT UNSIGNED GENERATED ALWAYS AS ROW {START|END}"
  behaves like a regular BIGINT column when in UNION.

4. Removes Field::vers_trx_id(), Item::vers_trx_id(), Item::field_flags()
  They are not needed anymore. See N1.
  • Loading branch information
abarkov committed Apr 23, 2018
1 parent 14f84d2 commit 8fce406
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 82 deletions.
12 changes: 1 addition & 11 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -1461,11 +1461,6 @@ class Field: public Value_source
return flags & VERS_UPDATE_UNVERSIONED_FLAG;
}

virtual bool vers_trx_id() const
{
return false;
}

/*
Validate a non-null field value stored in the given record
according to the current thread settings, e.g. sql_mode.
Expand Down Expand Up @@ -2313,8 +2308,7 @@ class Field_vers_trx_id :public Field_longlong {
unsigned_arg),
cached(0)
{}
enum_field_types real_type() const { return MYSQL_TYPE_LONGLONG; }
enum_field_types type() const { return MYSQL_TYPE_LONGLONG;}
const Type_handler *type_handler() const { return &type_handler_vers_trx_id; }
uint size_of() const { return sizeof(*this); }
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate, ulonglong trx_id);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
Expand All @@ -2341,10 +2335,6 @@ class Field_vers_trx_id :public Field_longlong {
}
/* cmp_type() cannot be TIME_RESULT, because we want to compare this field against
integers. But in all other cases we treat it as TIME_RESULT! */
bool vers_trx_id() const
{
return true;
}
};


Expand Down
3 changes: 2 additions & 1 deletion sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6854,7 +6854,8 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int f
f->flags= flags | NOT_NULL_FLAG;
if (integer)
{
f->set_handler(&type_handler_longlong);
DBUG_ASSERT(0); // Not implemented yet
f->set_handler(&type_handler_vers_trx_id);
f->length= MY_INT64_NUM_DECIMAL_DIGITS - 1;
f->flags|= UNSIGNED_FLAG;
}
Expand Down
5 changes: 0 additions & 5 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10700,11 +10700,6 @@ Item_field::excl_dep_on_grouping_fields(st_select_lex *sel)
return find_matching_grouping_field(this, sel) != NULL;
}

bool Item_field::vers_trx_id() const
{
DBUG_ASSERT(field);
return field->vers_trx_id();
}

void Item::register_in(THD *thd)
{
Expand Down
59 changes: 4 additions & 55 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,6 @@ class Item: public Value_source,
return type_handler()->field_type();
}
virtual const Type_handler *type_handler() const= 0;
virtual uint field_flags() const
{
return 0;
}
const Type_handler *type_handler_for_comparison() const
{
return type_handler()->type_handler_for_comparison();
Expand Down Expand Up @@ -1814,8 +1810,6 @@ class Item: public Value_source,

virtual Item_field *field_for_view_update() { return 0; }

virtual bool vers_trx_id() const
{ return false; }
virtual Item *neg_transformer(THD *thd) { return NULL; }
virtual Item *update_value_transformer(THD *thd, uchar *select_arg)
{ return this; }
Expand Down Expand Up @@ -2941,10 +2935,6 @@ class Item_field :public Item_ident,
return field->type_handler();
}
TYPELIB *get_typelib() const { return field->get_typelib(); }
uint32 field_flags() const
{
return field->flags;
}
enum_monotonicity_info get_monotonicity_info() const
{
return MONOTONIC_STRICT_INCREASING;
Expand Down Expand Up @@ -3042,7 +3032,6 @@ class Item_field :public Item_ident,
uint32 max_display_length() const { return field->max_display_length(); }
Item_field *field_for_view_update() { return this; }
int fix_outer_field(THD *thd, Field **field, Item **reference);
virtual bool vers_trx_id() const;
virtual Item *update_value_transformer(THD *thd, uchar *select_arg);
Item *derived_field_transformer_for_having(THD *thd, uchar *arg);
Item *derived_field_transformer_for_where(THD *thd, uchar *arg);
Expand Down Expand Up @@ -4890,12 +4879,6 @@ 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 @@ -6392,29 +6375,14 @@ class Item_type_holder: public Item,
{
protected:
TYPELIB *enum_set_typelib;
private:
void init_flags(Item *item)
{
if (item->real_type() == Item::FIELD_ITEM)
{
Item_field *item_field= (Item_field *)item->real_item();
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),
m_flags(0),
m_vers_trx_id(false)
enum_set_typelib(0)
{
DBUG_ASSERT(item->fixed);
maybe_null= item->maybe_null;
init_flags(item);
}
Item_type_holder(THD *thd,
Item *item,
Expand All @@ -6424,27 +6392,20 @@ class Item_type_holder: public Item,
:Item(thd),
Type_handler_hybrid_field_type(handler),
Type_geometry_attributes(handler, attr),
enum_set_typelib(attr->get_typelib()),
m_flags(0),
m_vers_trx_id(false)
enum_set_typelib(attr->get_typelib())
{
name= item->name;
Type_std_attributes::set(*attr);
maybe_null= maybe_null_arg;
init_flags(item);
}

const Type_handler *type_handler() const
{
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();
return Type_handler_hybrid_field_type::type_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 @@ -6471,18 +6432,6 @@ class Item_type_holder: public Item,
}
Item* get_copy(THD *thd) { return 0; }

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


Expand Down
6 changes: 2 additions & 4 deletions sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,9 @@ Type_handler_hybrid_field_type::aggregate_for_comparison(const char *funcname,
many cases.
*/
set_handler(items[0]->type_handler()->type_handler_for_comparison());
m_vers_trx_id= items[0]->vers_trx_id();
for (uint i= 1 ; i < nitems ; i++)
{
unsigned_count+= items[i]->unsigned_flag;
if (!m_vers_trx_id)
m_vers_trx_id= items[i]->vers_trx_id();
if (aggregate_for_comparison(items[i]->type_handler()->
type_handler_for_comparison()))
{
Expand Down Expand Up @@ -423,7 +420,8 @@ void Item_func::convert_const_compared_to_int_field(THD *thd)
args[field= 1]->real_item()->type() == FIELD_ITEM)
{
Item_field *field_item= (Item_field*) (args[field]->real_item());
if (((field_item->field_type() == MYSQL_TYPE_LONGLONG && !field_item->vers_trx_id()) ||
if (((field_item->field_type() == MYSQL_TYPE_LONGLONG &&
field_item->type_handler() != &type_handler_vers_trx_id) ||
field_item->field_type() == MYSQL_TYPE_YEAR))
convert_const_to_int(thd, field_item, &args[!field]);
}
Expand Down
4 changes: 1 addition & 3 deletions sql/sql_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@ Type_handler_hybrid_field_type::aggregate_for_comparison(const Type_handler *h)

Item_result a= cmp_type();
Item_result b= h->cmp_type();
if (m_vers_trx_id && (a == STRING_RESULT || b == STRING_RESULT))
m_type_handler= &type_handler_datetime;
else if (a == STRING_RESULT && b == STRING_RESULT)
if (a == STRING_RESULT && b == STRING_RESULT)
m_type_handler= &type_handler_long_blob;
else if (a == INT_RESULT && b == INT_RESULT)
m_type_handler= &type_handler_longlong;
Expand Down
5 changes: 2 additions & 3 deletions sql/sql_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -3291,16 +3291,15 @@ class Type_handler_set: public Type_handler_typelib
class Type_handler_hybrid_field_type
{
const Type_handler *m_type_handler;
bool m_vers_trx_id;
bool aggregate_for_min_max(const Type_handler *other);

public:
Type_handler_hybrid_field_type();
Type_handler_hybrid_field_type(const Type_handler *handler)
:m_type_handler(handler), m_vers_trx_id(false)
:m_type_handler(handler)
{ }
Type_handler_hybrid_field_type(const Type_handler_hybrid_field_type *other)
:m_type_handler(other->m_type_handler), m_vers_trx_id(other->m_vers_trx_id)
:m_type_handler(other->m_type_handler)
{ }
void swap(Type_handler_hybrid_field_type &other)
{
Expand Down

0 comments on commit 8fce406

Please sign in to comment.