Skip to content

Commit 4dab54d

Browse files
Add vertex and edge composite types with direct field access optimization
- 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
1 parent 7beb653 commit 4dab54d

File tree

23 files changed

+2845
-341
lines changed

23 files changed

+2845
-341
lines changed

regress/expected/agtype.out

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,49 +3251,49 @@ NOTICE: graph "agtype_null_duplicate_test" has been dropped
32513251
-- Vertex
32523252
--
32533253
--Basic Vertex Creation
3254-
SELECT _agtype_build_vertex('1'::graphid, $$label_name$$, agtype_build_map());
3254+
SELECT _agtype_build_vertex('1'::graphid, '"label_name"', agtype_build_map());
32553255
_agtype_build_vertex
32563256
------------------------------------------------------------
32573257
{"id": 1, "label": "label_name", "properties": {}}::vertex
32583258
(1 row)
32593259

3260-
SELECT _agtype_build_vertex('1'::graphid, $$label$$, agtype_build_map('id', 2));
3260+
SELECT _agtype_build_vertex('1'::graphid, '"label"', agtype_build_map('id', 2));
32613261
_agtype_build_vertex
32623262
--------------------------------------------------------------
32633263
{"id": 1, "label": "label", "properties": {"id": 2}}::vertex
32643264
(1 row)
32653265

32663266
--Null properties
3267-
SELECT _agtype_build_vertex('1'::graphid, $$label_name$$, NULL);
3267+
SELECT _agtype_build_vertex('1'::graphid, '"label_name"', NULL);
32683268
_agtype_build_vertex
32693269
------------------------------------------------------------
32703270
{"id": 1, "label": "label_name", "properties": {}}::vertex
32713271
(1 row)
32723272

32733273
--Test access operator
3274-
SELECT agtype_access_operator(_agtype_build_vertex('1'::graphid, $$label$$,
3274+
SELECT agtype_access_operator(_agtype_build_vertex('1'::graphid, '"label"',
32753275
agtype_build_map('id', 2)), '"id"');
32763276
agtype_access_operator
32773277
------------------------
32783278
2
32793279
(1 row)
32803280

3281-
SELECT _agtype_build_vertex('1'::graphid, $$label$$, agtype_build_list());
3281+
SELECT _agtype_build_vertex('1'::graphid, '"label"', agtype_build_list());
32823282
ERROR: _agtype_build_vertex() properties argument must be an object
32833283
--Vertex in a map
32843284
SELECT agtype_build_map(
32853285
'vertex',
3286-
_agtype_build_vertex('1'::graphid, $$label_name$$, agtype_build_map()));
3286+
_agtype_build_vertex('1'::graphid, '"label_name"', agtype_build_map()));
32873287
agtype_build_map
32883288
------------------------------------------------------------------------
32893289
{"vertex": {"id": 1, "label": "label_name", "properties": {}}::vertex}
32903290
(1 row)
32913291

32923292
SELECT agtype_access_operator(
32933293
agtype_build_map(
3294-
'vertex', _agtype_build_vertex('1'::graphid, $$label_name$$,
3294+
'vertex', _agtype_build_vertex('1'::graphid, '"label_name"',
32953295
agtype_build_map('key', 'value')),
3296-
'other_vertex', _agtype_build_vertex('1'::graphid, $$label_name$$,
3296+
'other_vertex', _agtype_build_vertex('1'::graphid, '"label_name"',
32973297
agtype_build_map('key', 'other_value'))),
32983298
'"vertex"');
32993299
agtype_access_operator
@@ -3303,18 +3303,18 @@ SELECT agtype_access_operator(
33033303

33043304
--Vertex in a list
33053305
SELECT agtype_build_list(
3306-
_agtype_build_vertex('1'::graphid, $$label_name$$, agtype_build_map()),
3307-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()));
3306+
_agtype_build_vertex('1'::graphid, '"label_name"', agtype_build_map()),
3307+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()));
33083308
agtype_build_list
33093309
--------------------------------------------------------------------------------------------------------------------------
33103310
[{"id": 1, "label": "label_name", "properties": {}}::vertex, {"id": 2, "label": "label_name", "properties": {}}::vertex]
33113311
(1 row)
33123312

33133313
SELECT agtype_access_operator(
33143314
agtype_build_list(
3315-
_agtype_build_vertex('1'::graphid, $$label_name$$,
3315+
_agtype_build_vertex('1'::graphid, '"label_name"',
33163316
agtype_build_map('id', 3)),
3317-
_agtype_build_vertex('2'::graphid, $$label_name$$,
3317+
_agtype_build_vertex('2'::graphid, '"label_name"',
33183318
agtype_build_map('id', 4))), '0');
33193319
agtype_access_operator
33203320
-------------------------------------------------------------------
@@ -3326,30 +3326,30 @@ SELECT agtype_access_operator(
33263326
--
33273327
--Basic Edge Creation
33283328
SELECT _agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3329-
$$label_name$$, agtype_build_map());
3329+
'"label_name"', agtype_build_map());
33303330
_agtype_build_edge
33313331
--------------------------------------------------------------------------------------
33323332
{"id": 1, "label": "label_name", "end_id": 3, "start_id": 2, "properties": {}}::edge
33333333
(1 row)
33343334

33353335
SELECT _agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3336-
$$label$$, agtype_build_map('id', 2));
3336+
'"label"', agtype_build_map('id', 2));
33373337
_agtype_build_edge
33383338
----------------------------------------------------------------------------------------
33393339
{"id": 1, "label": "label", "end_id": 3, "start_id": 2, "properties": {"id": 2}}::edge
33403340
(1 row)
33413341

33423342
--Null properties
33433343
SELECT _agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3344-
$$label_name$$, NULL);
3344+
'"label_name"', NULL);
33453345
_agtype_build_edge
33463346
--------------------------------------------------------------------------------------
33473347
{"id": 1, "label": "label_name", "end_id": 3, "start_id": 2, "properties": {}}::edge
33483348
(1 row)
33493349

33503350
--Test access operator
33513351
SELECT agtype_access_operator(_agtype_build_edge('1'::graphid, '2'::graphid,
3352-
'3'::graphid, $$label$$, agtype_build_map('id', 2)),'"id"');
3352+
'3'::graphid, '"label"', agtype_build_map('id', 2)),'"id"');
33533353
agtype_access_operator
33543354
------------------------
33553355
2
@@ -3359,7 +3359,7 @@ SELECT agtype_access_operator(_agtype_build_edge('1'::graphid, '2'::graphid,
33593359
SELECT agtype_build_map(
33603360
'edge',
33613361
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3362-
$$label_name$$, agtype_build_map()));
3362+
'"label_name"', agtype_build_map()));
33633363
agtype_build_map
33643364
------------------------------------------------------------------------------------------------
33653365
{"edge": {"id": 1, "label": "label_name", "end_id": 3, "start_id": 2, "properties": {}}::edge}
@@ -3368,9 +3368,9 @@ SELECT agtype_build_map(
33683368
SELECT agtype_access_operator(
33693369
agtype_build_map(
33703370
'edge', _agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3371-
$$label_name$$, agtype_build_map('key', 'value')),
3371+
'"label_name"', agtype_build_map('key', 'value')),
33723372
'other_edge', _agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3373-
$$label_name$$, agtype_build_map('key', 'other_value'))),
3373+
'"label_name"', agtype_build_map('key', 'other_value'))),
33743374
'"edge"');
33753375
agtype_access_operator
33763376
----------------------------------------------------------------------------------------------------
@@ -3380,19 +3380,19 @@ SELECT agtype_access_operator(
33803380
--Edge in a list
33813381
SELECT agtype_build_list(
33823382
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3383-
$$label_name$$, agtype_build_map()),
3383+
'"label_name"', agtype_build_map()),
33843384
_agtype_build_edge('2'::graphid, '2'::graphid, '3'::graphid,
3385-
$$label_name$$, agtype_build_map()));
3385+
'"label_name"', agtype_build_map()));
33863386
agtype_build_list
33873387
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
33883388
[{"id": 1, "label": "label_name", "end_id": 3, "start_id": 2, "properties": {}}::edge, {"id": 2, "label": "label_name", "end_id": 3, "start_id": 2, "properties": {}}::edge]
33893389
(1 row)
33903390

33913391
SELECT agtype_access_operator(
33923392
agtype_build_list(
3393-
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid, $$label_name$$,
3393+
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid, '"label_name"',
33943394
agtype_build_map('id', 3)),
3395-
_agtype_build_edge('2'::graphid, '2'::graphid, '3'::graphid, $$label_name$$,
3395+
_agtype_build_edge('2'::graphid, '2'::graphid, '3'::graphid, '"label_name"',
33963396
agtype_build_map('id', 4))), '0');
33973397
agtype_access_operator
33983398
---------------------------------------------------------------------------------------------
@@ -3401,10 +3401,10 @@ SELECT agtype_access_operator(
34013401

34023402
-- Path
34033403
SELECT _agtype_build_path(
3404-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3404+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34053405
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3406-
$$label$$, agtype_build_map('id', 2)),
3407-
_agtype_build_vertex('3'::graphid, $$label_name$$, agtype_build_map())
3406+
'"label"', agtype_build_map('id', 2)),
3407+
_agtype_build_vertex('3'::graphid, '"label_name"', agtype_build_map())
34083408
);
34093409
_agtype_build_path
34103410
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -3413,78 +3413,78 @@ SELECT _agtype_build_path(
34133413

34143414
--All these paths should produce Errors
34153415
SELECT _agtype_build_path(
3416-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3416+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34173417
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3418-
$$label$$, agtype_build_map('id', 2))
3418+
'"label"', agtype_build_map('id', 2))
34193419
);
34203420
ERROR: a path is of the form: [vertex, (edge, vertex)*i] where i >= 0
34213421
SELECT _agtype_build_path(
3422-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3422+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34233423
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3424-
$$label$$, agtype_build_map('id', 2)),
3425-
_agtype_build_vertex('3'::graphid, $$label_name$$, agtype_build_map()),
3424+
'"label"', agtype_build_map('id', 2)),
3425+
_agtype_build_vertex('3'::graphid, '"label_name"', agtype_build_map()),
34263426
_agtype_build_edge('1'::graphid, '4'::graphid, '5'::graphid,
3427-
$$label$$, agtype_build_map('id', 2))
3427+
'"label"', agtype_build_map('id', 2))
34283428
);
34293429
ERROR: a path is of the form: [vertex, (edge, vertex)*i] where i >= 0
34303430
SELECT _agtype_build_path(
3431-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3431+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34323432
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3433-
$$label$$, agtype_build_map('id', 2)),
3433+
'"label"', agtype_build_map('id', 2)),
34343434
NULL
34353435
);
34363436
ERROR: argument 3 must not be null
34373437
SELECT _agtype_build_path(
3438-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3438+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34393439
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3440-
$$label$$, agtype_build_map('id', 2)),
3440+
'"label"', agtype_build_map('id', 2)),
34413441
1
34423442
);
34433443
ERROR: argument 3 must be an agtype
34443444
SELECT _agtype_build_path(
3445-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3445+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34463446
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3447-
$$label$$, agtype_build_map('id', 2)),
3447+
'"label"', agtype_build_map('id', 2)),
34483448
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3449-
$$label$$, agtype_build_map('id', 2))
3449+
'"label"', agtype_build_map('id', 2))
34503450
);
34513451
ERROR: paths consist of alternating vertices and edges
34523452
HINT: argument 3 must be an vertex
34533453
--
34543454
-- id, startid, endid
34553455
--
3456-
SELECT age_id(_agtype_build_vertex('1'::graphid, $$label_name$$, agtype_build_map()));
3456+
SELECT age_id(_agtype_build_vertex('1'::graphid, '"label_name"', agtype_build_map()));
34573457
age_id
34583458
--------
34593459
1
34603460
(1 row)
34613461

34623462
SELECT age_id(_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3463-
$$label_name$$, agtype_build_map('id', 2)));
3463+
'"label_name"', agtype_build_map('id', 2)));
34643464
age_id
34653465
--------
34663466
1
34673467
(1 row)
34683468

34693469
SELECT age_start_id(_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3470-
$$label_name$$, agtype_build_map('id', 2)));
3470+
'"label_name"', agtype_build_map('id', 2)));
34713471
age_start_id
34723472
--------------
34733473
2
34743474
(1 row)
34753475

34763476
SELECT age_end_id(_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3477-
$$label_name$$, agtype_build_map('id', 2)));
3477+
'"label_name"', agtype_build_map('id', 2)));
34783478
age_end_id
34793479
------------
34803480
3
34813481
(1 row)
34823482

34833483
SELECT age_id(_agtype_build_path(
3484-
_agtype_build_vertex('2'::graphid, $$label_name$$, agtype_build_map()),
3484+
_agtype_build_vertex('2'::graphid, '"label_name"', agtype_build_map()),
34853485
_agtype_build_edge('1'::graphid, '2'::graphid, '3'::graphid,
3486-
$$label$$, agtype_build_map('id', 2)),
3487-
_agtype_build_vertex('3'::graphid, $$label$$, agtype_build_map('id', 2))
3486+
'"label"', agtype_build_map('id', 2)),
3487+
_agtype_build_vertex('3'::graphid, '"label"', agtype_build_map('id', 2))
34883488
));
34893489
ERROR: id() argument must be a vertex, an edge or null
34903490
SELECT age_id(agtype_in('1'));

regress/expected/cypher_match.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ $$) AS (r0 agtype);
710710
---------------------------------------------------------------------------------------------------------------------------
711711
{"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge
712712
{"id": 1407374883553281, "label": "e1", "end_id": 1125899906842627, "start_id": 1125899906842626, "properties": {}}::edge
713-
{"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge
714713
{"id": 1970324836974593, "label": "e2", "end_id": 1688849860263939, "start_id": 1688849860263938, "properties": {}}::edge
715-
{"id": 2533274790395905, "label": "e3", "end_id": 2251799813685250, "start_id": 2251799813685251, "properties": {}}::edge
714+
{"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge
716715
{"id": 2533274790395906, "label": "e3", "end_id": 2251799813685250, "start_id": 2251799813685249, "properties": {}}::edge
716+
{"id": 2533274790395905, "label": "e3", "end_id": 2251799813685250, "start_id": 2251799813685251, "properties": {}}::edge
717717
(6 rows)
718718

719719
SELECT * FROM cypher('cypher_match', $$
@@ -730,8 +730,8 @@ SELECT * FROM cypher('cypher_match', $$
730730
$$) AS (r0 agtype);
731731
r0
732732
---------------------------------------------------------------------------------------------------------------------------
733-
{"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge
734733
{"id": 1970324836974593, "label": "e2", "end_id": 1688849860263939, "start_id": 1688849860263938, "properties": {}}::edge
734+
{"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge
735735
(2 rows)
736736

737737
SELECT * FROM cypher('cypher_match', $$

0 commit comments

Comments
 (0)