Skip to content

Commit

Permalink
Merge branch '10.3' into 10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sanja-byelkin committed Sep 2, 2019
2 parents 3ca6879 + b0ff5a6 commit 4f10d09
Show file tree
Hide file tree
Showing 44 changed files with 2,183 additions and 1,654 deletions.
2 changes: 1 addition & 1 deletion libmariadb
27 changes: 27 additions & 0 deletions mysql-test/main/partition_range.result
Expand Up @@ -987,4 +987,31 @@ a MAX(b)
SHOW status LIKE 'handler_read_key';
Variable_name Value
Handler_read_key 2
#
# MDEV-18501 Partition pruning doesn't work for historical queries
#
set time_zone= '+00:00';
create or replace table t1 (d datetime(6))
partition by range (unix_timestamp(d)) (
partition p0 values less than (1),
partition p1 values less than (maxvalue));
ERROR HY000: Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
# DECIMAL functions are now allowed, partitioning is done by integer part
create or replace table t1 (d timestamp(6))
partition by range (unix_timestamp(d)) (
partition p0 values less than (946684801),
partition p1 values less than (maxvalue));
insert into t1 values
# go to p0
('2000-01-01 00:00:00'),
('2000-01-01 00:00:00.000001'),
# goes to p1
('2000-01-01 00:00:01');
select * from t1 partition (p0);
d
2000-01-01 00:00:00.000000
2000-01-01 00:00:00.000001
select * from t1 partition (p1);
d
2000-01-01 00:00:01.000000
DROP TABLE t1, t2;
27 changes: 27 additions & 0 deletions mysql-test/main/partition_range.test
Expand Up @@ -973,4 +973,31 @@ SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
--echo # Should be no more than 4 reads.
SHOW status LIKE 'handler_read_key';

--echo #
--echo # MDEV-18501 Partition pruning doesn't work for historical queries
--echo #
set time_zone= '+00:00';
let $ts= `select unix_timestamp('2000-01-01 00:00:00') + 1`;

--error ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
create or replace table t1 (d datetime(6))
partition by range (unix_timestamp(d)) (
partition p0 values less than (1),
partition p1 values less than (maxvalue));

--echo # DECIMAL functions are now allowed, partitioning is done by integer part
eval create or replace table t1 (d timestamp(6))
partition by range (unix_timestamp(d)) (
partition p0 values less than ($ts),
partition p1 values less than (maxvalue));

insert into t1 values
# go to p0
('2000-01-01 00:00:00'),
('2000-01-01 00:00:00.000001'),
# goes to p1
('2000-01-01 00:00:01');
select * from t1 partition (p0);
select * from t1 partition (p1);

DROP TABLE t1, t2;
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/partition_rotation.result
Expand Up @@ -47,7 +47,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 for system_time as of '2001-02-04 10:20:30';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1_p1sp0,p1_p1sp1,p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where
1 SIMPLE t1 p0_p0sp0,p0_p0sp1,p2_p2sp0,p2_p2sp1,pn_pnsp0,pn_pnsp1 ALL NULL NULL NULL NULL # Using where
set @ts=(select row_end from t1 for system_time all where i=1);
select * from t1 for system_time all where row_end = @ts;
i
Expand Down
2 changes: 1 addition & 1 deletion plugin/auth_pam/testing/pam_mariadb_mtr.c
Expand Up @@ -56,7 +56,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags,
if (strcmp(r1, "crash pam module") == 0 && atoi(r2) == 616)
abort();

if (strlen(r1) == (uint)atoi(r2) % 100)
if (strlen(r1) == (size_t)atoi(r2) % 100)
retval = PAM_SUCCESS;
else
retval = PAM_AUTH_ERR;
Expand Down
2 changes: 1 addition & 1 deletion sql/item.h
Expand Up @@ -767,7 +767,7 @@ class Item: public Value_source,
/* Cache of the result of is_expensive(). */
int8 is_expensive_cache;

/* Reuse size, only used by SP local variable assignment, otherwize 0 */
/* Reuse size, only used by SP local variable assignment, otherwise 0 */
uint rsize;

protected:
Expand Down
23 changes: 6 additions & 17 deletions sql/partition_element.h
Expand Up @@ -98,7 +98,7 @@ enum stat_trx_field
class partition_element :public Sql_alloc
{
public:
enum elem_type
enum elem_type_enum
{
CONVENTIONAL= 0,
CURRENT,
Expand All @@ -125,19 +125,7 @@ class partition_element :public Sql_alloc
bool max_value; // MAXVALUE range
uint32 id;
bool empty;

// TODO: subclass partition_element by partitioning type to avoid such semantic
// mixup
elem_type type()
{
return (elem_type)(int(signed_flag) << 1 | int(max_value));
}

void type(elem_type val)
{
max_value= (bool)(val & 1);
signed_flag= (bool)(val & 2);
}
elem_type_enum type;

partition_element()
: part_max_rows(0), part_min_rows(0), range_value(0),
Expand All @@ -148,7 +136,8 @@ class partition_element :public Sql_alloc
nodegroup_id(UNDEF_NODEGROUP), has_null_value(FALSE),
signed_flag(FALSE), max_value(FALSE),
id(UINT_MAX32),
empty(true)
empty(true),
type(CONVENTIONAL)
{}
partition_element(partition_element *part_elem)
: part_max_rows(part_elem->part_max_rows),
Expand All @@ -164,13 +153,13 @@ class partition_element :public Sql_alloc
nodegroup_id(part_elem->nodegroup_id),
has_null_value(FALSE),
id(part_elem->id),
empty(part_elem->empty)
empty(part_elem->empty),
type(CONVENTIONAL)
{}
~partition_element() {}

part_column_list_val& get_col_val(uint idx)
{
DBUG_ASSERT(type() == CONVENTIONAL || list_val_list.elements == 1);
part_elem_value *ev= list_val_list.head();
DBUG_ASSERT(ev);
DBUG_ASSERT(ev->col_val_array);
Expand Down
36 changes: 13 additions & 23 deletions sql/partition_info.cc
Expand Up @@ -894,15 +894,16 @@ bool partition_info::vers_setup_expression(THD * thd, uint32 alter_add)

DBUG_ASSERT(part_type == VERSIONING_PARTITION);
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
DBUG_ASSERT(num_columns == 1);

if (!alter_add)
{
Field *row_end= table->vers_end_field();
part_field_list.push_back(row_end->field_name.str, thd->mem_root);
DBUG_ASSERT(part_field_list.elements == 1);
// needed in handle_list_of_fields()
row_end->flags|= GET_FIXED_FIELDS_FLAG;
Name_resolution_context *context= &thd->lex->current_select->context;
Item *row_end_item= new (thd->mem_root) Item_field(thd, context, row_end);
Item *row_end_ts= new (thd->mem_root) Item_func_unix_timestamp(thd, row_end_item);
set_part_expr(thd, row_end_ts, false);
}

if (alter_add)
Expand All @@ -911,12 +912,12 @@ bool partition_info::vers_setup_expression(THD * thd, uint32 alter_add)
partition_element *el;
for(uint32 id= 0; ((el= it++)); id++)
{
DBUG_ASSERT(el->type() != partition_element::CONVENTIONAL);
DBUG_ASSERT(el->type != partition_element::CONVENTIONAL);
/* Newly added element is inserted before AS_OF_NOW. */
if (el->id == UINT_MAX32 || el->type() == partition_element::CURRENT)
if (el->id == UINT_MAX32 || el->type == partition_element::CURRENT)
{
el->id= id;
if (el->type() == partition_element::CURRENT)
if (el->type == partition_element::CURRENT)
break;
}
}
Expand Down Expand Up @@ -1343,13 +1344,13 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type,
}
if (part_type == VERSIONING_PARTITION)
{
if (part_elem->type() == partition_element::HISTORY)
if (part_elem->type == partition_element::HISTORY)
{
hist_parts++;
}
else
{
DBUG_ASSERT(part_elem->type() == partition_element::CURRENT);
DBUG_ASSERT(part_elem->type == partition_element::CURRENT);
now_parts++;
}
}
Expand Down Expand Up @@ -1473,15 +1474,8 @@ void partition_info::print_no_partition_found(TABLE *table_arg, myf errflag)
FALSE Success
*/

bool partition_info::set_part_expr(THD *thd, char *start_token, Item *item_ptr,
char *end_token, bool is_subpart)
bool partition_info::set_part_expr(THD *thd, Item *item_ptr, bool is_subpart)
{
size_t expr_len= end_token - start_token;
char *func_string= (char*) thd->memdup(start_token, expr_len);

if (unlikely(!func_string))
return TRUE;

if (is_subpart)
{
list_of_subpart_fields= FALSE;
Expand Down Expand Up @@ -2654,12 +2648,9 @@ part_column_list_val *partition_info::add_column_value(THD *thd)
return NULL;
}

bool partition_info::set_part_expr(THD *thd, char *start_token, Item *item_ptr,
char *end_token, bool is_subpart)
bool partition_info::set_part_expr(THD *thd, Item *item_ptr, bool is_subpart)
{
(void)start_token;
(void)item_ptr;
(void)end_token;
(void)is_subpart;
return FALSE;
}
Expand Down Expand Up @@ -2697,9 +2688,8 @@ bool check_partition_dirs(partition_info *part_info)
bool partition_info::vers_init_info(THD * thd)
{
part_type= VERSIONING_PARTITION;
list_of_part_fields= TRUE;
column_list= TRUE;
num_columns= 1;
list_of_part_fields= true;
column_list= false;
vers_info= new (thd->mem_root) Vers_part_info;
if (unlikely(!vers_info))
return true;
Expand Down
7 changes: 3 additions & 4 deletions sql/partition_info.h
Expand Up @@ -55,11 +55,11 @@ struct Vers_part_info : public Sql_alloc
if (now_part)
{
DBUG_ASSERT(now_part->id != UINT_MAX32);
DBUG_ASSERT(now_part->type() == partition_element::CURRENT);
DBUG_ASSERT(now_part->type == partition_element::CURRENT);
if (hist_part)
{
DBUG_ASSERT(hist_part->id != UINT_MAX32);
DBUG_ASSERT(hist_part->type() == partition_element::HISTORY);
DBUG_ASSERT(hist_part->type == partition_element::HISTORY);
}
return true;
}
Expand Down Expand Up @@ -366,8 +366,7 @@ class partition_info : public Sql_alloc
void init_col_val(part_column_list_val *col_val, Item *item);
int reorganize_into_single_field_col_val(THD *thd);
part_column_list_val *add_column_value(THD *thd);
bool set_part_expr(THD *thd, char *start_token, Item *item_ptr,
char *end_token, bool is_subpart);
bool set_part_expr(THD *thd, Item *item_ptr, bool is_subpart);
bool set_up_charset_field_preps(THD *thd);
bool check_partition_field_length();
bool init_column_part(THD *thd);
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_insert.cc
Expand Up @@ -2076,7 +2076,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)


/******************************************************************************
Check that all fields with arn't null_fields are used
Check that there aren't any null_fields
******************************************************************************/


Expand Down
8 changes: 2 additions & 6 deletions sql/sql_lex.cc
Expand Up @@ -8753,11 +8753,9 @@ bool LEX::part_values_current(THD *thd)
create_last_non_select_table->table_name.str);
return true;
}
elem->type(partition_element::CURRENT);
elem->type= partition_element::CURRENT;
DBUG_ASSERT(part_info->vers_info);
part_info->vers_info->now_part= elem;
if (unlikely(part_info->init_column_part(thd)))
return true;
return false;
}

Expand Down Expand Up @@ -8787,9 +8785,7 @@ bool LEX::part_values_history(THD *thd)
create_last_non_select_table->table_name.str);
return true;
}
elem->type(partition_element::HISTORY);
if (unlikely(part_info->init_column_part(thd)))
return true;
elem->type= partition_element::HISTORY;
return false;
}

Expand Down

0 comments on commit 4f10d09

Please sign in to comment.