Skip to content

Conversation

@MuhammadTahaNaveed
Copy link
Member

  • 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

Assisted-by AI

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces vertex and edge as PostgreSQL composite types to optimize graph query performance. The changes enable direct field access for properties and accessor functions instead of rebuilding agtype structures.

Changes:

  • Introduces vertex (id, label, properties) and edge (id, label, start_id, end_id, properties) composite types
  • Optimizes property access to use direct field selection instead of agtype rebuild
  • Changes _label_name to return agtype instead of cstring for type consistency
  • Adds implicit casts from vertex/edge to agtype and json
  • Fixes MERGE clause type mismatches with volatile wrapper

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/include/utils/agtype.h Added OID accessors for VERTEXOID and EDGEOID composite types
src/include/parser/cypher_expr.h Added helper functions for entity type checking and field extraction
src/include/parser/cypher_clause.h Added field access helper functions for composite types
src/include/catalog/ag_label.h Added get_label_name function signature
src/backend/utils/adt/agtype.c Implemented composite type OID caching, vertex/edge to agtype casts, label parameter type change
src/backend/parser/cypher_expr.c Implemented accessor function optimization and entity type coercion
src/backend/parser/cypher_clause.c Updated entity expression builders to use RowExpr, added field selection helpers
src/backend/executor/*.c Updated executors to use agtype labels instead of cstrings
src/backend/catalog/ag_label.c Changed _label_name to return agtype, added cache-based get_label_name
sql/agtype_graphid.sql Defined vertex/edge composite types and cast functions
sql/age_scalar.sql Added _get_vertex_by_graphid helper function
sql/age_main.sql Removed duplicate _label_name definition
regress/sql/*.sql Added comprehensive tests for accessor optimizations and composite types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MuhammadTahaNaveed MuhammadTahaNaveed force-pushed the columns-opt branch 3 times, most recently from a1fa547 to 4dab54d Compare January 10, 2026 16:19
…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

Assisted-by AI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

master override-stale To keep issues/PRs untouched from stale action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant