cwida / duckpgq-extension

DuckDB extension that adds support for SQL/PGQ
https://duckpgq.notion.site/b8ac652667964f958bfada1c3e53f1bb?v=3b47a8d44bdf4e0c8b503bf23f1b76f2
MIT License
72 stars 7 forks source link

Duplicate table index "1" in debug mode #109

Closed Dtenwolde closed 7 months ago

Dtenwolde commented 7 months ago

When run in debug mode, during the verification stage (after optimization) there is an error in the following query:

CREATE TABLE Student(id BIGINT, name VARCHAR);INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Peter'), (4, 'David');
CREATE TABLE know(src BIGINT, dst BIGINT, createDate BIGINT);INSERT INTO know VALUES (0,1, 10), (0,2, 11), (0,3, 12), (3,0, 13), (1,2, 14), (1,3, 15), (2,3, 16), (4,3, 17), (4, 0, 18);

-SELECT person, friend
FROM GRAPH_TABLE (pg
    MATCH
    (a:Student)-[k:know]-(b:Student)
    WHERE a.name = 'Daniel'
    COLUMNS (a.name as person, b.name as friend)
    )
ORDER BY person, friend;
----
INTERNAL Error: Duplicate table index "1" found

The problem does not occur in release mode and gets the correct results. A plain SQL equivalent is:

SELECT a.name AS person, b.name AS friend
    FROM ((SELECT know.src, know.dst FROM know) UNION ALL (SELECT know.dst, know.src FROM know)) AS k , Student AS b , Student AS a
    WHERE ((a.id = k.src) AND (b.id = k.dst) AND (a.name = 'Daniel'));

It does not occur here because we register a table function for the PGQ query, which bumps the number of bound tables up by one. However, one of the projections that is part of the UNION ALL gets a duplicate table index. In Binder::Binder:52, a new Binder is created with 0 bound tables. It may be that the union does not get the proper number of bound tables and sets the number of bound tables to 0, while it should be 1 (the table function).