• Alexander Barkov's avatar
    MDEV-14347 CREATE PROCEDURE returns no error when using an unknown variable · 6e2d967b
    Alexander Barkov authored
    CREATE PROCEDURE did not detect unknown SP variables in assignments like this:
    
      SET var=a_long_var_name_with_a_typo;
    
    The error happened only during the SP execution time, and only of the control
    flow reaches the erroneous statement.
    
    Fixing most expressions to detect unknown identifiers.
    This includes simple subqueries without tables:
    
    - Query specification: SELECT list, WHERE,
      HAVING (inside aggregate functions) clauses, e.g.
        SET var= (SELECT unknown_ident+1);
        SET var= (SELECT 1 WHERE unknown_identifier);
        SET var= (SELECT 1 HAVING SUM(unknown_identifier);
    
    - Table value constructor: VALUES clause, e.g.:
        SET var= (VALUES(unknown_ident));
    
    Note, in some more complex subquery cases unknown variables are still not detected
    (this will be fixed separately):
    
    - Derived tables:
      SET a=(SELECT unknown_ident FROM (SELECT 1 AS alias) t1);
      SET res=(SELECT * FROM t1 LEFT OUTER JOIN (SELECT unknown_ident) t2 USING (c1));
    
    - CTE:
      SET a=(WITH cte1 (a) AS (SELECT unknown_ident) SELECT * FROM cte1);
      SET a=(WITH cte1 (a,b) AS (VALUES (unknown,2),(3,4)) SELECT * FROM cte1);
      SET a=(WITH cte1 (a,b) AS (VALUES (1,2),(3,4)) SELECT unknown_ident FROM cte1);
    
    - SELECT .. GROUP BY unknown_identifier
    - SELECT .. ORDER BY unknown_identifier
    - HAVING with an unknown identifier outside of any aggregate functions:
      SELECT .. HAVING unknown_identifier;
    6e2d967b
item_subselect.h 51.2 KB