Commit 6a3fe88
committed
Optimize vertex/edge field access with direct array indexing
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.h1 parent c979380 commit 6a3fe88
4 files changed
Lines changed: 450 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5409 | 5409 | | |
5410 | 5410 | | |
5411 | 5411 | | |
5412 | | - | |
5413 | | - | |
5414 | | - | |
5415 | | - | |
| 5412 | + | |
| 5413 | + | |
| 5414 | + | |
| 5415 | + | |
| 5416 | + | |
| 5417 | + | |
| 5418 | + | |
| 5419 | + | |
| 5420 | + | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
5416 | 5430 | | |
5417 | 5431 | | |
5418 | 5432 | | |
| |||
5447 | 5461 | | |
5448 | 5462 | | |
5449 | 5463 | | |
5450 | | - | |
5451 | | - | |
5452 | | - | |
5453 | | - | |
| 5464 | + | |
| 5465 | + | |
| 5466 | + | |
| 5467 | + | |
| 5468 | + | |
5454 | 5469 | | |
5455 | 5470 | | |
5456 | 5471 | | |
| |||
5485 | 5500 | | |
5486 | 5501 | | |
5487 | 5502 | | |
5488 | | - | |
5489 | | - | |
5490 | | - | |
5491 | | - | |
| 5503 | + | |
| 5504 | + | |
| 5505 | + | |
| 5506 | + | |
| 5507 | + | |
5492 | 5508 | | |
5493 | 5509 | | |
5494 | 5510 | | |
| |||
6038 | 6054 | | |
6039 | 6055 | | |
6040 | 6056 | | |
6041 | | - | |
6042 | | - | |
6043 | | - | |
6044 | | - | |
| 6057 | + | |
| 6058 | + | |
| 6059 | + | |
| 6060 | + | |
| 6061 | + | |
| 6062 | + | |
| 6063 | + | |
| 6064 | + | |
| 6065 | + | |
| 6066 | + | |
| 6067 | + | |
| 6068 | + | |
| 6069 | + | |
| 6070 | + | |
| 6071 | + | |
| 6072 | + | |
| 6073 | + | |
| 6074 | + | |
| 6075 | + | |
6045 | 6076 | | |
6046 | 6077 | | |
6047 | 6078 | | |
| |||
7170 | 7201 | | |
7171 | 7202 | | |
7172 | 7203 | | |
7173 | | - | |
7174 | | - | |
| 7204 | + | |
| 7205 | + | |
| 7206 | + | |
| 7207 | + | |
| 7208 | + | |
| 7209 | + | |
| 7210 | + | |
| 7211 | + | |
| 7212 | + | |
| 7213 | + | |
| 7214 | + | |
| 7215 | + | |
| 7216 | + | |
| 7217 | + | |
| 7218 | + | |
| 7219 | + | |
| 7220 | + | |
| 7221 | + | |
7175 | 7222 | | |
7176 | 7223 | | |
7177 | 7224 | | |
| |||
10507 | 10554 | | |
10508 | 10555 | | |
10509 | 10556 | | |
| 10557 | + | |
| 10558 | + | |
| 10559 | + | |
| 10560 | + | |
| 10561 | + | |
| 10562 | + | |
| 10563 | + | |
| 10564 | + | |
| 10565 | + | |
| 10566 | + | |
| 10567 | + | |
| 10568 | + | |
| 10569 | + | |
| 10570 | + | |
| 10571 | + | |
| 10572 | + | |
| 10573 | + | |
| 10574 | + | |
| 10575 | + | |
| 10576 | + | |
| 10577 | + | |
| 10578 | + | |
| 10579 | + | |
| 10580 | + | |
| 10581 | + | |
| 10582 | + | |
| 10583 | + | |
| 10584 | + | |
| 10585 | + | |
| 10586 | + | |
| 10587 | + | |
| 10588 | + | |
| 10589 | + | |
| 10590 | + | |
| 10591 | + | |
| 10592 | + | |
| 10593 | + | |
| 10594 | + | |
| 10595 | + | |
| 10596 | + | |
| 10597 | + | |
| 10598 | + | |
| 10599 | + | |
| 10600 | + | |
| 10601 | + | |
| 10602 | + | |
| 10603 | + | |
| 10604 | + | |
| 10605 | + | |
| 10606 | + | |
| 10607 | + | |
| 10608 | + | |
| 10609 | + | |
10510 | 10610 | | |
10511 | 10611 | | |
10512 | 10612 | | |
| |||
0 commit comments