jrgemignani opened a new pull request, #2295:
URL: https://github.com/apache/age/pull/2295

   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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to