Fix crash pushing groups into UNION ALL operands projecting different datatypes

Details

Detail name Value
Changelog number 31244
Type Bug
Status Open
Affected versions Exasol 2026.1.0
Fix versions Pending

Description

If a query has the following conditions and the Compiler pushes the GROUP BY through the UNION ALL, then the Engine can crash.

  1. The query has a UNION ALL.
  2. The subselect containing the UNION ALL has a GROUP BY clause.
  3. The conditions for pushing GROUP BY through UNION ALL apply.
  4. The UNION ALL projects a column which has a different datatype projected from different table operands. Note that this can be the same datatype name with different type parameters (e.g. both DECIMAL but with different precisions).
  5. After optimization, the table operands calculate complex expressions for this column.

Example

-- Setup
CREATE TABLE a (a1 INT, a2 INT);
INSERT INTO a VALUES (1, 1),
                     (2, 2.345);

CREATE TABLE b (b1 DECIMAL(9,0));
INSERT INTO b VALUES (1);
CREATE TABLE b_ (b1 DECIMAL(18,0));
INSERT INTO b_ VALUES (2);

-- Expected: 3 rows, values (1, 100), (0, 50), (2, 50)
-- Observed: Internal server error
SELECT a1, 100 / a2
FROM (SELECT a1, a2 FROM a
      UNION ALL
      SELECT 0, CAST(2 AS INT))
GROUP BY 1, 2;

-- Expected: 3 rows, values (3), (4)
-- Observed: Internal server error
SELECT x+1
FROM (SELECT b1+1 X FROM b
      UNION ALL
      SELECT b1+1 FROM b_)
GROUP BY 1;

Workaround

  1. Use ORDER BY FALSE in the subquery with the UNION ALL:
  2. Use explicit casts:
  3. Disable the optimization that pushes GROUP BY into unions. Please contact support for details.
SELECT a1, 100 / a2
FROM (SELECT a1, a2 FROM a
      UNION ALL
      SELECT 0, CAST(2 AS INT)
      ORDER BY FALSE)
GROUP BY 1, 2;
SELECT x+1
FROM (SELECT CAST(b1+1 AS DECIMAL(18,0)) X FROM b
      UNION ALL
      SELECT CAST(b1+1 AS DECIMAL(18,0)) FROM b_)
GROUP BY 1;

Fix

The query behaves as expected.