Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "postgres.h"
00043
00044 #include "access/htup_details.h"
00045 #include "access/xact.h"
00046 #include "utils/combocid.h"
00047 #include "utils/hsearch.h"
00048 #include "utils/memutils.h"
00049
00050
00051
00052 static HTAB *comboHash = NULL;
00053
00054
00055 typedef struct
00056 {
00057 CommandId cmin;
00058 CommandId cmax;
00059 } ComboCidKeyData;
00060
00061 typedef ComboCidKeyData *ComboCidKey;
00062
00063 typedef struct
00064 {
00065 ComboCidKeyData key;
00066 CommandId combocid;
00067 } ComboCidEntryData;
00068
00069 typedef ComboCidEntryData *ComboCidEntry;
00070
00071
00072 #define CCID_HASH_SIZE 100
00073
00074
00075
00076
00077
00078
00079 static ComboCidKey comboCids = NULL;
00080 static int usedComboCids = 0;
00081 static int sizeComboCids = 0;
00082
00083
00084 #define CCID_ARRAY_SIZE 100
00085
00086
00087
00088 static CommandId GetComboCommandId(CommandId cmin, CommandId cmax);
00089 static CommandId GetRealCmin(CommandId combocid);
00090 static CommandId GetRealCmax(CommandId combocid);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 CommandId
00103 HeapTupleHeaderGetCmin(HeapTupleHeader tup)
00104 {
00105 CommandId cid = HeapTupleHeaderGetRawCommandId(tup);
00106
00107 Assert(!(tup->t_infomask & HEAP_MOVED));
00108 Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup)));
00109
00110 if (tup->t_infomask & HEAP_COMBOCID)
00111 return GetRealCmin(cid);
00112 else
00113 return cid;
00114 }
00115
00116 CommandId
00117 HeapTupleHeaderGetCmax(HeapTupleHeader tup)
00118 {
00119 CommandId cid = HeapTupleHeaderGetRawCommandId(tup);
00120
00121 Assert(!(tup->t_infomask & HEAP_MOVED));
00122 Assert(TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetUpdateXid(tup)));
00123
00124 if (tup->t_infomask & HEAP_COMBOCID)
00125 return GetRealCmax(cid);
00126 else
00127 return cid;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 void
00144 HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
00145 CommandId *cmax,
00146 bool *iscombo)
00147 {
00148
00149
00150
00151
00152
00153
00154 if (!(tup->t_infomask & HEAP_XMIN_COMMITTED) &&
00155 TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tup)))
00156 {
00157 CommandId cmin = HeapTupleHeaderGetCmin(tup);
00158
00159 *cmax = GetComboCommandId(cmin, *cmax);
00160 *iscombo = true;
00161 }
00162 else
00163 {
00164 *iscombo = false;
00165 }
00166 }
00167
00168
00169
00170
00171
00172 void
00173 AtEOXact_ComboCid(void)
00174 {
00175
00176
00177
00178
00179 comboHash = NULL;
00180
00181 comboCids = NULL;
00182 usedComboCids = 0;
00183 sizeComboCids = 0;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 static CommandId
00195 GetComboCommandId(CommandId cmin, CommandId cmax)
00196 {
00197 CommandId combocid;
00198 ComboCidKeyData key;
00199 ComboCidEntry entry;
00200 bool found;
00201
00202
00203
00204
00205
00206 if (comboHash == NULL)
00207 {
00208 HASHCTL hash_ctl;
00209
00210 memset(&hash_ctl, 0, sizeof(hash_ctl));
00211 hash_ctl.keysize = sizeof(ComboCidKeyData);
00212 hash_ctl.entrysize = sizeof(ComboCidEntryData);
00213 hash_ctl.hash = tag_hash;
00214 hash_ctl.hcxt = TopTransactionContext;
00215
00216 comboHash = hash_create("Combo CIDs",
00217 CCID_HASH_SIZE,
00218 &hash_ctl,
00219 HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
00220
00221 comboCids = (ComboCidKeyData *)
00222 MemoryContextAlloc(TopTransactionContext,
00223 sizeof(ComboCidKeyData) * CCID_ARRAY_SIZE);
00224 sizeComboCids = CCID_ARRAY_SIZE;
00225 usedComboCids = 0;
00226 }
00227
00228
00229
00230
00231 key.cmin = cmin;
00232 key.cmax = cmax;
00233 entry = (ComboCidEntry) hash_search(comboHash,
00234 (void *) &key,
00235 HASH_ENTER,
00236 &found);
00237
00238 if (found)
00239 {
00240
00241 return entry->combocid;
00242 }
00243
00244
00245
00246
00247
00248 if (usedComboCids >= sizeComboCids)
00249 {
00250
00251 int newsize = sizeComboCids * 2;
00252
00253 comboCids = (ComboCidKeyData *)
00254 repalloc(comboCids, sizeof(ComboCidKeyData) * newsize);
00255 sizeComboCids = newsize;
00256 }
00257
00258 combocid = usedComboCids;
00259
00260 comboCids[combocid].cmin = cmin;
00261 comboCids[combocid].cmax = cmax;
00262 usedComboCids++;
00263
00264 entry->combocid = combocid;
00265
00266 return combocid;
00267 }
00268
00269 static CommandId
00270 GetRealCmin(CommandId combocid)
00271 {
00272 Assert(combocid < usedComboCids);
00273 return comboCids[combocid].cmin;
00274 }
00275
00276 static CommandId
00277 GetRealCmax(CommandId combocid)
00278 {
00279 Assert(combocid < usedComboCids);
00280 return comboCids[combocid].cmax;
00281 }