Skip to content

Commit 73df6c3

Browse files
committed
Add switch for retrieve vertex to remove when no prop
constraints are used
1 parent 84a6bb2 commit 73df6c3

4 files changed

Lines changed: 126 additions & 64 deletions

File tree

regress/expected/cypher_create.out

Lines changed: 109 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ USE GRAPH cypher_create;
3333

3434
CREATE ();
3535
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
36-
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
3736
--
3837
(0 rows)
3938

4039
SELECT * FROM cypher_create._ag_label_vertex;
41-
id | properties
42-
-----------------+------------
43-
281474976710657 |
40+
id | properties
41+
--------+------------
42+
(1, 1) |
4443
(1 row)
4544

4645
MATCH () RETURN 1;
@@ -57,64 +56,75 @@ NOTICE: VLabel "test" has been created
5756
(1 row)
5857

5958
SELECT * FROM postgraph.ag_label;
60-
name | graph | id | kind | relation | vertex_adjlist | label_path
61-
------------------+-------+----+------+--------------------------------+-------------------------------------+-----------------------
62-
_ag_label_vertex | 18780 | 1 | v | 18783 | 18792 | _ag_label_vertex
63-
_ag_label_edge | 18780 | 2 | e | 18796 | | _ag_label_edge
64-
_ag_label_vertex | 18805 | 1 | v | 18808 | 18817 | _ag_label_vertex
65-
_ag_label_edge | 18805 | 2 | e | 18821 | | _ag_label_edge
66-
_ag_label_vertex | 18833 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
67-
_ag_label_edge | 18833 | 2 | e | cypher_create._ag_label_edge | | _ag_label_edge
68-
test | 18833 | 3 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
69-
(7 rows)
59+
name | graph | id | kind | relation | vertex_adjlist | label_path
60+
----------------------------+-------+----+------+------------------------------------------+-------------------------------------+-------------------------------------------
61+
_adj__adj__ag_label_vertex | 18790 | 2 | e | 18807 | | _ag_label_edge._adj__adj__ag_label_vertex
62+
_ag_label_vertex | 18790 | 1 | v | 18793 | 18802 | _ag_label_vertex
63+
_ag_label_edge | 18790 | 3 | e | 18817 | | _ag_label_edge
64+
_adj__adj__ag_label_vertex | 18826 | 2 | e | 18843 | | _ag_label_edge._adj__adj__ag_label_vertex
65+
_ag_label_vertex | 18826 | 1 | v | 18829 | 18838 | _ag_label_vertex
66+
_ag_label_edge | 18826 | 3 | e | 18853 | | _ag_label_edge
67+
_adj__adj__ag_label_vertex | 18862 | 2 | e | cypher_create._adj__adj__ag_label_vertex | | _ag_label_edge._adj__adj__ag_label_vertex
68+
_ag_label_vertex | 18862 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
69+
_ag_label_edge | 18862 | 3 | e | cypher_create._ag_label_edge | | _ag_label_edge
70+
_adj__adj_test | 18862 | 5 | e | cypher_create._adj__adj_test | | _ag_label_edge._adj__adj_test
71+
test | 18862 | 4 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
72+
(11 rows)
7073

7174
CREATE (:test);
7275
WARNING: relcache reference leak: relation "test" not closed
73-
WARNING: relcache reference leak: relation "test" not closed
7476
--
7577
(0 rows)
7678

7779
SELECT * FROM postgraph.ag_label;
78-
name | graph | id | kind | relation | vertex_adjlist | label_path
79-
------------------+-------+----+------+--------------------------------+-------------------------------------+-----------------------
80-
_ag_label_vertex | 18780 | 1 | v | 18783 | 18792 | _ag_label_vertex
81-
_ag_label_edge | 18780 | 2 | e | 18796 | | _ag_label_edge
82-
_ag_label_vertex | 18805 | 1 | v | 18808 | 18817 | _ag_label_vertex
83-
_ag_label_edge | 18805 | 2 | e | 18821 | | _ag_label_edge
84-
_ag_label_vertex | 18833 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
85-
_ag_label_edge | 18833 | 2 | e | cypher_create._ag_label_edge | | _ag_label_edge
86-
test | 18833 | 3 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
87-
(7 rows)
80+
name | graph | id | kind | relation | vertex_adjlist | label_path
81+
----------------------------+-------+----+------+------------------------------------------+-------------------------------------+-------------------------------------------
82+
_adj__adj__ag_label_vertex | 18790 | 2 | e | 18807 | | _ag_label_edge._adj__adj__ag_label_vertex
83+
_ag_label_vertex | 18790 | 1 | v | 18793 | 18802 | _ag_label_vertex
84+
_ag_label_edge | 18790 | 3 | e | 18817 | | _ag_label_edge
85+
_adj__adj__ag_label_vertex | 18826 | 2 | e | 18843 | | _ag_label_edge._adj__adj__ag_label_vertex
86+
_ag_label_vertex | 18826 | 1 | v | 18829 | 18838 | _ag_label_vertex
87+
_ag_label_edge | 18826 | 3 | e | 18853 | | _ag_label_edge
88+
_adj__adj__ag_label_vertex | 18862 | 2 | e | cypher_create._adj__adj__ag_label_vertex | | _ag_label_edge._adj__adj__ag_label_vertex
89+
_ag_label_vertex | 18862 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
90+
_ag_label_edge | 18862 | 3 | e | cypher_create._ag_label_edge | | _ag_label_edge
91+
_adj__adj_test | 18862 | 5 | e | cypher_create._adj__adj_test | | _ag_label_edge._adj__adj_test
92+
test | 18862 | 4 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
93+
(11 rows)
8894

8995
SELECT * FROM cypher_create.test;
90-
id | properties
91-
-----------------+------------
92-
844424930131969 |
96+
id | properties
97+
--------+------------
98+
(4, 1) |
9399
(1 row)
94100

95101
CREATE (:test2);
96102
WARNING: relcache reference leak: relation "test2" not closed
97-
WARNING: relcache reference leak: relation "test2" not closed
98103
--
99104
(0 rows)
100105

101106
SELECT * FROM postgraph.ag_label;
102-
name | graph | id | kind | relation | vertex_adjlist | label_path
103-
------------------+-------+----+------+--------------------------------+-------------------------------------+------------------------
104-
_ag_label_vertex | 18780 | 1 | v | 18783 | 18792 | _ag_label_vertex
105-
_ag_label_edge | 18780 | 2 | e | 18796 | | _ag_label_edge
106-
_ag_label_vertex | 18805 | 1 | v | 18808 | 18817 | _ag_label_vertex
107-
_ag_label_edge | 18805 | 2 | e | 18821 | | _ag_label_edge
108-
_ag_label_vertex | 18833 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
109-
_ag_label_edge | 18833 | 2 | e | cypher_create._ag_label_edge | | _ag_label_edge
110-
test | 18833 | 3 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
111-
test2 | 18833 | 4 | v | cypher_create.test2 | cypher_create._adj_test2 | _ag_label_vertex.test2
112-
(8 rows)
107+
name | graph | id | kind | relation | vertex_adjlist | label_path
108+
----------------------------+-------+----+------+------------------------------------------+-------------------------------------+-------------------------------------------
109+
_adj__adj__ag_label_vertex | 18790 | 2 | e | 18807 | | _ag_label_edge._adj__adj__ag_label_vertex
110+
_ag_label_vertex | 18790 | 1 | v | 18793 | 18802 | _ag_label_vertex
111+
_ag_label_edge | 18790 | 3 | e | 18817 | | _ag_label_edge
112+
_adj__adj__ag_label_vertex | 18826 | 2 | e | 18843 | | _ag_label_edge._adj__adj__ag_label_vertex
113+
_ag_label_vertex | 18826 | 1 | v | 18829 | 18838 | _ag_label_vertex
114+
_ag_label_edge | 18826 | 3 | e | 18853 | | _ag_label_edge
115+
_adj__adj__ag_label_vertex | 18862 | 2 | e | cypher_create._adj__adj__ag_label_vertex | | _ag_label_edge._adj__adj__ag_label_vertex
116+
_ag_label_vertex | 18862 | 1 | v | cypher_create._ag_label_vertex | cypher_create._adj__ag_label_vertex | _ag_label_vertex
117+
_ag_label_edge | 18862 | 3 | e | cypher_create._ag_label_edge | | _ag_label_edge
118+
_adj__adj_test | 18862 | 5 | e | cypher_create._adj__adj_test | | _ag_label_edge._adj__adj_test
119+
test | 18862 | 4 | v | cypher_create.test | cypher_create._adj_test | _ag_label_vertex.test
120+
_adj__adj_test2 | 18862 | 7 | e | cypher_create._adj__adj_test2 | | _ag_label_edge._adj__adj_test2
121+
test2 | 18862 | 6 | v | cypher_create.test2 | cypher_create._adj_test2 | _ag_label_vertex.test2
122+
(13 rows)
113123

114124
SELECT * FROM cypher_create.test2;
115-
id | properties
116-
------------------+------------
117-
1125899906842625 |
125+
id | properties
126+
--------+------------
127+
(6, 1) |
118128
(1 row)
119129

120130
MATCH () RETURN 1;
@@ -128,12 +138,62 @@ MATCH () RETURN 1;
128138
CREATE ()-[]->();
129139
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
130140
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
131-
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
132-
WARNING: relcache reference leak: relation "_ag_label_vertex" not closed
133141
WARNING: relcache reference leak: relation "_ag_label_edge" not closed
134142
--
135143
(0 rows)
136144

145+
EXPLAIN MATCH ()-[]->() RETURN 1;
146+
QUERY PLAN
147+
-----------------------------------------------------------------------------------------------------
148+
Nested Loop (cost=12.50..50471.30 rows=2520000 width=32)
149+
-> Append (cost=0.00..58.80 rows=2520 width=8)
150+
-> Seq Scan on _ag_label_vertex _age_default_alias_0_1 (cost=0.00..2.20 rows=120 width=8)
151+
-> Seq Scan on test _age_default_alias_0_2 (cost=0.00..22.00 rows=1200 width=8)
152+
-> Seq Scan on test2 _age_default_alias_0_3 (cost=0.00..22.00 rows=1200 width=8)
153+
-> Function Scan on edge_search _age_default_alias_1 (cost=12.50..22.50 rows=1000 width=0)
154+
(6 rows)
155+
156+
EXPLAIN ANALYZE MATCH ()-[]->() RETURN 1;
157+
QUERY PLAN
158+
-----------------------------------------------------------------------------------------------------------------------------------------------
159+
Nested Loop (cost=12.50..50471.30 rows=2520000 width=32) (actual time=0.060..0.237 rows=1 loops=1)
160+
-> Append (cost=0.00..58.80 rows=2520 width=8) (actual time=0.005..0.013 rows=5 loops=1)
161+
-> Seq Scan on _ag_label_vertex _age_default_alias_0_1 (cost=0.00..2.20 rows=120 width=8) (actual time=0.005..0.006 rows=3 loops=1)
162+
-> Seq Scan on test _age_default_alias_0_2 (cost=0.00..22.00 rows=1200 width=8) (actual time=0.001..0.002 rows=1 loops=1)
163+
-> Seq Scan on test2 _age_default_alias_0_3 (cost=0.00..22.00 rows=1200 width=8) (actual time=0.002..0.002 rows=1 loops=1)
164+
-> Function Scan on edge_search _age_default_alias_1 (cost=12.50..22.50 rows=1000 width=0) (actual time=0.043..0.043 rows=0 loops=5)
165+
Planning Time: 0.095 ms
166+
Execution Time: 0.262 ms
167+
(8 rows)
168+
169+
MATCH ()-[]->() RETURN 1;
170+
?column?
171+
----------
172+
1
173+
(1 row)
174+
175+
SELECT * FROM cypher_create._ag_label_vertex;
176+
id | properties
177+
--------+------------
178+
(1, 1) |
179+
(1, 2) |
180+
(1, 3) |
181+
(4, 1) |
182+
(6, 1) |
183+
(5 rows)
184+
185+
SELECT * FROM cypher_create._adj__adj__ag_label_vertex;
186+
id | start_id | end_id | properties
187+
---------------+----------+--------+------------
188+
(0, 41914048) | (1, 2) | (1, 3) |
189+
(1 row)
190+
191+
SELECT * FROM cypher_create._adj__ag_label_vertex;
192+
id | start_id | end_id | properties
193+
---------------+----------+--------+------------
194+
(0, 41914048) | (1, 2) | (1, 3) |
195+
(1 row)
196+
137197
MATCH () RETURN 1;
138198
?column?
139199
----------
@@ -153,14 +213,17 @@ ERROR: CREATE doesn't work with next clauses
153213
-- Clean up
154214
--
155215
DROP GRAPH cypher_create CASCADE;
156-
NOTICE: drop cascades to 7 other objects
216+
NOTICE: drop cascades to 10 other objects
157217
DETAIL: drop cascades to table cypher_create._ag_label_vertex
158218
drop cascades to table cypher_create._adj__ag_label_vertex
219+
drop cascades to table cypher_create._adj__adj__ag_label_vertex
159220
drop cascades to table cypher_create._ag_label_edge
160221
drop cascades to table cypher_create.test
161222
drop cascades to table cypher_create._adj_test
223+
drop cascades to table cypher_create._adj__adj_test
162224
drop cascades to table cypher_create.test2
163225
drop cascades to table cypher_create._adj_test2
226+
drop cascades to table cypher_create._adj__adj_test2
164227
NOTICE: graph "cypher_create" has been dropped
165228
drop_graph
166229
------------

regress/expected/new_cypher.out

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,18 @@ USE GRAPH new_cypher;
7272
SELECT * FROM postgraph.ag_label WHERE name = '_ag_label_vertex';
7373
name | graph | id | kind | relation | vertex_adjlist | label_path
7474
------------------+-------+----+------+-------------------------------+------------------------------------+------------------
75-
_ag_label_vertex | 18780 | 1 | v | new_cypher._ag_label_vertex | new_cypher._adj__ag_label_vertex | _ag_label_vertex
76-
_ag_label_vertex | 18805 | 1 | v | new_cypher_2._ag_label_vertex | new_cypher_2._adj__ag_label_vertex | _ag_label_vertex
75+
_ag_label_vertex | 18790 | 1 | v | new_cypher._ag_label_vertex | new_cypher._adj__ag_label_vertex | _ag_label_vertex
76+
_ag_label_vertex | 18826 | 1 | v | new_cypher_2._ag_label_vertex | new_cypher_2._adj__ag_label_vertex | _ag_label_vertex
7777
(2 rows)
7878

7979
\d+ new_cypher._adj__ag_label_vertex
80-
Table "new_cypher._adj__ag_label_vertex"
81-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
82-
---------+---------+-----------+----------+---------+----------+--------------+-------------
83-
id | graphid | | | | plain | |
84-
adjlist | gtype | | | | extended | |
80+
Table "new_cypher._adj__ag_label_vertex"
81+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
82+
------------+---------+-----------+----------+-------------------+----------+--------------+-------------
83+
id | graphid | | | | plain | |
84+
start_id | graphid | | not null | | plain | |
85+
end_id | graphid | | not null | | plain | |
86+
properties | gtype | | | gtype_build_map() | extended | |
8587

8688
SELECT c.relname AS table_name,am.amname AS access_method
8789
FROM pg_class c
@@ -94,9 +96,10 @@ WHERE c.relkind = 'r' AND c.relname = '_adj__ag_label_vertex';
9496
(2 rows)
9597

9698
DROP GRAPH new_cypher CASCADE;
97-
NOTICE: drop cascades to 3 other objects
99+
NOTICE: drop cascades to 4 other objects
98100
DETAIL: drop cascades to table new_cypher._ag_label_vertex
99101
drop cascades to table new_cypher._adj__ag_label_vertex
102+
drop cascades to table new_cypher._adj__adj__ag_label_vertex
100103
drop cascades to table new_cypher._ag_label_edge
101104
NOTICE: graph "new_cypher" has been dropped
102105
drop_graph
@@ -105,9 +108,10 @@ NOTICE: graph "new_cypher" has been dropped
105108
(1 row)
106109

107110
DROP GRAPH new_cypher_2 CASCADE;
108-
NOTICE: drop cascades to 3 other objects
111+
NOTICE: drop cascades to 4 other objects
109112
DETAIL: drop cascades to table new_cypher_2._ag_label_vertex
110113
drop cascades to table new_cypher_2._adj__ag_label_vertex
114+
drop cascades to table new_cypher_2._adj__adj__ag_label_vertex
111115
drop cascades to table new_cypher_2._ag_label_edge
112116
NOTICE: graph "new_cypher_2" has been dropped
113117
drop_graph

src/backend/parser/cypher_clause.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,13 +1264,17 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query, Li
12641264
//
12651265
} else {
12661266

1267+
if (node->props) {
12671268
int sublevels_up =1;
12681269
Node * id_field = scanNSItemForColumn(cpstate, edge_pnsi, 0, "endid", -1);
12691270

12701271
FuncCall *fc = makeFuncCall(list_make2(makeString("postgraph"), makeString("retrieve_vertex")),
12711272
list_make2(make_int_const(cpstate->graph_oid, -1),id_field),
12721273
COERCE_EXPLICIT_CALL, -1);
12731274
pnsi = add_srf_to_query1(cpstate, fc, node->name);
1275+
} else {
1276+
continue;
1277+
}
12741278
//edge_pnsi = pnsi;
12751279
}
12761280
//expr = (Expr *)make_vertex_expr(cpstate, pnsi);

src/backend/utils/edge_searching.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static Datum get_vertex(Oid graph_oid, int64 graphid)
8181
table_endscan(scan_desc);
8282
table_close(graph_vertex_label, ShareLock);
8383

84-
8584
return properties;
8685
}
8786

@@ -168,17 +167,9 @@ Datum edge_search(PG_FUNCTION_ARGS)
168167
TableAmRoutine *vertex_am = GetVertexHeapamTableAmRoutine();
169168

170169
if (!table_scan_getnextslot(cxt->scan_desc, ForwardScanDirection, cxt->slot)) {
171-
//DecrTupleDescRefCount(funcctx->tuple_desc);
172-
//if (funcctx->tuple_desc->tdrefcount > 1) {
173-
// ereport(WARNING, errmsg("tdrefcount is %d", funcctx->tuple_desc->tdrefcount));
174-
//}
175170
ReleaseTupleDesc(RelationGetDescr(cxt->rel));
176171
table_endscan(cxt->scan_desc);
177172
table_close(cxt->rel, ShareLock);
178-
179-
//DecrTupleDescRefCount(funcctx->tuple_desc);
180-
pfree(cxt->scan_desc);
181-
pfree(cxt);
182173
SRF_RETURN_DONE(funcctx);
183174
}
184175

0 commit comments

Comments
 (0)