Commit a734c2f0 authored by Aleksey Midenkov's avatar Aleksey Midenkov

Style: partitioning, sysvars, handler fixes

* Sys_var_vers_asof formatting
* Vers_field_stats renamed to Vers_min_max_stats
* Item_temporal_literal::set_lower()/set_higher() replaced by operator>()/operator<()
* handler API comments
parent 40e3922a
...@@ -1392,9 +1392,41 @@ struct handlerton ...@@ -1392,9 +1392,41 @@ struct handlerton
/* /*
System Versioning System Versioning
*/ */
/**
Query VTQ by TRX_ID.
@param[in] thd MySQL thread
@param[out] out field value or whole record returned by query (selected by `field`)
@param[in] in_trx_id query parameter TRX_ID
@param[in] field field to get in `out` or VTQ_ALL for whole record (vtq_record_t)
@return TRUE if record is found, FALSE otherwise */
bool (*vers_query_trx_id)(THD* thd, void *out, ulonglong trx_id, vtq_field_t field); bool (*vers_query_trx_id)(THD* thd, void *out, ulonglong trx_id, vtq_field_t field);
bool (*vers_query_commit_ts)(THD* thd, void *out, const MYSQL_TIME &commit_ts, vtq_field_t field, bool backwards);
bool (*vers_trx_sees)(THD *thd, bool &result, ulonglong trx_id1, ulonglong trx_id0, ulonglong commit_id1, uchar iso_level1, ulonglong commit_id0); /** Query VTQ by COMMIT_TS.
@param[in] thd MySQL thread
@param[out] out field value or whole record returned by query (selected by `field`)
@param[in] commit_ts query parameter COMMIT_TS
@param[in] field field to get in `out` or VTQ_ALL for whole record (vtq_record_t)
@param[in] backwards direction of VTQ search
@return TRUE if record is found, FALSE otherwise */
bool (*vers_query_commit_ts)(THD* thd, void *out, const MYSQL_TIME &commit_ts,
vtq_field_t field, bool backwards);
/** Check if transaction TX1 sees transaction TX0.
@param[in] thd MySQL thread
@param[out] result true if TX1 sees TX0
@param[in] trx_id1 TX1 TRX_ID
@param[in] trx_id0 TX0 TRX_ID
@param[in] commit_id1 TX1 COMMIT_ID
@param[in] iso_level1 TX1 isolation level
@param[in] commit_id0 TX0 COMMIT_ID
@return FALSE if there is no trx_id1 in VTQ, otherwise TRUE */
bool (*vers_trx_sees)(THD *thd, bool &result, ulonglong trx_id1, ulonglong trx_id0,
ulonglong commit_id1, uchar iso_level1, ulonglong commit_id0);
/** Upgrade InnoDB table handler to InnoDB partitioning handler.
@param[in] hnd InnoDB table handler
@param[in] mem_root mem_root for resulting handler
@return InnoDB partitioning handler or NULL on error */
handler *(*vers_upgrade_handler)(handler *hnd, MEM_ROOT *mem_root); handler *(*vers_upgrade_handler)(handler *hnd, MEM_ROOT *mem_root);
}; };
......
...@@ -6983,26 +6983,26 @@ bool Item_temporal_literal::eq(const Item *item, bool binary_cmp) const ...@@ -6983,26 +6983,26 @@ bool Item_temporal_literal::eq(const Item *item, bool binary_cmp) const
&((Item_temporal_literal *) item)->cached_time); &((Item_temporal_literal *) item)->cached_time);
} }
bool Item_temporal_literal::set_lower(MYSQL_TIME * ltime) bool Item_temporal_literal::operator<(const MYSQL_TIME &ltime) const
{ {
if (my_time_compare(ltime, &cached_time) < 0) if (my_time_compare(&cached_time, &ltime) < 0)
{
cached_time= *ltime;
return true; return true;
}
return false; return false;
} }
bool Item_temporal_literal::set_higher(MYSQL_TIME * ltime) bool Item_temporal_literal::operator>(const MYSQL_TIME &ltime) const
{ {
if (my_time_compare(ltime, &cached_time) > 0) if (my_time_compare(&cached_time, &ltime) > 0)
{
cached_time= *ltime;
return true; return true;
}
return false; return false;
} }
bool Item_temporal_literal::operator==(const MYSQL_TIME &ltime) const
{
if (my_time_compare(&cached_time, &ltime) == 0)
return true;
return false;
}
void Item_date_literal::print(String *str, enum_query_type query_type) void Item_date_literal::print(String *str, enum_query_type query_type)
{ {
......
...@@ -3878,8 +3878,9 @@ class Item_temporal_literal :public Item_basic_constant ...@@ -3878,8 +3878,9 @@ class Item_temporal_literal :public Item_basic_constant
{ {
cached_time= *ltime; cached_time= *ltime;
} }
bool set_lower(MYSQL_TIME *ltime); bool operator>(const MYSQL_TIME &ltime) const;
bool set_higher(MYSQL_TIME *ltime); bool operator<(const MYSQL_TIME &ltime) const;
bool operator==(const MYSQL_TIME &ltime) const;
}; };
......
...@@ -90,7 +90,9 @@ typedef struct p_elem_val ...@@ -90,7 +90,9 @@ typedef struct p_elem_val
struct st_ddl_log_memory_entry; struct st_ddl_log_memory_entry;
class Vers_field_stats : public Sql_alloc /* Used for collecting MIN/MAX stats on sys_trx_end for doing pruning
in SYSTEM_TIME partitiong. */
class Vers_min_max_stats : public Sql_alloc
{ {
static const uint buf_size= 4 + (TIME_SECOND_PART_DIGITS + 1) / 2; static const uint buf_size= 4 + (TIME_SECOND_PART_DIGITS + 1) / 2;
uchar min_buf[buf_size]; uchar min_buf[buf_size];
...@@ -100,7 +102,7 @@ class Vers_field_stats : public Sql_alloc ...@@ -100,7 +102,7 @@ class Vers_field_stats : public Sql_alloc
mysql_rwlock_t lock; mysql_rwlock_t lock;
public: public:
Vers_field_stats(const char *field_name, TABLE_SHARE *share) : Vers_min_max_stats(const char *field_name, TABLE_SHARE *share) :
min_value(min_buf, NULL, 0, Field::NONE, field_name, share, 6), min_value(min_buf, NULL, 0, Field::NONE, field_name, share, 6),
max_value(max_buf, NULL, 0, Field::NONE, field_name, share, 6) max_value(max_buf, NULL, 0, Field::NONE, field_name, share, 6)
{ {
...@@ -108,7 +110,7 @@ class Vers_field_stats : public Sql_alloc ...@@ -108,7 +110,7 @@ class Vers_field_stats : public Sql_alloc
memset(max_buf, 0, buf_size); memset(max_buf, 0, buf_size);
mysql_rwlock_init(key_rwlock_LOCK_vers_stats, &lock); mysql_rwlock_init(key_rwlock_LOCK_vers_stats, &lock);
} }
~Vers_field_stats() ~Vers_min_max_stats()
{ {
mysql_rwlock_destroy(&lock); mysql_rwlock_destroy(&lock);
} }
......
...@@ -926,8 +926,8 @@ bool partition_info::vers_setup_1(THD * thd, uint32 added) ...@@ -926,8 +926,8 @@ bool partition_info::vers_setup_1(THD * thd, uint32 added)
if (added) if (added)
{ {
DBUG_ASSERT(partitions.elements > added + 1); DBUG_ASSERT(partitions.elements > added + 1);
Vers_field_stats** old_array= table->s->stat_trx; Vers_min_max_stats** old_array= table->s->stat_trx;
table->s->stat_trx= static_cast<Vers_field_stats**>( table->s->stat_trx= static_cast<Vers_min_max_stats**>(
alloc_root(&table->s->mem_root, sizeof(void *) * partitions.elements * num_columns)); alloc_root(&table->s->mem_root, sizeof(void *) * partitions.elements * num_columns));
memcpy(table->s->stat_trx, old_array, sizeof(void *) * (partitions.elements - added) * num_columns); memcpy(table->s->stat_trx, old_array, sizeof(void *) * (partitions.elements - added) * num_columns);
} }
...@@ -961,8 +961,8 @@ bool partition_info::vers_setup_1(THD * thd, uint32 added) ...@@ -961,8 +961,8 @@ bool partition_info::vers_setup_1(THD * thd, uint32 added)
if (el->id == UINT32_MAX || el->type == partition_element::AS_OF_NOW) if (el->id == UINT32_MAX || el->type == partition_element::AS_OF_NOW)
{ {
DBUG_ASSERT(table && table->s); DBUG_ASSERT(table && table->s);
Vers_field_stats *stat_trx_end= new (&table->s->mem_root) Vers_min_max_stats *stat_trx_end= new (&table->s->mem_root)
Vers_field_stats(table->s->vers_end_field()->field_name, table->s); Vers_min_max_stats(table->s->vers_end_field()->field_name, table->s);
table->s->stat_trx[id * num_columns + STAT_TRX_END]= stat_trx_end; table->s->stat_trx[id * num_columns + STAT_TRX_END]= stat_trx_end;
el->id= id++; el->id= id++;
if (el->type == partition_element::AS_OF_NOW) if (el->type == partition_element::AS_OF_NOW)
...@@ -1107,7 +1107,7 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part ...@@ -1107,7 +1107,7 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part
my_time_t ts; my_time_t ts;
part_column_list_val *col_val; part_column_list_val *col_val;
Item_datetime_literal *val_item; Item_datetime_literal *val_item;
Vers_field_stats *stat_trx_x; Vers_min_max_stats *stat_trx_x;
for (uint i= 0; i < num_columns; ++i) for (uint i= 0; i < num_columns; ++i)
{ {
stat_trx_x= table->s->stat_trx[idx + i]; stat_trx_x= table->s->stat_trx[idx + i];
...@@ -1118,9 +1118,12 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part ...@@ -1118,9 +1118,12 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part
col_val= &el0->get_col_val(i); col_val= &el0->get_col_val(i);
val_item= static_cast<Item_datetime_literal*>(col_val->item_expression); val_item= static_cast<Item_datetime_literal*>(col_val->item_expression);
DBUG_ASSERT(val_item); DBUG_ASSERT(val_item);
if (val_item->set_lower(&t)) if (*val_item > t)
{
val_item->set_time(&t);
col_val->fixed= 0; col_val->fixed= 0;
} }
}
col_val= &el1->get_col_val(i); col_val= &el1->get_col_val(i);
if (!col_val->max_value) if (!col_val->max_value)
{ {
...@@ -1128,10 +1131,13 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part ...@@ -1128,10 +1131,13 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part
thd->variables.time_zone->gmt_sec_to_TIME(&t, ts); thd->variables.time_zone->gmt_sec_to_TIME(&t, ts);
val_item= static_cast<Item_datetime_literal*>(col_val->item_expression); val_item= static_cast<Item_datetime_literal*>(col_val->item_expression);
DBUG_ASSERT(val_item); DBUG_ASSERT(val_item);
if (val_item->set_higher(&t)) if (*val_item < t)
{
val_item->set_time(&t);
col_val->fixed= 0; col_val->fixed= 0;
} }
} }
}
} }
...@@ -1162,7 +1168,7 @@ bool partition_info::vers_setup_2(THD * thd, bool is_create_table_ind) ...@@ -1162,7 +1168,7 @@ bool partition_info::vers_setup_2(THD * thd, bool is_create_table_ind)
if (!table->s->stat_trx) if (!table->s->stat_trx)
{ {
DBUG_ASSERT(partitions.elements > 1); DBUG_ASSERT(partitions.elements > 1);
table->s->stat_trx= static_cast<Vers_field_stats**>( table->s->stat_trx= static_cast<Vers_min_max_stats**>(
alloc_root(&table->s->mem_root, sizeof(void *) * partitions.elements * num_columns)); alloc_root(&table->s->mem_root, sizeof(void *) * partitions.elements * num_columns));
dont_stat= false; dont_stat= false;
} }
...@@ -1183,8 +1189,8 @@ bool partition_info::vers_setup_2(THD * thd, bool is_create_table_ind) ...@@ -1183,8 +1189,8 @@ bool partition_info::vers_setup_2(THD * thd, bool is_create_table_ind)
} }
{ {
Vers_field_stats *stat_trx_end= new (&table->s->mem_root) Vers_min_max_stats *stat_trx_end= new (&table->s->mem_root)
Vers_field_stats(table->s->vers_end_field()->field_name, table->s); Vers_min_max_stats(table->s->vers_end_field()->field_name, table->s);
table->s->stat_trx[el->id * num_columns + STAT_TRX_END]= stat_trx_end; table->s->stat_trx[el->id * num_columns + STAT_TRX_END]= stat_trx_end;
} }
......
...@@ -478,14 +478,14 @@ class partition_info : public Sql_alloc ...@@ -478,14 +478,14 @@ class partition_info : public Sql_alloc
// TODO: cache thread-shared part_recs and increment on INSERT // TODO: cache thread-shared part_recs and increment on INSERT
return table->file->part_records(part) >= vers_info->limit; return table->file->part_records(part) >= vers_info->limit;
} }
Vers_field_stats& vers_stat_trx(stat_trx_field fld, uint32 part_element_id) Vers_min_max_stats& vers_stat_trx(stat_trx_field fld, uint32 part_element_id)
{ {
DBUG_ASSERT(table && table->s && table->s->stat_trx); DBUG_ASSERT(table && table->s && table->s->stat_trx);
Vers_field_stats* res= table->s->stat_trx[part_element_id * num_columns + fld]; Vers_min_max_stats* res= table->s->stat_trx[part_element_id * num_columns + fld];
DBUG_ASSERT(res); DBUG_ASSERT(res);
return *res; return *res;
} }
Vers_field_stats& vers_stat_trx(stat_trx_field fld, partition_element *part) Vers_min_max_stats& vers_stat_trx(stat_trx_field fld, partition_element *part)
{ {
DBUG_ASSERT(part); DBUG_ASSERT(part);
return vers_stat_trx(fld, part->id); return vers_stat_trx(fld, part->id);
......
...@@ -2495,32 +2495,11 @@ public: ...@@ -2495,32 +2495,11 @@ public:
class Sys_var_vers_asof: public sys_var class Sys_var_vers_asof: public sys_var
{ {
public: public:
Sys_var_vers_asof( Sys_var_vers_asof(const char *name_arg, const char *comment, int flag_args,
const char *name_arg, ptrdiff_t off, size_t size, CMD_LINE getopt, enum charset_enum is_os_charset_arg,
const char *comment, const char *def_val, on_check_function on_check_func=0, on_update_function on_update_func=0) :
int flag_args, sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id, getopt.arg_type,
ptrdiff_t off, SHOW_CHAR, (intptr) def_val, 0, VARIABLE_NOT_IN_BINLOG, on_check_func, on_update_func, 0)
size_t size,
CMD_LINE getopt,
enum charset_enum is_os_charset_arg,
const char *def_val,
on_check_function on_check_func=0,
on_update_function on_update_func=0) :
sys_var(
&all_sys_vars,
name_arg,
comment,
flag_args,
off,
getopt.id,
getopt.arg_type,
SHOW_CHAR,
(intptr) def_val,
0,
VARIABLE_NOT_IN_BINLOG,
on_check_func,
on_update_func,
0)
{ {
option.var_type|= GET_STR; option.var_type|= GET_STR;
if (global_update(def_val)) if (global_update(def_val))
...@@ -2534,31 +2513,18 @@ public: ...@@ -2534,31 +2513,18 @@ public:
bool update(String &in, st_vers_current_time &out) bool update(String &in, st_vers_current_time &out)
{ {
if (in.length() == 3 && if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "ALL", in.ptr()))
0 == my_strcasecmp(
in.charset(),
"ALL",
in.ptr()))
{ {
out.type= FOR_SYSTEM_TIME_ALL; out.type= FOR_SYSTEM_TIME_ALL;
} }
else if (in.length() == 3 && else if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "NOW", in.ptr()))
0 == my_strcasecmp(
in.charset(),
"NOW",
in.ptr()))
{ {
out.type= FOR_SYSTEM_TIME_UNSPECIFIED; out.type= FOR_SYSTEM_TIME_UNSPECIFIED;
} }
else else
{ {
MYSQL_TIME_STATUS status; MYSQL_TIME_STATUS status;
if (str_to_datetime( if (str_to_datetime(in.ptr(), in.length(), &out.ltime, flags, &status) ||
in.ptr(),
in.length(),
&out.ltime,
flags,
&status) ||
out.ltime.time_type != MYSQL_TIMESTAMP_DATETIME || out.ltime.time_type != MYSQL_TIMESTAMP_DATETIME ||
(status.warnings & ~MYSQL_TIME_NOTE_TRUNCATED) != 0) (status.warnings & ~MYSQL_TIME_NOTE_TRUNCATED) != 0)
{ {
......
...@@ -561,7 +561,7 @@ struct TABLE_STATISTICS_CB ...@@ -561,7 +561,7 @@ struct TABLE_STATISTICS_CB
bool histograms_are_read; bool histograms_are_read;
}; };
class Vers_field_stats; class Vers_min_max_stats;
#ifndef UINT32_MAX #ifndef UINT32_MAX
#define UINT32_MAX (4294967295U) #define UINT32_MAX (4294967295U)
...@@ -755,7 +755,7 @@ struct TABLE_SHARE ...@@ -755,7 +755,7 @@ struct TABLE_SHARE
uint16 row_start_field; uint16 row_start_field;
uint16 row_end_field; uint16 row_end_field;
uint32 hist_part_id; uint32 hist_part_id;
Vers_field_stats** stat_trx; Vers_min_max_stats** stat_trx;
ulonglong stat_serial; // guards check_range_constants() updates ulonglong stat_serial; // guards check_range_constants() updates
bool busy_rotation; bool busy_rotation;
......
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