Skip to content

Commit e8cca63

Browse files
committed
Shove a shared memory hash table in for the relation
put the ids in there for tuples
1 parent d90068d commit e8cca63

File tree

2 files changed

+94
-53
lines changed

2 files changed

+94
-53
lines changed

regress/sql/vertex_am.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SELECT * FROM vertex_am_tst;
3131
DELETE FROM vertex_am_tst;
3232

3333
INSERT INTO vertex_am_tst (id, props)
34-
VALUES ('1'::postgraph.graphid, postgraph.gtype_build_map('id', 1));
34+
VALUES ('2'::postgraph.graphid, postgraph.gtype_build_map('id', 1));
3535

3636

3737
SELECT * FROM vertex_am_tst;

src/backend/access/vertex_heap/vertex_heapam_handler.c

Lines changed: 93 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#include "utils/builtins.h"
5050
#include "utils/rel.h"
5151

52+
#include "utils/graphid.h"
53+
#include "utils/gtype.h"
54+
5255
#define HEAP_OVERHEAD_BYTES_PER_TUPLE \
5356
(MAXALIGN(SizeofHeapTupleHeader) + sizeof(ItemIdData))
5457
#define HEAP_USABLE_BYTES_PER_PAGE \
@@ -61,8 +64,16 @@ static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
6164
static MultiXactStatus
6265
get_mxact_status_for_lock(LockTupleMode mode, bool is_update);
6366
static bool heap_acquire_tuplock(Relation relation, ItemPointer tid,
64-
LockTupleMode mode, LockWaitPolicy wait_policy,
65-
bool *have_tuple_lock);
67+
LockTupleMode mode, LockWaitPolicy wait_policy,
68+
bool *have_tuple_lock);
69+
70+
typedef struct vertex_hash_struct
71+
{
72+
graphid id; // hash key
73+
gtype *properties;
74+
} vertex_hash_struct;
75+
76+
6677

6778
/*
6879
* * Given infomask/infomask2, compute the bits that must be saved in the
@@ -75,69 +86,67 @@ static uint8
7586
compute_infobits(uint16 infomask, uint16 infomask2)
7687
{
7788
return
78-
((infomask & HEAP_XMAX_IS_MULTI) != 0 ? XLHL_XMAX_IS_MULTI : 0) |
79-
((infomask & HEAP_XMAX_LOCK_ONLY) != 0 ? XLHL_XMAX_LOCK_ONLY : 0) |
80-
((infomask & HEAP_XMAX_EXCL_LOCK) != 0 ? XLHL_XMAX_EXCL_LOCK : 0) |
81-
/* note we ignore HEAP_XMAX_SHR_LOCK here */
82-
((infomask & HEAP_XMAX_KEYSHR_LOCK) != 0 ? XLHL_XMAX_KEYSHR_LOCK : 0) |
83-
((infomask2 & HEAP_KEYS_UPDATED) != 0 ?
84-
XLHL_KEYS_UPDATED : 0);
89+
((infomask & HEAP_XMAX_IS_MULTI) != 0 ? XLHL_XMAX_IS_MULTI : 0) |
90+
((infomask & HEAP_XMAX_LOCK_ONLY) != 0 ? XLHL_XMAX_LOCK_ONLY : 0) |
91+
((infomask & HEAP_XMAX_EXCL_LOCK) != 0 ? XLHL_XMAX_EXCL_LOCK : 0) |
92+
/* note we ignore HEAP_XMAX_SHR_LOCK here */
93+
((infomask & HEAP_XMAX_KEYSHR_LOCK) != 0 ? XLHL_XMAX_KEYSHR_LOCK : 0) |
94+
((infomask2 & HEAP_KEYS_UPDATED) != 0 ?
95+
XLHL_KEYS_UPDATED : 0);
8596
}
8697

87-
8898
/*
89-
* * MultiXactIdGetUpdateXid
90-
* *
91-
* * Given a multixact Xmax and corresponding infomask, which does not have the
92-
* * HEAP_XMAX_LOCK_ONLY bit set, obtain and return the Xid of the updating
93-
* * transaction.
94-
* *
95-
* * Caller is expected to check the status of the updating transaction, if
96-
* * necessary.
97-
* */
99+
* MultiXactIdGetUpdateXid
100+
*
101+
* Given a multixact Xmax and corresponding infomask, which does not have the
102+
* HEAP_XMAX_LOCK_ONLY bit set, obtain and return the Xid of the updating
103+
* transaction.
104+
*
105+
* Caller is expected to check the status of the updating transaction, if
106+
* necessary.
107+
*/
98108
static TransactionId
99109
MultiXactIdGetUpdateXid(TransactionId xmax, uint16 t_infomask)
100110
{
101-
TransactionId update_xact = InvalidTransactionId;
102-
MultiXactMember *members;
103-
int nmembers;
111+
TransactionId update_xact = InvalidTransactionId;
112+
MultiXactMember *members;
113+
int nmembers;
104114

105-
Assert(!(t_infomask & HEAP_XMAX_LOCK_ONLY));
106-
Assert(t_infomask & HEAP_XMAX_IS_MULTI);
115+
Assert(!(t_infomask & HEAP_XMAX_LOCK_ONLY));
116+
Assert(t_infomask & HEAP_XMAX_IS_MULTI);
107117

108-
/*
109-
* * Since we know the LOCK_ONLY bit is not set, this cannot be a multi from
110-
* * pre-pg_upgrade.
111-
* */
112-
nmembers = GetMultiXactIdMembers(xmax, &members, false, false);
118+
/*
119+
* Since we know the LOCK_ONLY bit is not set, this cannot be a multi from
120+
* pre-pg_upgrade.
121+
*/
122+
nmembers = GetMultiXactIdMembers(xmax, &members, false, false);
113123

114-
if (nmembers > 0)
115-
{
116-
int i;
124+
if (nmembers > 0)
125+
{
126+
int i;
117127

118-
for (i = 0; i < nmembers; i++)
119-
{
120-
/* Ignore lockers */
121-
if (!ISUPDATE_from_mxstatus(members[i].status))
122-
continue;
128+
for (i = 0; i < nmembers; i++)
129+
{
130+
/* Ignore lockers */
131+
if (!ISUPDATE_from_mxstatus(members[i].status))
132+
continue;
123133

124-
/* there can be at most one updater */
125-
Assert(update_xact == InvalidTransactionId);
126-
update_xact = members[i].xid;
134+
/* there can be at most one updater */
135+
Assert(update_xact == InvalidTransactionId);
136+
update_xact = members[i].xid;
127137
#ifndef USE_ASSERT_CHECKING
128-
129-
/*
130-
* * in an assert-enabled build, walk the whole array to ensure
131-
* * there's no other updater.
132-
* */
133-
break;
138+
/*
139+
* in an assert-enabled build, walk the whole array to ensure
140+
* there's no other updater.
141+
*/
142+
break;
134143
#endif
135-
}
144+
}
136145

137-
pfree(members);
138-
}
146+
pfree(members);
147+
}
139148

140-
return update_xact;
149+
return update_xact;
141150
}
142151

143152

@@ -2019,7 +2028,7 @@ void vertex_index_fetch_end(struct IndexFetchTableData *data) {
20192028
*
20202029
* *all_dead, if all_dead is not NULL, should be set to true by
20212030
* index_fetch_tuple iff it is guaranteed that no backend needs to see
2022-
* that tuple. Index AMs can use that to avoid returning that tid in
2031+
* that tuple. Index AMs can use that to av-oid returning that tid in
20232032
* future searches.
20242033
*/
20252034
bool vertex_index_fetch_tuple(struct IndexFetchTableData *scan,
@@ -2034,7 +2043,7 @@ bool vertex_index_fetch_tuple(struct IndexFetchTableData *scan,
20342043
}
20352044

20362045

2037-
/* ------------------------------------------------------------------------
2046+
/* -----------------------------------------------------------------------
20382047
* Callbacks for non-modifying operations on individual tuples
20392048
* ------------------------------------------------------------------------
20402049
*/
@@ -2124,6 +2133,29 @@ void vertex_tuple_insert(Relation relation, TupleTableSlot *slot,
21242133
slot->tts_tableOid = RelationGetRelid(relation);
21252134
tuple->t_tableOid = slot->tts_tableOid;
21262135

2136+
2137+
graphid id = DATUM_GET_GRAPHID(slot->tts_values[0]);
2138+
gtype *properties = DATUM_GET_GTYPE_P(slot->tts_values[1]);
2139+
2140+
2141+
2142+
gtype *shmem_properties = ShmemAlloc(VARSIZE(properties));
2143+
memcpy(shmem_properties, properties, VARSIZE(properties));
2144+
vertex_hash_struct *ctl = ShmemAlloc(sizeof(vertex_hash_struct));
2145+
ctl->id = id,
2146+
ctl->properties = shmem_properties;
2147+
2148+
HASHCTL hash_ctl;
2149+
2150+
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
2151+
hash_ctl.keysize = sizeof(graphid);
2152+
hash_ctl.entrysize = sizeof(vertex_hash_struct);
2153+
2154+
HTAB *rel_hash_table = ShmemInitHash(RelationGetRelationName(relation),16, 1000, &hash_ctl,
2155+
HASH_ELEM | HASH_BLOBS | HASH_COMPARE);
2156+
bool found;
2157+
hash_search(rel_hash_table, ctl, HASH_ENTER, &found);
2158+
21272159
/* Perform the insertion, and copy the resulting ItemPointer */
21282160
heap_insert(relation, tuple, cid, options, bistate);
21292161
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
@@ -2678,6 +2710,15 @@ void vertex_relation_set_new_filenode(Relation rel, const RelFileNode *newrnode,
26782710
srel = RelationCreateStorage(*newrnode, persistence);
26792711

26802712
smgrclose(srel);
2713+
HASHCTL hash_ctl;
2714+
2715+
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
2716+
hash_ctl.keysize = sizeof(graphid);
2717+
hash_ctl.entrysize = sizeof(vertex_hash_struct);
2718+
2719+
HTAB *rel_hash_table = ShmemInitHash(RelationGetRelationName(rel),16, 1000, &hash_ctl,
2720+
HASH_ELEM | HASH_BLOBS | HASH_COMPARE);
2721+
26812722
}
26822723

26832724
/*

0 commit comments

Comments
 (0)