Skip to content

Conversation

@nicolas-geysse
Copy link

Summary

  • Fixes crash when using GRAPH_TABLE inside CTEs or with UNION operations
  • Adds recursive query node traversal for SetOperationNode
  • Adds regression tests for CTE and UNION scenarios

Problem

The parser extension's duckpgq_find_select_statement() was not handling SetOperationNode (UNION/UNION ALL/EXCEPT/INTERSECT), causing segfaults when GRAPH_TABLE was used in these contexts:

-- Crash with CTE containing GRAPH_TABLE
WITH mfp AS (
  FROM GRAPH_TABLE (snb MATCH (a:Person)-[k:knows]->(b:Person) COLUMNS (...))
  SELECT ...
)
FROM mfp, GRAPH_TABLE (snb MATCH ...) mem
SELECT ...

-- Crash with UNION
SELECT ... FROM GRAPH_TABLE(...)
UNION ALL
SELECT ... FROM GRAPH_TABLE(...)

Error: INTERNAL Error: Attempted to dereference unique_ptr that is NULL!

Solution

Added a recursive duckpgq_traverse_query_node() function that properly handles all QueryNode types:

  • SelectNode: traverse from_table and CTEs
  • CTENode: recurse into child node
  • SetOperationNode: recurse into all children (for UNION/EXCEPT/INTERSECT)

Test plan

  • New test file test/sql/cte_union_match.test with 5 test cases
  • All 126 existing tests pass
  • Tests cover: single CTE, multiple CTEs, UNION ALL, CTE + main GRAPH_TABLE, UNION with different patterns

Fixes #276

🤖 Generated with Claude Code

)

The parser extension's `duckpgq_find_select_statement()` was not handling
`SetOperationNode` (UNION/UNION ALL/EXCEPT/INTERSECT), causing crashes when
GRAPH_TABLE was used inside CTEs or with set operations.

## Changes
- Add recursive `duckpgq_traverse_query_node()` function that properly handles:
  - `SelectNode`: traverse from_table and CTEs
  - `CTENode`: recurse into child node
  - `SetOperationNode`: recurse into all children
- Simplify `duckpgq_find_select_statement()` to use the new traversal
- Add `std::move()` to return statements in summarize_property_graph.cpp
- Add regression tests for CTE and UNION scenarios

## Test cases added
- GRAPH_TABLE in CTE
- Multiple CTEs with GRAPH_TABLE
- UNION ALL with GRAPH_TABLE
- CTE with GRAPH_TABLE + main query GRAPH_TABLE
- UNION with different GRAPH_TABLE patterns

Fixes cwida#276

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segmentation fault with MATCH inside CTEs

1 participant