WL#13559: Deprecate syntax: confusing combinations of UNION and INTO

Affects: Server-8.0   —   Status: Complete

All examples below are syntactically correct and do the same:

1. `... UNION SELECT * FROM t INTO OUTFILE 'foo'`

2. `... UNION (SELECT * FROM t) INTO OUTFILE 'foo'`

3. `... UNION SELECT * INTO OUTFILE 'foo' FROM t`

4. `... UNION (SELECT * FROM t INTO OUTFILE 'foo')` (rejected as a syntax error since WL#8083)

5. `... UNION (SELECT * INTO OUTFILE 'foo' FROM t)`

OTOH variants #3 and #5 look very confusing like if they collect the output from table `t` only, not from the whole query expression (UNION).

It would be good to deprecate variants #3 and #5 to reject them in the future.

F-1. Using `INTO` before `FROM` in the trailing query block of a query expression shall produce a deprecation warning.

Example:

   ... UNION SELECT * INTO OUTFILE 'foo.txt' FROM t;
   

F-2. Using `INTO` in a parenthesized trailing block of a query expression, despite of its position against `FROM`, shall produce a deprecation warning.

Examples:

   ... UNION (SELECT * INTO OUTFILE 'foo.txt' FROM t);
   ... UNION (SELECT * FROM t INTO OUTFILE 'foo.txt'); (syntax error in 8.0)
   

F-3. Using a trailing locking clause after `INTO` in a query expression shall produce a deprecation warning:

Examples:

   ... UNION SELECT * FROM t1 INTO OUTFILE 'foo.txt' FOR UPDATE;
   

F-4. The WL should not affect query expressions with a single query block (non-unions) where `INTO` goes before `FROM`. Queries like these should be accepted without new deprecation warnings:

Examples:

   SELECT 1 INTO @var FROM t LIMIT 1;
   (SELECT * FROM t INTO OUTFILE 'foo.txt') LIMIT 10; (syntax error in 8.0)
   (SELECT * INTO OUTFILE 'foo.txt' FROM t) LIMIT 10;
   ((SELECT * INTO DUMPFILE 'foo.txt' FROM t));

F-5: Using `INTO` after `FROM` in non-union queries should produce a deprecation warning.

Sample query:

  SELECT * FROM t INTO OUTFILE 'foo.txt' FOR UPDATE;