00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef HTUP_DETAILS_H
00015 #define HTUP_DETAILS_H
00016
00017 #include "access/htup.h"
00018 #include "access/tupdesc.h"
00019 #include "access/tupmacs.h"
00020 #include "storage/bufpage.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #define MaxTupleAttributeNumber 1664
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #define MaxHeapAttributeNumber 1600
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 typedef struct HeapTupleFields
00107 {
00108 TransactionId t_xmin;
00109 TransactionId t_xmax;
00110
00111 union
00112 {
00113 CommandId t_cid;
00114 TransactionId t_xvac;
00115 } t_field3;
00116 } HeapTupleFields;
00117
00118 typedef struct DatumTupleFields
00119 {
00120 int32 datum_len_;
00121
00122 int32 datum_typmod;
00123
00124 Oid datum_typeid;
00125
00126
00127
00128
00129
00130 } DatumTupleFields;
00131
00132 struct HeapTupleHeaderData
00133 {
00134 union
00135 {
00136 HeapTupleFields t_heap;
00137 DatumTupleFields t_datum;
00138 } t_choice;
00139
00140 ItemPointerData t_ctid;
00141
00142
00143
00144 uint16 t_infomask2;
00145
00146 uint16 t_infomask;
00147
00148 uint8 t_hoff;
00149
00150
00151
00152 bits8 t_bits[1];
00153
00154
00155 };
00156
00157
00158
00159
00160
00161 #define HEAP_HASNULL 0x0001
00162 #define HEAP_HASVARWIDTH 0x0002
00163 #define HEAP_HASEXTERNAL 0x0004
00164 #define HEAP_HASOID 0x0008
00165 #define HEAP_XMAX_KEYSHR_LOCK 0x0010
00166 #define HEAP_COMBOCID 0x0020
00167 #define HEAP_XMAX_EXCL_LOCK 0x0040
00168 #define HEAP_XMAX_LOCK_ONLY 0x0080
00169
00170
00171 #define HEAP_XMAX_SHR_LOCK (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
00172
00173 #define HEAP_LOCK_MASK (HEAP_XMAX_SHR_LOCK | HEAP_XMAX_EXCL_LOCK | \
00174 HEAP_XMAX_KEYSHR_LOCK)
00175 #define HEAP_XMIN_COMMITTED 0x0100
00176 #define HEAP_XMIN_INVALID 0x0200
00177 #define HEAP_XMAX_COMMITTED 0x0400
00178 #define HEAP_XMAX_INVALID 0x0800
00179 #define HEAP_XMAX_IS_MULTI 0x1000
00180 #define HEAP_UPDATED 0x2000
00181 #define HEAP_MOVED_OFF 0x4000
00182
00183
00184 #define HEAP_MOVED_IN 0x8000
00185
00186
00187 #define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)
00188
00189 #define HEAP_XACT_MASK 0xFFF0
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 #define HEAP_XMAX_IS_LOCKED_ONLY(infomask) \
00202 (((infomask) & HEAP_XMAX_LOCK_ONLY) || \
00203 (((infomask) & (HEAP_XMAX_IS_MULTI | HEAP_LOCK_MASK)) == HEAP_XMAX_EXCL_LOCK))
00204
00205
00206
00207
00208 #define HEAP_XMAX_IS_SHR_LOCKED(infomask) \
00209 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK)
00210 #define HEAP_XMAX_IS_EXCL_LOCKED(infomask) \
00211 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK)
00212 #define HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) \
00213 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK)
00214
00215
00216 #define HEAP_XMAX_BITS (HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID | \
00217 HEAP_XMAX_IS_MULTI | HEAP_LOCK_MASK | HEAP_XMAX_LOCK_ONLY)
00218
00219
00220
00221
00222 #define HEAP_NATTS_MASK 0x07FF
00223
00224 #define HEAP_KEYS_UPDATED 0x2000
00225
00226 #define HEAP_HOT_UPDATED 0x4000
00227 #define HEAP_ONLY_TUPLE 0x8000
00228
00229 #define HEAP2_XACT_MASK 0xE000
00230
00231
00232
00233
00234
00235
00236
00237 #define HEAP_TUPLE_HAS_MATCH HEAP_ONLY_TUPLE
00238
00239
00240
00241
00242
00243
00244
00245
00246 #define HeapTupleHeaderGetXmin(tup) \
00247 ( \
00248 (tup)->t_choice.t_heap.t_xmin \
00249 )
00250
00251 #define HeapTupleHeaderSetXmin(tup, xid) \
00252 ( \
00253 (tup)->t_choice.t_heap.t_xmin = (xid) \
00254 )
00255
00256
00257
00258
00259
00260
00261
00262
00263 #define HeapTupleHeaderGetUpdateXid(tup) \
00264 ( \
00265 (!((tup)->t_infomask & HEAP_XMAX_INVALID) && \
00266 ((tup)->t_infomask & HEAP_XMAX_IS_MULTI) && \
00267 !((tup)->t_infomask & HEAP_XMAX_LOCK_ONLY)) ? \
00268 HeapTupleGetUpdateXid(tup) \
00269 : \
00270 HeapTupleHeaderGetRawXmax(tup) \
00271 )
00272
00273 #define HeapTupleHeaderGetRawXmax(tup) \
00274 ( \
00275 (tup)->t_choice.t_heap.t_xmax \
00276 )
00277
00278 #define HeapTupleHeaderSetXmax(tup, xid) \
00279 ( \
00280 (tup)->t_choice.t_heap.t_xmax = (xid) \
00281 )
00282
00283
00284
00285
00286
00287
00288
00289 #define HeapTupleHeaderGetRawCommandId(tup) \
00290 ( \
00291 (tup)->t_choice.t_heap.t_field3.t_cid \
00292 )
00293
00294
00295 #define HeapTupleHeaderSetCmin(tup, cid) \
00296 do { \
00297 Assert(!((tup)->t_infomask & HEAP_MOVED)); \
00298 (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \
00299 (tup)->t_infomask &= ~HEAP_COMBOCID; \
00300 } while (0)
00301
00302
00303 #define HeapTupleHeaderSetCmax(tup, cid, iscombo) \
00304 do { \
00305 Assert(!((tup)->t_infomask & HEAP_MOVED)); \
00306 (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \
00307 if (iscombo) \
00308 (tup)->t_infomask |= HEAP_COMBOCID; \
00309 else \
00310 (tup)->t_infomask &= ~HEAP_COMBOCID; \
00311 } while (0)
00312
00313 #define HeapTupleHeaderGetXvac(tup) \
00314 ( \
00315 ((tup)->t_infomask & HEAP_MOVED) ? \
00316 (tup)->t_choice.t_heap.t_field3.t_xvac \
00317 : \
00318 InvalidTransactionId \
00319 )
00320
00321 #define HeapTupleHeaderSetXvac(tup, xid) \
00322 do { \
00323 Assert((tup)->t_infomask & HEAP_MOVED); \
00324 (tup)->t_choice.t_heap.t_field3.t_xvac = (xid); \
00325 } while (0)
00326
00327 #define HeapTupleHeaderGetDatumLength(tup) \
00328 VARSIZE(tup)
00329
00330 #define HeapTupleHeaderSetDatumLength(tup, len) \
00331 SET_VARSIZE(tup, len)
00332
00333 #define HeapTupleHeaderGetTypeId(tup) \
00334 ( \
00335 (tup)->t_choice.t_datum.datum_typeid \
00336 )
00337
00338 #define HeapTupleHeaderSetTypeId(tup, typeid) \
00339 ( \
00340 (tup)->t_choice.t_datum.datum_typeid = (typeid) \
00341 )
00342
00343 #define HeapTupleHeaderGetTypMod(tup) \
00344 ( \
00345 (tup)->t_choice.t_datum.datum_typmod \
00346 )
00347
00348 #define HeapTupleHeaderSetTypMod(tup, typmod) \
00349 ( \
00350 (tup)->t_choice.t_datum.datum_typmod = (typmod) \
00351 )
00352
00353 #define HeapTupleHeaderGetOid(tup) \
00354 ( \
00355 ((tup)->t_infomask & HEAP_HASOID) ? \
00356 *((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \
00357 : \
00358 InvalidOid \
00359 )
00360
00361 #define HeapTupleHeaderSetOid(tup, oid) \
00362 do { \
00363 Assert((tup)->t_infomask & HEAP_HASOID); \
00364 *((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid); \
00365 } while (0)
00366
00367
00368
00369
00370
00371
00372
00373 #define HeapTupleHeaderIsHotUpdated(tup) \
00374 ( \
00375 ((tup)->t_infomask2 & HEAP_HOT_UPDATED) != 0 && \
00376 ((tup)->t_infomask & (HEAP_XMIN_INVALID | HEAP_XMAX_INVALID)) == 0 \
00377 )
00378
00379 #define HeapTupleHeaderSetHotUpdated(tup) \
00380 ( \
00381 (tup)->t_infomask2 |= HEAP_HOT_UPDATED \
00382 )
00383
00384 #define HeapTupleHeaderClearHotUpdated(tup) \
00385 ( \
00386 (tup)->t_infomask2 &= ~HEAP_HOT_UPDATED \
00387 )
00388
00389 #define HeapTupleHeaderIsHeapOnly(tup) \
00390 ( \
00391 (tup)->t_infomask2 & HEAP_ONLY_TUPLE \
00392 )
00393
00394 #define HeapTupleHeaderSetHeapOnly(tup) \
00395 ( \
00396 (tup)->t_infomask2 |= HEAP_ONLY_TUPLE \
00397 )
00398
00399 #define HeapTupleHeaderClearHeapOnly(tup) \
00400 ( \
00401 (tup)->t_infomask2 &= ~HEAP_ONLY_TUPLE \
00402 )
00403
00404 #define HeapTupleHeaderHasMatch(tup) \
00405 ( \
00406 (tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH \
00407 )
00408
00409 #define HeapTupleHeaderSetMatch(tup) \
00410 ( \
00411 (tup)->t_infomask2 |= HEAP_TUPLE_HAS_MATCH \
00412 )
00413
00414 #define HeapTupleHeaderClearMatch(tup) \
00415 ( \
00416 (tup)->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH \
00417 )
00418
00419 #define HeapTupleHeaderGetNatts(tup) \
00420 ((tup)->t_infomask2 & HEAP_NATTS_MASK)
00421
00422 #define HeapTupleHeaderSetNatts(tup, natts) \
00423 ( \
00424 (tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \
00425 )
00426
00427
00428
00429
00430
00431
00432 #define BITMAPLEN(NATTS) (((int)(NATTS) + 7) / 8)
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 #define MaxHeapTupleSize (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData)))
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 #define MaxHeapTuplesPerPage \
00459 ((int) ((BLCKSZ - SizeOfPageHeaderData) / \
00460 (MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData))))
00461
00462
00463
00464
00465
00466
00467
00468
00469 #define MaxAttrSize (10 * 1024 * 1024)
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 #define MINIMAL_TUPLE_OFFSET \
00504 ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
00505 #define MINIMAL_TUPLE_PADDING \
00506 ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
00507 #define MINIMAL_TUPLE_DATA_OFFSET \
00508 offsetof(MinimalTupleData, t_infomask2)
00509
00510 struct MinimalTupleData
00511 {
00512 uint32 t_len;
00513
00514 char mt_padding[MINIMAL_TUPLE_PADDING];
00515
00516
00517
00518 uint16 t_infomask2;
00519
00520 uint16 t_infomask;
00521
00522 uint8 t_hoff;
00523
00524
00525
00526 bits8 t_bits[1];
00527
00528
00529 };
00530
00531
00532
00533
00534
00535
00536 #define GETSTRUCT(TUP) ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff)
00537
00538
00539
00540
00541
00542 #define HeapTupleHasNulls(tuple) \
00543 (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
00544
00545 #define HeapTupleNoNulls(tuple) \
00546 (!((tuple)->t_data->t_infomask & HEAP_HASNULL))
00547
00548 #define HeapTupleHasVarWidth(tuple) \
00549 (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)
00550
00551 #define HeapTupleAllFixed(tuple) \
00552 (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))
00553
00554 #define HeapTupleHasExternal(tuple) \
00555 (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
00556
00557 #define HeapTupleIsHotUpdated(tuple) \
00558 HeapTupleHeaderIsHotUpdated((tuple)->t_data)
00559
00560 #define HeapTupleSetHotUpdated(tuple) \
00561 HeapTupleHeaderSetHotUpdated((tuple)->t_data)
00562
00563 #define HeapTupleClearHotUpdated(tuple) \
00564 HeapTupleHeaderClearHotUpdated((tuple)->t_data)
00565
00566 #define HeapTupleIsHeapOnly(tuple) \
00567 HeapTupleHeaderIsHeapOnly((tuple)->t_data)
00568
00569 #define HeapTupleSetHeapOnly(tuple) \
00570 HeapTupleHeaderSetHeapOnly((tuple)->t_data)
00571
00572 #define HeapTupleClearHeapOnly(tuple) \
00573 HeapTupleHeaderClearHeapOnly((tuple)->t_data)
00574
00575 #define HeapTupleGetOid(tuple) \
00576 HeapTupleHeaderGetOid((tuple)->t_data)
00577
00578 #define HeapTupleSetOid(tuple, oid) \
00579 HeapTupleHeaderSetOid((tuple)->t_data, (oid))
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 #if !defined(DISABLE_COMPLEX_MACRO)
00598
00599 #define fastgetattr(tup, attnum, tupleDesc, isnull) \
00600 ( \
00601 AssertMacro((attnum) > 0), \
00602 (*(isnull) = false), \
00603 HeapTupleNoNulls(tup) ? \
00604 ( \
00605 (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
00606 ( \
00607 fetchatt((tupleDesc)->attrs[(attnum)-1], \
00608 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \
00609 (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
00610 ) \
00611 : \
00612 nocachegetattr((tup), (attnum), (tupleDesc)) \
00613 ) \
00614 : \
00615 ( \
00616 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \
00617 ( \
00618 (*(isnull) = true), \
00619 (Datum)NULL \
00620 ) \
00621 : \
00622 ( \
00623 nocachegetattr((tup), (attnum), (tupleDesc)) \
00624 ) \
00625 ) \
00626 )
00627 #else
00628
00629 extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
00630 bool *isnull);
00631 #endif
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649 #define heap_getattr(tup, attnum, tupleDesc, isnull) \
00650 ( \
00651 ((attnum) > 0) ? \
00652 ( \
00653 ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \
00654 ( \
00655 (*(isnull) = true), \
00656 (Datum)NULL \
00657 ) \
00658 : \
00659 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \
00660 ) \
00661 : \
00662 heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \
00663 )
00664
00665
00666
00667 extern Size heap_compute_data_size(TupleDesc tupleDesc,
00668 Datum *values, bool *isnull);
00669 extern void heap_fill_tuple(TupleDesc tupleDesc,
00670 Datum *values, bool *isnull,
00671 char *data, Size data_size,
00672 uint16 *infomask, bits8 *bit);
00673 extern bool heap_attisnull(HeapTuple tup, int attnum);
00674 extern Datum nocachegetattr(HeapTuple tup, int attnum,
00675 TupleDesc att);
00676 extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
00677 bool *isnull);
00678 extern HeapTuple heap_copytuple(HeapTuple tuple);
00679 extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest);
00680 extern HeapTuple heap_form_tuple(TupleDesc tupleDescriptor,
00681 Datum *values, bool *isnull);
00682 extern HeapTuple heap_modify_tuple(HeapTuple tuple,
00683 TupleDesc tupleDesc,
00684 Datum *replValues,
00685 bool *replIsnull,
00686 bool *doReplace);
00687 extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
00688 Datum *values, bool *isnull);
00689
00690
00691 extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor,
00692 Datum *values, char *nulls);
00693 extern HeapTuple heap_modifytuple(HeapTuple tuple,
00694 TupleDesc tupleDesc,
00695 Datum *replValues,
00696 char *replNulls,
00697 char *replActions);
00698 extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc,
00699 Datum *values, char *nulls);
00700 extern void heap_freetuple(HeapTuple htup);
00701 extern MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor,
00702 Datum *values, bool *isnull);
00703 extern void heap_free_minimal_tuple(MinimalTuple mtup);
00704 extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup);
00705 extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup);
00706 extern MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup);
00707
00708 #endif