Skip to content

Commit 9e0b523

Browse files
committed
Scan from the Hash Table
1 parent e8cca63 commit 9e0b523

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

regress/sql/vertex_am.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ SELECT * FROM vertex_am_tst;
3838

3939
UPDATE vertex_am_tst SET id = '2'::postgraph.graphid;
4040

41+
INSERT INTO vertex_am_tst (id, props)
42+
VALUES ('4'::postgraph.graphid, postgraph.gtype_build_map('id', 1));
4143

4244
SELECT * FROM vertex_am_tst;

src/backend/access/vertex_heap/vertex_heapam_handler.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ typedef struct vertex_hash_struct
7474
} vertex_hash_struct;
7575

7676

77-
77+
static vertex_hash_struct *iterator = NULL;
78+
static HTAB *vertex_hash = NULL;
79+
static HASH_SEQ_STATUS scanStatus;
80+
//BlackPink
7881
/*
7982
* * Given infomask/infomask2, compute the bits that must be saved in the
8083
* * "infobits" field of xl_heap_delete, xl_heap_update, xl_heap_lock,
@@ -1773,6 +1776,7 @@ vertex_heapam_slot_callbacks(Relation relation)
17731776
return &TTSOpsBufferHeapTuple;
17741777
}
17751778

1779+
17761780
/* ------------------------------------------------------------------------
17771781
* Functions related to scaning
17781782
* ------------------------------------------------------------------------
@@ -1789,6 +1793,16 @@ TableScanDesc vertex_scan_begin(Relation relation, Snapshot snapshot, int nkeys,
17891793
* the scan has a pointer to it. Caller should be holding the rel open
17901794
* anyway, so this is redundant in all normal scenarios...
17911795
*/
1796+
HASHCTL hash_ctl;
1797+
//BlackPink
1798+
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
1799+
hash_ctl.keysize = sizeof(graphid);
1800+
hash_ctl.entrysize = sizeof(vertex_hash_struct);
1801+
vertex_hash = ShmemInitHash(RelationGetRelationName(relation),16, 1000, &hash_ctl,
1802+
HASH_ELEM | HASH_BLOBS | HASH_COMPARE);
1803+
hash_seq_init(&scanStatus, vertex_hash);
1804+
1805+
17921806
RelationIncrementReferenceCount(relation);
17931807

17941808
/*
@@ -1864,7 +1878,8 @@ void vertex_scan_end(TableScanDesc sscan) {
18641878
HeapScanDesc scan = (HeapScanDesc) sscan;
18651879

18661880
/* Note: no locking manipulations needed */
1867-
1881+
hash_seq_term(&scanStatus);
1882+
//BlackPink
18681883
/*
18691884
* unpin scan buffers
18701885
*/
@@ -1928,6 +1943,17 @@ bool vertex_scan_getnextslot(TableScanDesc sscan, ScanDirection direction,
19281943
pgstat_count_heap_getnext(scan->rs_base.rs_rd);
19291944

19301945
ExecStoreBufferHeapTuple(&scan->rs_ctup, slot, scan->rs_cbuf);
1946+
1947+
//BlackPink
1948+
if ((iterator = hash_seq_search(&scanStatus)) != NULL) {
1949+
slot->tts_values[0] = GRAPHID_GET_DATUM(iterator->id);
1950+
slot->tts_values[1] = GTYPE_P_GET_DATUM(iterator->properties);
1951+
} else {
1952+
return false;
1953+
}
1954+
1955+
1956+
19311957
return true;
19321958
}
19331959

@@ -2150,7 +2176,7 @@ void vertex_tuple_insert(Relation relation, TupleTableSlot *slot,
21502176
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
21512177
hash_ctl.keysize = sizeof(graphid);
21522178
hash_ctl.entrysize = sizeof(vertex_hash_struct);
2153-
2179+
//BlackPink
21542180
HTAB *rel_hash_table = ShmemInitHash(RelationGetRelationName(relation),16, 1000, &hash_ctl,
21552181
HASH_ELEM | HASH_BLOBS | HASH_COMPARE);
21562182
bool found;

0 commit comments

Comments
 (0)