Bug #77917 partitioning syntax lead to unexpected errno 1064
Submitted: 3 Aug 2015 10:21 Modified: 24 Aug 2015 10:07
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S4 (Feature request)
Version:8.0.0 OS:Any
Assigned to: CPU Architecture:Any

[3 Aug 2015 10:21] Shane Bester
Description:
Affects 5.1, 5.5, 5.6, 5.7, 5.8

Consider this example:

mysql> create table t(a timestamp)engine=innodb;
Query OK, 0 rows affected (0.02 sec)

mysql> alter table t partition by range((a=@a))(partition a values less than(1));
ERROR 1064 (42000): Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near ')(partition a values less than(1))' at line 1
mysql>

I expected errno of 1486 (ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR) and not 1064.

More examples:
E:\git\mysql-trunk\sql>grep -n my_syntax_error sql_yacc.yy|grep -i part

5147:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_ENTRY_ERROR));
5202:    my_syntax_error(ER_THD(YYTHD, ER_SYNTAX_ERROR));
5343:    my_syntax_error(ER_THD(YYTHD, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR));
5392:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_WRONG_NO_PART_ERROR));
5510:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_COLUMN_LIST_ERROR));
5541:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_COLUMN_LIST_ERROR));
5562:    my_syntax_error(ER_THD(YYTHD, ER_ROW_SINGLE_PARTITION_FIELD_ERROR));
5603:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_COLUMN_LIST_ERROR));
5621:    my_syntax_error(ER_THD(YYTHD, ER_MAXVALUE_IN_VALUES_IN));
5639:    my_syntax_error(ER_THD(YYTHD, ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR));
5661:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_WRONG_NO_SUBPART_ERROR));
5673:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_WRONG_NO_SUBPART_ERROR));
5681:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_WRONG_NO_SUBPART_ERROR));
5715:    my_syntax_error(ER_THD(YYTHD, ER_PARTITION_WRONG_NO_SUBPART_ERROR));

I check 1064 to detect real syntax errors in my grammar,  but otherwise valid partitioning clauses (that are wrong logically) are spoiling the 1064 counter.

How to repeat:
drop table if exists t;
create table t(a timestamp)engine=innodb;
alter table t partition by range((a=@a))(partition a values less than(1));

Suggested fix:
return the actual error code instead of lumping it together with 1064.
[3 Aug 2015 10:21] MySQL Verification Team
not sure if a bug, fr, or discussion....
[24 Aug 2015 10:07] MySQL Verification Team
Hello Shane,

Thank you for the report.

Thanks,
Umesh
[18 Jun 2016 21:27] Omer Barnir
Posted by developer:
 
Reported version value updated to reflect release name change from 5.8 to 8.0
[17 Apr 2017 3:22] MySQL Verification Team
As a workaround I will compare the string value of the mysql_error() to make sure it is a real syntax error and not a partitioning error.   

Random tests might also SIGNAL to raise errors, so i'm already needing to do this for error 2006,2013,2055 to prevent a false alarm for server crash.