You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize id()/start_id()/end_id() with direct column access
NOTE: This PR was created with AI tools and a human
Add optimization to avoid rebuilding full vertex/edge objects when only
the id, start_id, or end_id is needed. Instead of calling age_id() on
a reconstructed _agtype_build_vertex/_agtype_build_edge, directly access
the underlying graphid column and wrap it with graphid_to_agtype().
Implementation:
- Export hidden columns (_age_default_varname_id_*, _age_default_varname_
start_id_*, _age_default_varname_end_id_*) when entities pass between
clauses via export_entity_hidden_columns()
- Store Var references (id_var, start_id_var, end_id_var) in transform_entity
- try_optimize_id_funcs() checks for these optimizable patterns:
- Cross-clause: Use stored Var from previous clause export
- Current-clause: Extract graphid Var from entity's build expression
- Validate Var references to prevent stale references after WITH clauses
Optimized patterns:
MATCH (p) RETURN id(p) -- cross-clause in RETURN
MATCH (p) WHERE id(p) > 0 RETURN p -- current-clause in WHERE
MATCH (p) MATCH (q) WHERE id(p) > 0 -- cross-clause in WHERE
Query plan improvement:
Before: Filter: age_id(_agtype_build_vertex(p.id, _label_name(...), p.properties))
After: Filter: graphid_to_agtype(p.id)
All original regression tests passed.
Added additional regression tests.
Files changed:
- src/include/parser/cypher_transform_entity.h: Add id_var, start_id_var,
end_id_var, props_var fields to transform_entity struct
- src/backend/parser/cypher_clause.c: Add export_entity_hidden_columns()
and integrate with handle_prev_clause()
- src/backend/parser/cypher_expr.c: Add try_optimize_id_funcs(),
extract_id_var_from_entity_expr(), find_entity_in_current_cpstate()
- regress/sql/cypher_match.sql: Add 13 WHERE optimization tests
- regress/sql/expr.sql: Add cross-clause optimization tests
- regress/expected/*.out: Update expected output
modified: regress/expected/cypher_match.out
modified: regress/expected/cypher_with.out
modified: regress/sql/cypher_match.sql
modified: regress/sql/cypher_with.sql
modified: src/backend/parser/cypher_clause.c
modified: src/backend/parser/cypher_expr.c
modified: src/backend/parser/cypher_transform_entity.c
modified: src/include/parser/cypher_transform_entity.h
0 commit comments