cwida / duckpgq-extension

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

Reduce the number of pairs to compute path length for #23

Closed Dtenwolde closed 2 months ago

Dtenwolde commented 1 year ago

The query for path-finding should be something like:

WITH cte1 AS (
    SELECT  CREATE_CSR_EDGE(
            0,
            (SELECT count(a.id) FROM person a),
            CAST (
                (SELECT sum(CREATE_CSR_VERTEX(
                            0,
                            (SELECT count(a.id) FROM person a),
                            sub.dense_id,
                            sub.cnt)
                            )
                FROM (
                    SELECT a.rowid as dense_id, count(k.person1id) as cnt
                    FROM person a
                    LEFT JOIN person_knows_person k ON k.person1id = a.id
                    GROUP BY a.rowid) sub
                )
            AS BIGINT),
            a.rowid,
            c.rowid,
            k.rowid) as temp
    FROM person_knows_person k
    JOIN person a on a.id = k.person1id
    JOIN person c on c.id = k.person2id
)
SELECT distinct a.name AS a_name, b.name AS b_name,
FROM (SELECT count(temp) * 0 AS temp FROM cte1) x, (SELECT a.id, a.rowid FROM person a WHERE a.id = 332) a, person b
    where (x.temp + iterativelength(0, (SELECT count(c.id) FROM person c), a.rowid, b.rowid)) NOT NULL
Dtenwolde commented 1 year ago

Reworked in cwida/duckdb-pgq#43 and has been merged. Leaving this open as it might be an interesting optimizer problem that should perform the filter earlier

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.