Skip to content

Commit 597508d

Browse files
committed
Get Basic MATCH pattern ready
()-[]->() works, kinda. This is the base that everything after needs to do MATCH patterns efficiently, or... at least more efficiently than it was before
1 parent ecf4129 commit 597508d

File tree

12 files changed

+734
-1492
lines changed

12 files changed

+734
-1492
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ OBJS = src/backend/postgraph.o \
6464
src/backend/utils/adt/vector.o \
6565
src/backend/utils/adt/vertex.o \
6666
src/backend/utils/ag_func.o \
67+
src/backend/utils/edge_searching.o \
6768
src/backend/utils/cache/ag_cache.o \
6869

6970
EXTENSION = postgraph

postgraph--0.1.0.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,26 @@ PARALLEL SAFE
429429
RETURNS NULL ON NULL INPUT
430430
as 'MODULE_PATHNAME';
431431

432+
CREATE TYPE edge_composite AS (id graphid, startid graphid, endid graphid, properties gtype);
433+
434+
CREATE FUNCTION edge_search(graph_oid gtype, id graphid, label gtype, include_props gtype)
435+
RETURNS TABLE (id graphid, startid graphid, endid graphid, properties gtype)
436+
CALLED ON NULL INPUT
437+
STABLE
438+
PARALLEL SAFE
439+
LANGUAGE C
440+
COST 5000
441+
AS 'MODULE_PATHNAME';
442+
443+
444+
CREATE FUNCTION retrieve_vertex(graph_oid gtype, id graphid)
445+
RETURNS gtype
446+
RETURNS NULL ON NULL INPUT
447+
STABLE
448+
PARALLEL SAFE
449+
LANGUAGE C
450+
COST 5000
451+
AS 'MODULE_PATHNAME';
432452

433453
--
434454
-- There are times when the optimizer might eliminate

regress/sql/cypher_create.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CREATE ()-[]->();
4848

4949
EXPLAIN MATCH ()-[]->() RETURN 1;
5050

51+
EXPLAIN ANALYZE MATCH ()-[]->() RETURN 1;
5152

5253
MATCH ()-[]->() RETURN 1;
5354

@@ -57,11 +58,13 @@ SELECT * FROM cypher_create._adj__adj__ag_label_vertex;
5758
SELECT * FROM cypher_create._adj__ag_label_vertex;
5859
MATCH () RETURN 1;
5960

61+
6062
CYPHER WITH 1 as a
6163
CREATE ();
6264

6365
CREATE () RETURN 1 as a;
6466

67+
6568
--
6669
-- Clean up
6770
--

src/backend/access/vertex_heap/vertex_hash_search.c

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -34,100 +34,6 @@ static void vertex_hash_readnext(TableScanDesc scan, Buffer *bufp,
3434
Page *pagep, HashPageOpaque *opaquep);
3535
static void vertex_hash_kill_items(TableScanDesc scan);
3636

37-
/*
38-
* vertex_hash_next() -- Get the next item in a scan.
39-
*
40-
* On entry, so->currPos describes the current page, which may
41-
* be pinned but not locked, and so->currPos.itemIndex identifies
42-
* which item was previously returned.
43-
*
44-
* On successful exit, scan->xs_ctup.t_self is set to the TID
45-
* of the next heap tuple. so->currPos is updated as needed.
46-
*
47-
* On failure exit (no more tuples), we return false with pin
48-
* held on bucket page but no pins or locks held on overflow
49-
* page.
50-
*/
51-
bool
52-
vertex_hash_next(TableScanDesc scan, ScanDirection dir)
53-
{
54-
Relation rel = scan->rs_rd;
55-
VertexHeapScanDesc so = (VertexHeapScanDesc) scan;
56-
HashScanPosItem *currItem;
57-
BlockNumber blkno;
58-
Buffer buf;
59-
bool end_of_scan = false;
60-
61-
/*
62-
* Advance to the next tuple on the current page; or if done, try to read
63-
* data from the next or previous page based on the scan direction. Before
64-
* moving to the next or previous page make sure that we deal with all the
65-
* killed items.
66-
*/
67-
if (ScanDirectionIsForward(dir))
68-
{
69-
if (++so->currPos.itemIndex > so->currPos.lastItem)
70-
{
71-
if (so->numKilled > 0)
72-
vertex_hash_kill_items(scan);
73-
74-
blkno = so->currPos.nextPage;
75-
if (BlockNumberIsValid(blkno))
76-
{
77-
buf = _hash_getbuf(rel, blkno, HASH_READ, LH_OVERFLOW_PAGE);
78-
TestForOldSnapshot(scan->rs_snapshot, rel, BufferGetPage(buf));
79-
if (!vertex_hash_readpage(scan, &buf, dir))
80-
end_of_scan = true;
81-
}
82-
else
83-
end_of_scan = true;
84-
}
85-
}
86-
else
87-
{
88-
if (--so->currPos.itemIndex < so->currPos.firstItem)
89-
{
90-
if (so->numKilled > 0)
91-
vertex_hash_kill_items(scan);
92-
93-
blkno = so->currPos.prevPage;
94-
if (BlockNumberIsValid(blkno))
95-
{
96-
buf = _hash_getbuf(rel, blkno, HASH_READ,
97-
LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
98-
TestForOldSnapshot(scan->rs_snapshot, rel, BufferGetPage(buf));
99-
100-
/*
101-
* We always maintain the pin on bucket page for whole scan
102-
* operation, so releasing the additional pin we have acquired
103-
* here.
104-
*/
105-
if (buf == so->hashso_bucket_buf ||
106-
buf == so->hashso_split_bucket_buf)
107-
_hash_dropbuf(rel, buf);
108-
109-
if (!vertex_hash_readpage(scan, &buf, dir))
110-
end_of_scan = true;
111-
}
112-
else
113-
end_of_scan = true;
114-
}
115-
}
116-
117-
if (end_of_scan)
118-
{
119-
//_hash_dropscanbuf(rel,( TableScanDesc)so); TODO
120-
HashScanPosInvalidate(so->currPos);
121-
return false;
122-
}
123-
124-
/* OK, itemIndex says what to return */
125-
currItem = &so->currPos.items[so->currPos.itemIndex];
126-
//scan->xs_heaptid = currItem->heapTid;
127-
128-
return true;
129-
}
130-
13137
/*
13238
* Advance to next page in a bucket, if any. If we are scanning the bucket
13339
* being populated during split operation then this function advances to the

0 commit comments

Comments
 (0)