49
49
#include "utils/builtins.h"
50
50
#include "utils/rel.h"
51
51
52
+ #include "utils/graphid.h"
53
+ #include "utils/gtype.h"
54
+
52
55
#define HEAP_OVERHEAD_BYTES_PER_TUPLE \
53
56
(MAXALIGN(SizeofHeapTupleHeader) + sizeof(ItemIdData))
54
57
#define HEAP_USABLE_BYTES_PER_PAGE \
@@ -61,8 +64,16 @@ static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
61
64
static MultiXactStatus
62
65
get_mxact_status_for_lock (LockTupleMode mode , bool is_update );
63
66
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
+
66
77
67
78
/*
68
79
* * Given infomask/infomask2, compute the bits that must be saved in the
@@ -75,69 +86,67 @@ static uint8
75
86
compute_infobits (uint16 infomask , uint16 infomask2 )
76
87
{
77
88
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 );
85
96
}
86
97
87
-
88
98
/*
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
+ */
98
108
static TransactionId
99
109
MultiXactIdGetUpdateXid (TransactionId xmax , uint16 t_infomask )
100
110
{
101
- TransactionId update_xact = InvalidTransactionId ;
102
- MultiXactMember * members ;
103
- int nmembers ;
111
+ TransactionId update_xact = InvalidTransactionId ;
112
+ MultiXactMember * members ;
113
+ int nmembers ;
104
114
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 );
107
117
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);
113
123
114
- if (nmembers > 0 )
115
- {
116
- int i ;
124
+ if (nmembers > 0 )
125
+ {
126
+ int i ;
117
127
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 ;
123
133
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 ;
127
137
#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 ;
134
143
#endif
135
- }
144
+ }
136
145
137
- pfree (members );
138
- }
146
+ pfree (members );
147
+ }
139
148
140
- return update_xact ;
149
+ return update_xact ;
141
150
}
142
151
143
152
@@ -2019,7 +2028,7 @@ void vertex_index_fetch_end(struct IndexFetchTableData *data) {
2019
2028
*
2020
2029
* *all_dead, if all_dead is not NULL, should be set to true by
2021
2030
* 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
2023
2032
* future searches.
2024
2033
*/
2025
2034
bool vertex_index_fetch_tuple (struct IndexFetchTableData * scan ,
@@ -2034,7 +2043,7 @@ bool vertex_index_fetch_tuple(struct IndexFetchTableData *scan,
2034
2043
}
2035
2044
2036
2045
2037
- /* ------------------------------------------------------------------------
2046
+ /* -----------------------------------------------------------------------
2038
2047
* Callbacks for non-modifying operations on individual tuples
2039
2048
* ------------------------------------------------------------------------
2040
2049
*/
@@ -2124,6 +2133,29 @@ void vertex_tuple_insert(Relation relation, TupleTableSlot *slot,
2124
2133
slot -> tts_tableOid = RelationGetRelid (relation );
2125
2134
tuple -> t_tableOid = slot -> tts_tableOid ;
2126
2135
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
+
2127
2159
/* Perform the insertion, and copy the resulting ItemPointer */
2128
2160
heap_insert (relation , tuple , cid , options , bistate );
2129
2161
ItemPointerCopy (& tuple -> t_self , & slot -> tts_tid );
@@ -2678,6 +2710,15 @@ void vertex_relation_set_new_filenode(Relation rel, const RelFileNode *newrnode,
2678
2710
srel = RelationCreateStorage (* newrnode , persistence );
2679
2711
2680
2712
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
+
2681
2722
}
2682
2723
2683
2724
/*
0 commit comments