Skip to content

Add vertex and edge composite types with direct field access optimization#209

Closed
MuhammadTahaNaveed wants to merge 1 commit into
masterfrom
columns-opt
Closed

Add vertex and edge composite types with direct field access optimization#209
MuhammadTahaNaveed wants to merge 1 commit into
masterfrom
columns-opt

Conversation

@MuhammadTahaNaveed

Copy link
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) and edge(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.

Copilot AI Jan 10, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread src/backend/parser/cypher_expr.c
Comment thread src/backend/parser/cypher_expr.c
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants