summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/handler.h36
-rw-r--r--sql/item.cc20
-rw-r--r--sql/item.h5
-rw-r--r--sql/partition_element.h8
-rw-r--r--sql/partition_info.cc26
-rw-r--r--sql/partition_info.h6
-rw-r--r--sql/sys_vars.ic50
-rw-r--r--sql/table.h4
8 files changed, 81 insertions, 74 deletions
diff --git a/sql/handler.h b/sql/handler.h
index 2ab9ed48c8f..a0c40d2765a 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1392,9 +1392,41 @@ struct handlerton
/*
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_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);
};
diff --git a/sql/item.cc b/sql/item.cc
index 67e59016864..5743c742900 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -6983,26 +6983,26 @@ bool Item_temporal_literal::eq(const Item *item, bool binary_cmp) const
&((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)
- {
- cached_time= *ltime;
+ if (my_time_compare(&cached_time, &ltime) < 0)
return true;
- }
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)
- {
- cached_time= *ltime;
+ if (my_time_compare(&cached_time, &ltime) > 0)
return true;
- }
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)
{
diff --git a/sql/item.h b/sql/item.h
index 6e74329eb86..ceb73c18264 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -3878,8 +3878,9 @@ public:
{
cached_time= *ltime;
}
- bool set_lower(MYSQL_TIME *ltime);
- bool set_higher(MYSQL_TIME *ltime);
+ bool operator>(const MYSQL_TIME &ltime) const;
+ bool operator<(const MYSQL_TIME &ltime) const;
+ bool operator==(const MYSQL_TIME &ltime) const;
};
diff --git a/sql/partition_element.h b/sql/partition_element.h
index 18276ef713e..723d2f21a46 100644
--- a/sql/partition_element.h
+++ b/sql/partition_element.h
@@ -90,7 +90,9 @@ typedef struct p_elem_val
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;
uchar min_buf[buf_size];
@@ -100,7 +102,7 @@ class Vers_field_stats : public Sql_alloc
mysql_rwlock_t lock;
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),
max_value(max_buf, NULL, 0, Field::NONE, field_name, share, 6)
{
@@ -108,7 +110,7 @@ public:
memset(max_buf, 0, buf_size);
mysql_rwlock_init(key_rwlock_LOCK_vers_stats, &lock);
}
- ~Vers_field_stats()
+ ~Vers_min_max_stats()
{
mysql_rwlock_destroy(&lock);
}
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index 86fb4b5bf63..8bf2e2cd72d 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -926,8 +926,8 @@ bool partition_info::vers_setup_1(THD * thd, uint32 added)
if (added)
{
DBUG_ASSERT(partitions.elements > added + 1);
- Vers_field_stats** old_array= table->s->stat_trx;
- table->s->stat_trx= static_cast<Vers_field_stats**>(
+ Vers_min_max_stats** old_array= table->s->stat_trx;
+ table->s->stat_trx= static_cast<Vers_min_max_stats**>(
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);
}
@@ -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)
{
DBUG_ASSERT(table && table->s);
- Vers_field_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 *stat_trx_end= new (&table->s->mem_root)
+ 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;
el->id= id++;
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
my_time_t ts;
part_column_list_val *col_val;
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)
{
stat_trx_x= table->s->stat_trx[idx + i];
@@ -1118,8 +1118,11 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part
col_val= &el0->get_col_val(i);
val_item= static_cast<Item_datetime_literal*>(col_val->item_expression);
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= &el1->get_col_val(i);
if (!col_val->max_value)
@@ -1128,8 +1131,11 @@ void partition_info::vers_update_col_vals(THD *thd, partition_element *el0, part
thd->variables.time_zone->gmt_sec_to_TIME(&t, ts);
val_item= static_cast<Item_datetime_literal*>(col_val->item_expression);
DBUG_ASSERT(val_item);
- if (val_item->set_higher(&t))
+ if (*val_item < t)
+ {
+ val_item->set_time(&t);
col_val->fixed= 0;
+ }
}
}
}
@@ -1162,7 +1168,7 @@ bool partition_info::vers_setup_2(THD * thd, bool is_create_table_ind)
if (!table->s->stat_trx)
{
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));
dont_stat= false;
}
@@ -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_field_stats(table->s->vers_end_field()->field_name, table->s);
+ Vers_min_max_stats *stat_trx_end= new (&table->s->mem_root)
+ 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;
}
diff --git a/sql/partition_info.h b/sql/partition_info.h
index 9dff7a41a4a..d69774e0841 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -478,14 +478,14 @@ public:
// TODO: cache thread-shared part_recs and increment on INSERT
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);
- 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);
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);
return vers_stat_trx(fld, part->id);
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic
index 27987a8d8b8..4f075c3436e 100644
--- a/sql/sys_vars.ic
+++ b/sql/sys_vars.ic
@@ -2495,32 +2495,11 @@ public:
class Sys_var_vers_asof: public sys_var
{
public:
- Sys_var_vers_asof(
- const char *name_arg,
- const char *comment,
- int flag_args,
- ptrdiff_t off,
- 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)
+ Sys_var_vers_asof(const char *name_arg, const char *comment, int flag_args,
+ ptrdiff_t off, 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;
if (global_update(def_val))
@@ -2534,31 +2513,18 @@ public:
bool update(String &in, st_vers_current_time &out)
{
- if (in.length() == 3 &&
- 0 == my_strcasecmp(
- in.charset(),
- "ALL",
- in.ptr()))
+ if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "ALL", in.ptr()))
{
out.type= FOR_SYSTEM_TIME_ALL;
}
- else if (in.length() == 3 &&
- 0 == my_strcasecmp(
- in.charset(),
- "NOW",
- in.ptr()))
+ else if (in.length() == 3 && 0 == my_strcasecmp(in.charset(), "NOW", in.ptr()))
{
out.type= FOR_SYSTEM_TIME_UNSPECIFIED;
}
else
{
MYSQL_TIME_STATUS status;
- if (str_to_datetime(
- in.ptr(),
- in.length(),
- &out.ltime,
- flags,
- &status) ||
+ if (str_to_datetime(in.ptr(), in.length(), &out.ltime, flags, &status) ||
out.ltime.time_type != MYSQL_TIMESTAMP_DATETIME ||
(status.warnings & ~MYSQL_TIME_NOTE_TRUNCATED) != 0)
{
diff --git a/sql/table.h b/sql/table.h
index 82d41ff831b..a2ede121064 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -561,7 +561,7 @@ struct TABLE_STATISTICS_CB
bool histograms_are_read;
};
-class Vers_field_stats;
+class Vers_min_max_stats;
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
@@ -755,7 +755,7 @@ struct TABLE_SHARE
uint16 row_start_field;
uint16 row_end_field;
uint32 hist_part_id;
- Vers_field_stats** stat_trx;
+ Vers_min_max_stats** stat_trx;
ulonglong stat_serial; // guards check_range_constants() updates
bool busy_rotation;