Analytic functions in combination with other expressions which may be optimized out can crash
Details
| Detail name | Value |
|---|---|
| Changelog Number | 32545 |
| Type | Bug |
| Status | Resolved |
| Affected Versions | Exasol 8.19.0, Exasol 8.29.0, Exasol 2025.1.0, Exasol 2025.2.0, Exasol 2026.1.0 |
| Fix Versions | Exasol 2025.1.17 |
| Resolution Date | 2026-11-12 |
Description
An 'Internal server error' may be thrown when the following conditions are met:
- There is an expression combining analytic functions with other expressions.
- In this expression there is a lookup to a subselect with a join.
- There are expressions which might be optimized out, such as: duplicate predicates (x = 1 and x = 1), true in OR predicate (x = 1 or TRUE), false in AND predicate (x = 1 and FALSE), equal predicate of the same values (x = x), etc.
Example
create table t1(x int, id int);
create table t2(y int, id int);
-- Expected: 0 rows
-- Observed: Successfully reconnected after internal server error, transaction was rolled back.
SELECT
cond
FROM (
SELECT
CASE
WHEN SUM(1) OVER () >= 1
AND x = 1
AND x = 1
THEN 1
ELSE 0
END AS cond
FROM (
SELECT
t1.x AS x
FROM t1
INNER JOIN t2
ON t1.id = t2.id
ORDER BY false
)
);
Workaround
There are several possible workarounds:
- Remove redundant predicate manually (remove one of x = 1 expressions in the example above).
- Move analytic function to a separate expression. One of the ways to do it is to move it to a different subselect. For an example above:
SELECT
cond
FROM (
SELECT
CASE
WHEN analytic_function_result
AND x = 1
AND x = 1
THEN 1
ELSE 0
END AS cond
FROM (
SELECT
SUM(1) OVER () >= 1 as analytic_function_result,
x
FROM (
SELECT
t1.x AS x
FROM t1
INNER JOIN t2
ON t1.id = t2.id
ORDER BY false
)
)
);
Fix
Query runs as expected.