Add vertex and edge composite types with direct field access optimization#209
Closed
MuhammadTahaNaveed wants to merge 1 commit into
Closed
Add vertex and edge composite types with direct field access optimization#209MuhammadTahaNaveed wants to merge 1 commit into
MuhammadTahaNaveed wants to merge 1 commit into
Conversation
MuhammadTahaNaveed
commented
Jan 10, 2026
Owner
- Introduce vertex and edge as pg composite types vertex: (id, label, properties) edge: (id, label, start_id, end_id, properties)
- Property access (a.name) now directly uses a.properties for agtype_access_operator instead of rebuilding via _agtype_build_vertex/edge
- Optimize accessor functions (id, properties, label, type, start_id, end_id) to use direct FieldSelect on composite types instead of agtype functions
- Add casts: vertex/edge to agtype, vertex/edge to json
- Fix label_name specific routine to use cache instead of ag_label scan
- Write/update clauses have executors strictly tied to agtype, due to which the variables after any write/update clause are carried forward as agtype.
- Allows users to completely skip agtype build functions and return vertex/edge for pure read queries.
- Change _label_name to return agtype since record comparisons are not allowed with cstring. Consequently, _agtype_build_vertex/edge now accept agtype as label.
- Fix MERGE clause type mismatch when accessing properties from previous MATCH clauses by wrapping columns with agtype_volatile_wrapper before namespace lookup
- Add regression tests
There was a problem hiding this comment.
Pull request overview
This PR introduces significant performance optimizations by adding composite types (vertex and edge) alongside the existing agtype representation. The changes enable direct field access without rebuilding agtype objects for read-only queries.
Changes:
- Introduces composite types
vertex(id, label, properties)andedge(id, label, start_id, end_id, properties)with implicit casts to agtype - Optimizes accessor functions (id, properties, label, type, start_id, end_id) to use FieldSelect for direct field extraction from composite types
- Updates _agtype_build_vertex/edge to accept agtype labels instead of cstring, and modifies executors to convert labels accordingly
- Adds comprehensive regression tests for accessor optimizations and composite type returns
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/include/utils/agtype.h | Adds Oid accessors for VERTEXOID and EDGEOID composite types |
| src/include/parser/cypher_expr.h | Declares helper functions for entity detection and field extraction |
| src/include/parser/cypher_clause.h | Adds declarations for record field info helpers |
| src/include/catalog/ag_label.h | Adds get_label_name function declaration |
| src/backend/utils/adt/agtype.c | Implements vertex/edge composite type support, conversion functions, and updates build functions to accept agtype labels |
| src/backend/parser/cypher_expr.c | Implements accessor function optimization and entity coercion logic |
| src/backend/parser/cypher_clause.c | Updates entity creation to use RowExpr with composite types and adds entity coercion for write clauses |
| src/backend/executor/cypher_set.c | Updates to use string_to_agtype for label parameters |
| src/backend/executor/cypher_merge.c | Updates to use string_to_agtype for label parameters |
| src/backend/executor/cypher_create.c | Updates to use string_to_agtype for label parameters |
| src/backend/catalog/ag_label.c | Changes _label_name to return agtype and adds cached label lookup |
| sql/agtype_graphid.sql | Defines composite types, cast functions, and updates function signatures |
| sql/age_scalar.sql | Adds _get_vertex_by_graphid helper function |
| sql/age_main.sql | Removes old _label_name function definition |
| regress/sql/expr.sql | Adds comprehensive tests for accessor optimizations and composite types |
| regress/sql/cypher_with.sql | Adds tests for accessor optimizations in WITH clauses |
| regress/sql/agtype.sql | Updates tests to use agtype labels instead of cstring |
| regress/expected/*.out | Updated expected test outputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* | ||
| * Wrap vertex/edge columns in the left subquery with volatile wrapper | ||
| * before adding to namespace and building property expressions since | ||
| * our executors are stictly tied to agtype. |
There was a problem hiding this comment.
The comment contains a typo: "stictly" should be "strictly".
Suggested change
| * our executors are stictly tied to agtype. | |
| * our executors are strictly tied to agtype. |
…tion - Introduce vertex and edge as pg composite types vertex: (id, label, properties) edge: (id, label, start_id, end_id, properties) - Property access (a.name) now directly uses a.properties for agtype_access_operator instead of rebuilding via _agtype_build_vertex/edge - Optimize accessor functions (id, properties, label, type, start_id, end_id) to use direct FieldSelect on composite types instead of agtype functions - Add casts: vertex/edge to agtype, vertex/edge to json - Fix label_name specific routine to use cache instead of ag_label scan - Write/update clauses have executors strictly tied to agtype, due to which the variables after any write/update clause are carried forward as agtype. - Allows users to completely skip agtype build functions and return vertex/edge for pure read queries. - Change _label_name to return agtype since record comparisons are not allowed with cstring. Consequently, _agtype_build_vertex/edge now accept agtype as label. - Fix MERGE clause type mismatch when accessing properties from previous MATCH clauses by wrapping columns with agtype_volatile_wrapper before namespace lookup. - Update expression index in pgvector.sql, since now it uses raw properties column instead of _agtype_build_vertex/edge. - Add regression tests
db5e7f3 to
e6aae14
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.