tidb-challenge-program / bug-hunting-issue

Bug hunting issues.
3 stars 0 forks source link

P2-[4.0 bug hunting]-[SQL Plan Management]-Inserting into a partitioned table results in an "Missing session variable when eval builtin" error #18

Open mrigger opened 4 years ago

mrigger commented 4 years ago

Consider the following statements:

CREATE TABLE t0(c0 INT) PARTITION BY HASH((c0<CURRENT_USER())) PARTITIONS 1;
INSERT INTO t0 VALUES (0); -- Missing session variable when eval builtin

Unexpectedly, the INSERT results in an error:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.25-TiDB- TiDB Server (Apache License 2.0), MySQL 5.7 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE TABLE t0(c0 INT) PARTITION BY HASH((c0<CURRENT_USER())) PARTITIONS 1;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t0 VALUES (0); -- Missing session variable when eval builtin
ERROR 1105 (HY000): Missing session variable when eval builtin

MySQL 8.0.19 seems to prohibit the creation of such a table:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE TABLE t0(c0 INT) PARTITION BY HASH((c0<CURRENT_USER())) PARTITIONS 1;
ERROR 1064 (42000): Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed near '(c0<CURRENT_USER())) PARTITIONS 1' at line 1

I can reproduce this both on a recent master commit (72f457674238d28435b874af2899f7f684140a49) and the 4.0 RC.

Environment:

+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: 
Git Commit Hash: 
Git Branch: 
UTC Build Time: 2020-04-15 06:06:10
GoVersion: go1.13.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
shuke987 commented 4 years ago

/bug P2

wwar commented 4 years ago

MySQL also prohibits this expression, potentially because it depends on an sql mode:

mysql> CREATE TABLE t1 (
    ->  id INT NOT NULL auto_increment,
    ->  bool TINYINT NOT NULL,
    ->  PRIMARY KEY (id, bool)
    -> )
    -> PARTITION BY HASH ((NOT bool BETWEEN -5 AND 5)) PARTITIONS 2;
ERROR 1564 (HY000): This partition function is not allowed