Commit 966d0eba authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#54483: valgrind errors when making warnings for multiline inserts into partition

Bug#57071: EXTRACT(WEEK from date_col) cannot be allowed as partitioning function

There were functions allowed as partitioning functions
that implicit allowed cast. That could result in unacceptable
behaviour.

Solution was to check that the arguments of date and time functions
have allowed types (field and date/datetime/time depending on function).
parent c676f125
...@@ -1778,7 +1778,7 @@ c1 bigint, ...@@ -1778,7 +1778,7 @@ c1 bigint,
c2 set('sweet'), c2 set('sweet'),
key (c2,c1,c0), key (c2,c1,c0),
key(c0) key(c0)
) engine=myisam partition by hash (month(c0)) partitions 5; ) engine=myisam partition by hash (c0) partitions 5;
insert ignore into t1 set c0 = -6502262, c1 = 3992917, c2 = 35019; insert ignore into t1 set c0 = -6502262, c1 = 3992917, c2 = 35019;
insert ignore into t1 set c0 = 241221, c1 = -6862346, c2 = 56644; insert ignore into t1 set c0 = 241221, c1 = -6862346, c2 = 56644;
select c1 from t1 group by (select c0 from t1 limit 1); select c1 from t1 group by (select c0 from t1 limit 1);
......
This diff is collapsed.
...@@ -88,8 +88,9 @@ let $val2 = '2006-01-17'; ...@@ -88,8 +88,9 @@ let $val2 = '2006-01-17';
let $val3 = '2006-02-25'; let $val3 = '2006-02-25';
let $val4 = '2006-02-05'; let $val4 = '2006-02-05';
--source suite/parts/inc/partition_supported_sql_funcs.inc --source suite/parts/inc/partition_supported_sql_funcs.inc
let $coltype = char(30); # Disabled after fixing bug#54483.
--source suite/parts/inc/partition_supported_sql_funcs.inc #let $coltype = char(30);
#--source suite/parts/inc/partition_supported_sql_funcs.inc
let $sqlfunc = extract(month from col1); let $sqlfunc = extract(month from col1);
let $valsqlfunc = extract(year from '1998-11-23'); let $valsqlfunc = extract(year from '1998-11-23');
...@@ -139,8 +140,9 @@ let $val2 = '14:30:20'; ...@@ -139,8 +140,9 @@ let $val2 = '14:30:20';
let $val3 = '21:59:22'; let $val3 = '21:59:22';
let $val4 = '10:22:33'; let $val4 = '10:22:33';
--source suite/parts/inc/partition_supported_sql_funcs.inc --source suite/parts/inc/partition_supported_sql_funcs.inc
let $coltype = char(30); # second(non_time_col) is disabled after bug#54483.
--source suite/parts/inc/partition_supported_sql_funcs.inc #let $coltype = char(30);
#--source suite/parts/inc/partition_supported_sql_funcs.inc
let $sqlfunc = month(col1); let $sqlfunc = month(col1);
let $valsqlfunc = month('2006-10-14'); let $valsqlfunc = month('2006-10-14');
...@@ -172,26 +174,28 @@ let $val3 = '21:59:22'; ...@@ -172,26 +174,28 @@ let $val3 = '21:59:22';
let $val4 = '10:33:11'; let $val4 = '10:33:11';
--source suite/parts/inc/partition_supported_sql_funcs.inc --source suite/parts/inc/partition_supported_sql_funcs.inc
let $sqlfunc = to_days(col1)-to_days('2006-01-01'); # to_days(non_date_col) is disabled after bug#54483.
let $valsqlfunc = to_days('2006-02-02')-to_days('2006-01-01'); #let $sqlfunc = to_days(col1)-to_days('2006-01-01');
let $coltype = date; #let $valsqlfunc = to_days('2006-02-02')-to_days('2006-01-01');
let $infile = part_supported_sql_funcs_int_date.inc; #let $coltype = date;
let $val1 = '2006-02-03'; #let $infile = part_supported_sql_funcs_int_date.inc;
let $val2 = '2006-01-17'; #let $val1 = '2006-02-03';
let $val3 = '2006-01-25'; #let $val2 = '2006-01-17';
let $val4 = '2006-02-06'; #let $val3 = '2006-01-25';
--source suite/parts/inc/partition_supported_sql_funcs.inc #let $val4 = '2006-02-06';
#--source suite/parts/inc/partition_supported_sql_funcs.inc
# to_days(non_date_col) is disabled after bug#54483.
# DATEDIFF() is implemented as (TO_DAYS(d1) - TO_DAYS(d2)) # DATEDIFF() is implemented as (TO_DAYS(d1) - TO_DAYS(d2))
let $sqlfunc = datediff(col1, '2006-01-01'); #let $sqlfunc = datediff(col1, '2006-01-01');
let $valsqlfunc = datediff('2006-02-02', '2006-01-01'); #let $valsqlfunc = datediff('2006-02-02', '2006-01-01');
let $coltype = date; #let $coltype = date;
let $infile = part_supported_sql_funcs_int_date.inc; #let $infile = part_supported_sql_funcs_int_date.inc;
let $val1 = '2006-02-03'; #let $val1 = '2006-02-03';
let $val2 = '2006-01-17'; #let $val2 = '2006-01-17';
let $val3 = '2006-01-25'; #let $val3 = '2006-01-25';
let $val4 = '2006-02-06'; #let $val4 = '2006-02-06';
--source suite/parts/inc/partition_supported_sql_funcs.inc #--source suite/parts/inc/partition_supported_sql_funcs.inc
let $sqlfunc = weekday(col1); let $sqlfunc = weekday(col1);
let $valsqlfunc = weekday('2006-10-14'); let $valsqlfunc = weekday('2006-10-14');
......
...@@ -1821,15 +1821,16 @@ while ($cnt) ...@@ -1821,15 +1821,16 @@ while ($cnt)
drop table t1; drop table t1;
# #
# BUG#32272: partition crash 1: enum column # BUG#32772: partition crash 1: enum column
# #
# Note that month(int_col) is disallowed after bug#54483.
create table t1 ( create table t1 (
c0 int, c0 int,
c1 bigint, c1 bigint,
c2 set('sweet'), c2 set('sweet'),
key (c2,c1,c0), key (c2,c1,c0),
key(c0) key(c0)
) engine=myisam partition by hash (month(c0)) partitions 5; ) engine=myisam partition by hash (c0) partitions 5;
--disable_warnings --disable_warnings
insert ignore into t1 set c0 = -6502262, c1 = 3992917, c2 = 35019; insert ignore into t1 set c0 = -6502262, c1 = 3992917, c2 = 35019;
......
This diff is collapsed.
...@@ -966,11 +966,11 @@ public: ...@@ -966,11 +966,11 @@ public:
virtual bool set_no_const_sub(uchar *arg) { return FALSE; } virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
virtual Item *replace_equal_field(uchar * arg) { return this; } virtual Item *replace_equal_field(uchar * arg) { return this; }
/* /*
Check if an expression value depends on the current timezone. Used by Check if an expression value has allowed arguments, like DATE/DATETIME
partitioning code to reject timezone-dependent expressions in a for date functions. Also used by partitioning code to reject
(sub)partitioning function. timezone-dependent expressions in a (sub)partitioning function.
*/ */
virtual bool is_timezone_dependent_processor(uchar *bool_arg) virtual bool is_arguments_valid_processor(uchar *bool_arg)
{ {
return FALSE; return FALSE;
} }
......
...@@ -189,6 +189,7 @@ public: ...@@ -189,6 +189,7 @@ public:
null_value=1; null_value=1;
return 0.0; return 0.0;
} }
bool has_timestamp_args() bool has_timestamp_args()
{ {
DBUG_ASSERT(fixed == TRUE); DBUG_ASSERT(fixed == TRUE);
...@@ -200,6 +201,45 @@ public: ...@@ -200,6 +201,45 @@ public:
} }
return FALSE; return FALSE;
} }
bool has_date_args()
{
DBUG_ASSERT(fixed == TRUE);
for (uint i= 0; i < arg_count; i++)
{
if (args[i]->type() == Item::FIELD_ITEM &&
(args[i]->field_type() == MYSQL_TYPE_DATE ||
args[i]->field_type() == MYSQL_TYPE_DATETIME))
return TRUE;
}
return FALSE;
}
bool has_time_args()
{
DBUG_ASSERT(fixed == TRUE);
for (uint i= 0; i < arg_count; i++)
{
if (args[i]->type() == Item::FIELD_ITEM &&
(args[i]->field_type() == MYSQL_TYPE_TIME ||
args[i]->field_type() == MYSQL_TYPE_DATETIME))
return TRUE;
}
return FALSE;
}
bool has_datetime_args()
{
DBUG_ASSERT(fixed == TRUE);
for (uint i= 0; i < arg_count; i++)
{
if (args[i]->type() == Item::FIELD_ITEM &&
args[i]->field_type() == MYSQL_TYPE_DATETIME)
return TRUE;
}
return FALSE;
}
/* /*
We assume the result of any function that has a TIMESTAMP argument to be We assume the result of any function that has a TIMESTAMP argument to be
timezone-dependent, since a TIMESTAMP value in both numeric and string timezone-dependent, since a TIMESTAMP value in both numeric and string
...@@ -208,7 +248,7 @@ public: ...@@ -208,7 +248,7 @@ public:
representation of a TIMESTAMP argument verbatim, and thus does not depend on representation of a TIMESTAMP argument verbatim, and thus does not depend on
the timezone. the timezone.
*/ */
virtual bool is_timezone_dependent_processor(uchar *bool_arg) virtual bool is_arguments_valid_processor(uchar *bool_arg)
{ {
return has_timestamp_args(); return has_timestamp_args();
} }
......
...@@ -70,6 +70,10 @@ public: ...@@ -70,6 +70,10 @@ public:
enum_monotonicity_info get_monotonicity_info() const; enum_monotonicity_info get_monotonicity_info() const;
longlong val_int_endpoint(bool left_endp, bool *incl_endp); longlong val_int_endpoint(bool left_endp, bool *incl_endp);
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -86,6 +90,10 @@ public: ...@@ -86,6 +90,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -111,6 +119,10 @@ public: ...@@ -111,6 +119,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -140,6 +152,10 @@ public: ...@@ -140,6 +152,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -156,6 +172,10 @@ public: ...@@ -156,6 +172,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_time_args();
}
}; };
...@@ -172,6 +192,10 @@ public: ...@@ -172,6 +192,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_time_args();
}
}; };
...@@ -188,6 +212,10 @@ public: ...@@ -188,6 +212,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -204,6 +232,10 @@ public: ...@@ -204,6 +232,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_time_args();
}
}; };
...@@ -234,6 +266,10 @@ public: ...@@ -234,6 +266,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -252,6 +288,10 @@ public: ...@@ -252,6 +288,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
...@@ -282,6 +322,10 @@ public: ...@@ -282,6 +322,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_date_args();
}
}; };
class Item_func_dayname :public Item_func_weekday class Item_func_dayname :public Item_func_weekday
...@@ -311,7 +355,7 @@ public: ...@@ -311,7 +355,7 @@ public:
(and thus may not be used as a partitioning function) (and thus may not be used as a partitioning function)
when its argument is NOT of the TIMESTAMP type. when its argument is NOT of the TIMESTAMP type.
*/ */
bool is_timezone_dependent_processor(uchar *int_arg) bool is_arguments_valid_processor(uchar *int_arg)
{ {
return !has_timestamp_args(); return !has_timestamp_args();
} }
...@@ -336,6 +380,10 @@ public: ...@@ -336,6 +380,10 @@ public:
max_length=10*MY_CHARSET_BIN_MB_MAXLEN; max_length=10*MY_CHARSET_BIN_MB_MAXLEN;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_time_args();
}
}; };
...@@ -589,6 +637,10 @@ public: ...@@ -589,6 +637,10 @@ public:
const char *func_name() const { return "from_days"; } const char *func_name() const { return "from_days"; }
bool get_date(MYSQL_TIME *res, uint fuzzy_date); bool get_date(MYSQL_TIME *res, uint fuzzy_date);
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return has_date_args() || has_time_args();
}
}; };
...@@ -715,6 +767,42 @@ class Item_extract :public Item_int_func ...@@ -715,6 +767,42 @@ class Item_extract :public Item_int_func
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
virtual void print(String *str, enum_query_type query_type); virtual void print(String *str, enum_query_type query_type);
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
switch (int_type) {
case INTERVAL_YEAR:
case INTERVAL_YEAR_MONTH:
case INTERVAL_QUARTER:
case INTERVAL_MONTH:
/* case INTERVAL_WEEK: Not allowed as partitioning function, bug#57071 */
case INTERVAL_DAY:
return !has_date_args();
case INTERVAL_DAY_HOUR:
case INTERVAL_DAY_MINUTE:
case INTERVAL_DAY_SECOND:
case INTERVAL_DAY_MICROSECOND:
return !has_datetime_args();
case INTERVAL_HOUR:
case INTERVAL_HOUR_MINUTE:
case INTERVAL_HOUR_SECOND:
case INTERVAL_MINUTE:
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
case INTERVAL_MICROSECOND:
case INTERVAL_HOUR_MICROSECOND:
case INTERVAL_MINUTE_MICROSECOND:
case INTERVAL_SECOND_MICROSECOND:
return !has_time_args();
default:
/*
INTERVAL_LAST is only an end marker,
INTERVAL_WEEK depends on default_week_format which is a session
variable and cannot be used for partitioning. See bug#57071.
*/
break;
}
return true;
}
}; };
...@@ -965,6 +1053,10 @@ public: ...@@ -965,6 +1053,10 @@ public:
maybe_null=1; maybe_null=1;
} }
bool check_partition_func_processor(uchar *int_arg) {return FALSE;} bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
bool is_arguments_valid_processor(uchar *int_arg)
{
return !has_time_args();
}
}; };
......
...@@ -1019,7 +1019,7 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table, ...@@ -1019,7 +1019,7 @@ static bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
opening existing tables for easier maintenance. This exception should be opening existing tables for easier maintenance. This exception should be
deprecated at some point in future so that we always throw an error. deprecated at some point in future so that we always throw an error.
*/ */
if (func_expr->walk(&Item::is_timezone_dependent_processor, if (func_expr->walk(&Item::is_arguments_valid_processor,
0, NULL)) 0, NULL))
{ {
if (is_create_table_ind) if (is_create_table_ind)
......
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