[MDEV-17406] Problems with LIKE using a parenthesized expression in the pattern Created: 2018-10-09  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.2, 10.3
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-17408 VIEW is incorrectly defined for a com... Closed
relates to MDEV-23656 view: removal of parentheses results ... Closed
relates to MDEV-17359 || operator is not understand by "lik... Closed

 Description   

The problem is repeatable with virtual columns

I create some arbitrary table:

CREATE OR REPLACE TABLE t1 (a int);
SHOW TABLES LIKE 't1';

+---------------------+
| Tables_in_test (t1) |
+---------------------+
| t1                  |
+---------------------+

Now I overwrite the structure of t1, using a virtual column with LIKE (expr):

CREATE OR REPLACE TABLE t1 (a VARCHAR(100), b INT AS (a LIKE (10+1)));
SHOW TABLES LIKE 't1';

It returns the following output:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+ 1' at line 1
MariaDB [test]> SHOW TABLES LIKE 't1';
Empty set (0.00 sec)

Notice, some error happened in CREATE. But the table t1 is gone!

This is wrong. In case if there is something wrong with the table definition, the old table should not be dropped.

The problem is repeatable with VIEWs

CREATE OR REPLACE VIEW v1 AS SELECT 3 LIKE (1+3) AS c;

Query OK, 0 rows affected (0.01 sec)

SHOW CREATE VIEW v1;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '+ 3 AS `c`' at line 1

The reason of the problem

The problem happens because:

a LIKE (10+1)

is internally translated to:

a LIKE 10+1

without parentheses, which further cannot be understood by the parser.



 Comments   
Comment by Sergei Golubchik [ 2018-10-09 ]

MariaDB [test]> CREATE OR REPLACE VIEW v1 AS SELECT (1 LIKE 2) BETWEEN 1 AND 2 AS c;
Query OK, 0 rows affected (0.002 sec)
 
MariaDB [test]> show create view v1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'between 1 and 2 AS `c`' at line 1

Generated at Thu Feb 08 08:36:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.