`reduce()`/list comprehension in a `LIMIT` or `SKIP` clause raises internal error `unsupported SubLink` (0A000)
- Dominant language
- C
- Stars
- 4.8k
- Forks
- 523
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 9
Description
## Bug description
Putting a `reduce()` expression — or a list comprehension — inside a `LIMIT` or `SKIP` clause makes AGE 1.8.0 fail with the internal error `ERROR: 0A000: unsupported SubLink`. The query has no subquery and no outer variable; the trigger is the `reduce`'s own list iteration variable (`b IN [0]`).
## Access method
- Command line via `psql`, inside the official Docker container `apache/age:1.8.0`
## Data setup
No data is required — the error reproduces on an empty graph. Only the graph itself must exist:
```pgsql
CREATE EXTENSION IF NOT EXISTS age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
SELECT create_graph('graph_test');
```
## Configuration
- None beyond the stock AGE extension. No additional modules (no PostGIS, etc.), default `search_path` handling as shown above.
## Command that triggers the error
```pgsql
SELECT * FROM cypher('graph_test', $$ RETURN 1 LIMIT reduce(a = 1, b IN [0] | a + b) $$) AS (c0 agtype);
```
```
ERROR: unsupported SubLink
```
(SQLSTATE `0A000`, internal error.) Run the statement on its own (e.g. `psql -c "..."`): when several statements are piped to `psql` at once, stdout/stderr buffering can push the `ERROR` line to a different position in the output and make it look like the query succeeded.
The failure is specific to `LIMIT`/`SKIP`: the same `reduce` returns a row without one, and `LIMIT` accepts other data-free expressions:
```pgsql
-- works: reduce without LIMIT
SELECT * FROM cypher('graph_test', $$ RETURN reduce(a = 1, b IN [0] | a + b) $$) AS (c0 agtype);
-- works: arithmetic / function in LIMIT
SELECT * FROM cypher('graph_test', $$ RETURN 1 LIMIT 1 + 1 $$) AS (c0 agtype);
SELECT * FROM cypher('graph_test', $$ RETURN 1 LIMIT size([0, 0]) $$) AS (c0 agtype);
```
## Environment
- Version: 1.8.0 (official `apache/age:1.8.0` Docker image)
- PostgreSQL: 18.1 (Debian 18.1-1.pgdg13+2), x86_64
Contributor guide
Research direction
Start by reproducing the query in psql using the official apache/age:1.8.0 Docker image and the graph_test setup shown in the report. Trace how LIMIT and SKIP handle reduce() and list comprehensions, then verify that the reproducer no longer raises unsupported SubLink while the working LIMIT examples remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, postgresql, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100