Skip to content

Conversation

@jrgemignani
Copy link
Contributor

NOTE: This PR was created using AI tools and a human.

Leverage deterministic key ordering from uniqueify_agtype_object() to access vertex/edge fields in O(1) instead of O(log n) binary search.

Fields are sorted by key length, giving fixed positions:

  • Vertex: id(0), label(1), properties(2)
  • Edge: id(0), label(1), end_id(2), start_id(3), properties(4)

Changes:

  • Add field index constants and accessor macros to agtype.h
  • Update age_id(), age_start_id(), age_end_id(), age_label(), age_properties() to use direct field access
  • Add fill_agtype_value_no_copy() for read-only scalar extraction without memory allocation
  • Add compare_agtype_scalar_containers() fast path for scalar comparison
  • Update hash_agtype_value(), equals_agtype_scalar_value(), and compare_agtype_scalar_values() to use direct field access macros
  • Add fast path in get_one_agtype_from_variadic_args() bypassing extract_variadic_args() for single argument case
  • Add comprehensive regression test (30 tests)

Performance impact: Improves ORDER BY, hash joins, aggregations, and Cypher functions (id, start_id, end_id, label, properties) on vertices and edges.

All previous regression tests were not impacted.
Additional regression test added to enhance coverage.

modified: Makefile
new file: regress/expected/direct_field_access.out
new file: regress/sql/direct_field_access.sql
modified: src/backend/utils/adt/agtype.c
modified: src/backend/utils/adt/agtype_util.c
modified: src/include/utils/agtype.h

@github-actions github-actions bot added master override-stale To keep issues/PRs untouched from stale action labels Jan 10, 2026
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 PR optimizes vertex and edge field access by leveraging the deterministic key ordering from uniqueify_agtype_object() to use direct array indexing instead of binary search, providing O(1) instead of O(log n) access time.

Key Changes:

  • Introduces direct field access macros and constants for vertex (3 fields) and edge (5 fields) objects based on key length sorting
  • Adds fill_agtype_value_no_copy() for read-only scalar extraction without memory allocation
  • Implements fast path in compare_agtype_scalar_containers() for scalar comparisons
  • Optimizes get_one_agtype_from_variadic_args() to bypass extract_variadic_args() for single agtype arguments

Reviewed changes

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

Show a summary per file
File Description
src/include/utils/agtype.h Adds field index constants and direct access macros for vertex/edge objects
src/backend/utils/adt/agtype_util.c Implements no-copy value extraction and scalar comparison fast paths; fixes bounds checking in comparison functions
src/backend/utils/adt/agtype.c Updates accessor functions (id, start_id, end_id, label, properties) to use direct field access; adds fast path for variadic arg handling; fixes 4 assert bugs (= to ==)
regress/sql/direct_field_access.sql Comprehensive test suite covering scalar comparisons, ORDER BY, vertex/edge operations, and edge cases
regress/expected/direct_field_access.out Expected test output
Makefile Registers new regression test

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

@jrgemignani jrgemignani force-pushed the optimize_vertex_edge_field_access branch from 7537dd0 to 6a3fe88 Compare January 13, 2026 23:54
NOTE: This PR was created using AI tools and a human.

Leverage deterministic key ordering from uniqueify_agtype_object() to
access vertex/edge fields in O(1) instead of O(log n) binary search.

Fields are sorted by key length, giving fixed positions:
- Vertex: id(0), label(1), properties(2)
- Edge: id(0), label(1), end_id(2), start_id(3), properties(4)

Changes:
- Add field index constants and accessor macros to agtype.h
- Update age_id(), age_start_id(), age_end_id(), age_label(),
  age_properties() to use direct field access
- Add fill_agtype_value_no_copy() for read-only scalar extraction
  without memory allocation
- Add compare_agtype_scalar_containers() fast path for scalar comparison
- Update hash_agtype_value(), equals_agtype_scalar_value(), and
  compare_agtype_scalar_values() to use direct field access macros
- Add fast path in get_one_agtype_from_variadic_args() bypassing
  extract_variadic_args() for single argument case
- Add comprehensive regression test (30 tests)

Performance impact: Improves ORDER BY, hash joins, aggregations, and
Cypher functions (id, start_id, end_id, label, properties) on vertices
and edges.

All previous regression tests were not impacted.
Additional regression test added to enhance coverage.

modified:   Makefile
new file:   regress/expected/direct_field_access.out
new file:   regress/sql/direct_field_access.sql
modified:   src/backend/utils/adt/agtype.c
modified:   src/backend/utils/adt/agtype_util.c
modified:   src/include/utils/agtype.h
@jrgemignani jrgemignani force-pushed the optimize_vertex_edge_field_access branch from 6a3fe88 to d863820 Compare January 13, 2026 23:58
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