citusdata / citusdata/citus

NewTableId() function cannot find correct range table id

Open
#1,071 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

Hit this problem when implementing view support (#442).

Problem is that, NewTableId() function is almost always called when rangeTableId's in ```originalTableIdList``` is 1. However, when views are enabled, range table is is greater than 1. The first call to NewTableId() function correctly finds originaltableid in the first rangeTableEntry, and the caller updates varno of target entry to 1. The same function is called later from ``` MergeTaskList()->IntermediateTableQueryString()```. This time varno is 1, and cannot be found in original range table list since it still contains old value (3 in this case).

The problem is only visible for queries on single table views since we reject subqueries in multi relation queries. Also subquery pushdown does not have the problem.

## Repro case
```sql
CREATE VIEW lineitems_by_orderkey AS
SELECT l_orderkey, count(*) FROM lineitem GROUP BY 1;
SELECT * FROM lineitems_by_orderkey;
ERROR: Unrecognized range table id 1
```
## Expected
Query to complete since it is equivalent to

```sql
SELECT * FROM (SELECT l_orderkey, count(*) FROM lineitem_hash GROUP BY 1) a;
```
which is supported under task-tracker mode.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.