Re: Reduce heap tuple header size II - Mailing list pgsql-patches
From | Manfred Koizar |
---|---|
Subject | Re: Reduce heap tuple header size II |
Date | |
Msg-id | b26jhu0bml0hn88ig4ds5s6m2j1a3lllqc@4ax.com Whole thread Raw |
In response to | Re: Reduce heap tuple header size (Bruce Momjian <pgman@candle.pha.pa.us>) |
Responses |
Re: Reduce heap tuple header size II
|
List | pgsql-patches |
On Fri, 21 Jun 2002 12:45:48 -0400 (EDT), Bruce Momjian <pgman@candle.pha.pa.us> wrote: >> > Yes, there are some good ones there, but the idea that somehow they are >> > all going to hit in the same release seems unlikely. I say let's do >> > some now, some later, and move ahead. I (strongly :-)) agree. >Well, that is a different argument than initially. So, it is a valid >patch, but we have to decide when to apply it. > >We can easily hold it until we near release of 7.3. If pg_upgrade is in >good shape _and_ no other format changes are required, we can hold it >for 7.4. What happens if 7.4 doesn't have any format changes? > >However, if we have other changes or pg_upgrade isn't going to work, we >can apply it in August. But what, if the patch causes or reveals a well hidden bug, possibly somewhere else in the code? I'd vote for applying it now, so that in August it already has undergone some testing. You can always patch -R before going beta... >(Manfred, you can be sure I will not lose this patch.) Thanks. Anyway, lose it! Here is a new version. >So, we have to decide if we apply it now or delay it for later in 7.3, >or for >=7.4. Why not let the users decide? With this new version of the patch they can configure --enable-pg72format if this patch is the only thing that stops pg_upgrade from working and if they want to use pg_upgrade. >My personal vote is that we apply it now, and perhaps try some of the >other format changes we were going to make. And with #ifdef PG72FORMAT we can introduce them without very much risk. One thing that's still missing is we'd need two entries in catversion.h. Servus Manfred diff -u ../base/INSTALL ./INSTALL --- ../base/INSTALL 2002-01-31 01:46:26.000000000 +0100 +++ ./INSTALL 2002-06-25 15:59:03.000000000 +0200 @@ -283,6 +283,13 @@ Enables single-byte character set recode support. See the Administrator's Guide about this feature. + --enable-pg72format + + Enables version 7.2 page format, giving you a better chance of + converting existing databases by pg_upgrade. Do not use this + feature, if you are just starting to use PostgreSQL or if you + plan to upgrade via pg_dump/restore. + --enable-multibyte Allows the use of multibyte character encodings (including Common subdirectories: ../base/config and ./config diff -u ../base/configure ./configure --- ../base/configure 2002-05-29 14:42:20.000000000 +0200 +++ ./configure 2002-06-25 15:51:18.000000000 +0200 @@ -1652,6 +1652,44 @@ # +# Version 7.2 page format (--enable-pg72format) +# +echo "$as_me:$LINENO: checking whether to build with version 7.2 page format" >&5 +echo $ECHO_N "checking whether to build with version 7.2 page format... $ECHO_C" >&6 + + +# Check whether --enable-pg72format or --disable-pg72format was given. +if test "${enable_pg72format+set}" = set; then + enableval="$enable_pg72format" + + case $enableval in + yes) + +cat >>confdefs.h <<\_ACEOF +#define PG72FORMAT 1 +_ACEOF + + ;; + no) + : + ;; + *) + { { echo "$as_me:$LINENO: error: no argument expected for --enable-pg72format option" >&5 +echo "$as_me: error: no argument expected for --enable-pg72format option" >&2;} + { (exit 1); exit 1; }; } + ;; + esac + +else + enable_pg72format=no + +fi; + +echo "$as_me:$LINENO: result: $enable_pg72format" >&5 +echo "${ECHO_T}$enable_pg72format" >&6 + + +# # Multibyte support # MULTIBYTE=SQL_ASCII diff -u ../base/configure.in ./configure.in --- ../base/configure.in 2002-05-29 14:42:20.000000000 +0200 +++ ./configure.in 2002-06-25 15:51:15.000000000 +0200 @@ -162,6 +162,16 @@ # +# Version 7.2 page format (--enable-pg72format) +# +AC_MSG_CHECKING([whether to build with version 7.2 page format]) +PGAC_ARG_BOOL(enable, pg72format, no, [ --enable-pg72format enable version 7.2 page format], + [AC_DEFINE([PG72FORMAT], 1, + [Set to 1 if you want version 7.2 page format (--enable-pg72format)])]) +AC_MSG_RESULT([$enable_pg72format]) + + +# # Multibyte support # MULTIBYTE=SQL_ASCII diff -ru ../base/src/backend/access/heap/heapam.c src/backend/access/heap/heapam.c --- ../base/src/backend/access/heap/heapam.c 2002-06-17 10:11:31.000000000 +0200 +++ src/backend/access/heap/heapam.c 2002-06-17 22:35:32.000000000 +0200 @@ -2204,7 +2204,7 @@ htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask; HeapTupleHeaderSetXmin(htup, record->xl_xid); HeapTupleHeaderSetCmin(htup, FirstCommandId); - HeapTupleHeaderSetXmax(htup, InvalidTransactionId); + HeapTupleHeaderSetXmaxInvalid(htup); HeapTupleHeaderSetCmax(htup, FirstCommandId); offnum = PageAddItem(page, (Item) htup, newlen, offnum, diff -ru ../base/src/include/access/htup.h src/include/access/htup.h --- ../base/src/include/access/htup.h 2002-06-17 10:11:32.000000000 +0200 +++ src/include/access/htup.h 2002-06-25 16:14:37.000000000 +0200 @@ -57,15 +57,33 @@ * Also note that we omit the nulls bitmap if t_infomask shows that there * are no nulls in the tuple. */ +/* +** We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac +** in three physical fields t_xmin, t_cid, t_xmax: +** CommandId Cmin; insert CID stamp +** CommandId Cmax; delete CommandId stamp +** TransactionId Xmin; insert XID stamp +** TransactionId Xmax; delete XID stamp +** TransactionId Xvac; used by VACCUUM +** +** This assumes, that a CommandId can be stored in a TransactionId. +*/ typedef struct HeapTupleHeaderData { Oid t_oid; /* OID of this tuple -- 4 bytes */ +#ifdef PG72FORMAT + /* v7.2: Xvac is stored in t_cmin */ CommandId t_cmin; /* insert CID stamp -- 4 bytes each */ CommandId t_cmax; /* delete CommandId stamp */ TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */ TransactionId t_xmax; /* delete XID stamp */ +#else + TransactionId t_xmin; /* Xmin -- 4 bytes each */ + TransactionId t_cid; /* Cmin, Cmax, Xvac */ + TransactionId t_xmax; /* Xmax, Cmax */ +#endif ItemPointerData t_ctid; /* current TID of this or newer tuple */ @@ -75,7 +93,7 @@ uint8 t_hoff; /* sizeof header incl. bitmap, padding */ - /* ^ - 31 bytes - ^ */ + /* ^ - 27 (v7.3) or 31 (v7.2) bytes - ^ */ bits8 t_bits[1]; /* bitmap of NULLs -- VARIABLE LENGTH */ @@ -96,6 +114,8 @@ * attribute(s) */ #define HEAP_HASEXTENDED 0x000C /* the two above combined */ +#define HEAP_XMIN_IS_XMAX 0x0040 /* created and deleted in the */ + /* same transaction */ #define HEAP_XMAX_UNLOGGED 0x0080 /* to lock tuple for update */ /* without logging */ #define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */ @@ -108,6 +128,7 @@ * vacuum */ #define HEAP_MOVED_IN 0x8000 /* moved from another place by * vacuum */ +#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN) #define HEAP_XACT_MASK 0xFFF0 /* visibility-related bits */ @@ -116,8 +137,11 @@ /* HeapTupleHeader accessor macros */ #define HeapTupleHeaderGetXmin(tup) \ - ((tup)->t_xmin) +( \ + (tup)->t_xmin \ +) +#ifdef PG72FORMAT #define HeapTupleHeaderGetXmax(tup) \ ((tup)->t_xmax) @@ -163,6 +187,98 @@ AssertMacro((tup)->t_infomask & (HEAP_MOVED_IN | HEAP_MOVED_OFF)), \ TransactionIdStore((xid), (TransactionId *) &((tup)->t_cmin)) \ ) +#else +#define HeapTupleHeaderGetXmax(tup) \ +( \ + ((tup)->t_infomask & HEAP_XMIN_IS_XMAX) ? \ + (tup)->t_xmin \ + : \ + (tup)->t_xmax \ +) + +/* no AssertMacro, because this is read as a system-defined attribute */ +#define HeapTupleHeaderGetCmin(tup) \ +( \ + ((tup)->t_infomask & HEAP_MOVED) ? \ + FirstCommandId \ + : \ + ( \ + ((tup)->t_infomask & (HEAP_XMIN_IS_XMAX | HEAP_XMAX_INVALID)) ? \ + (CommandId) (tup)->t_cid \ + : \ + FirstCommandId \ + ) \ +) + +#define HeapTupleHeaderGetCmax(tup) \ +( \ + ((tup)->t_infomask & HEAP_MOVED) ? \ + FirstCommandId \ + : \ + ( \ + ((tup)->t_infomask & (HEAP_XMIN_IS_XMAX | HEAP_XMAX_INVALID)) ? \ + (CommandId) (tup)->t_xmax \ + : \ + (CommandId) (tup)->t_cid \ + ) \ +) + +#define HeapTupleHeaderGetXvac(tup) \ +( \ + AssertMacro((tup)->t_infomask & HEAP_MOVED), \ + (tup)->t_cid \ +) + + +#define HeapTupleHeaderSetXmin(tup, xid) \ +( \ + TransactionIdStore((xid), &(tup)->t_xmin) \ +) + +#define HeapTupleHeaderSetXminInvalid(tup) \ +do { \ + (tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \ + StoreInvalidTransactionId(&(tup)->t_xmin); \ +} while (0) + +#define HeapTupleHeaderSetXmax(tup, xid) \ +do { \ + if (TransactionIdEquals((tup)->t_xmin, (xid))) \ + (tup)->t_infomask |= HEAP_XMIN_IS_XMAX; \ + else \ + { \ + (tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \ + TransactionIdStore((xid), &(tup)->t_xmax); \ + } \ +} while (0) + +#define HeapTupleHeaderSetXmaxInvalid(tup) \ +do { \ + (tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \ + StoreInvalidTransactionId(&(tup)->t_xmax); \ +} while (0) + +#define HeapTupleHeaderSetCmin(tup, cid) \ +do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + TransactionIdStore((TransactionId) (cid), &(tup)->t_cid); \ +} while (0) + +#define HeapTupleHeaderSetCmax(tup, cid) \ +do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + if ((tup)->t_infomask & HEAP_XMIN_IS_XMAX) \ + TransactionIdStore((TransactionId) (cid), &(tup)->t_xmax); \ + else \ + TransactionIdStore((TransactionId) (cid), &(tup)->t_cid); \ +} while (0) + +#define HeapTupleHeaderSetXvac(tup, xid) \ +do { \ + Assert((tup)->t_infomask & HEAP_MOVED); \ + TransactionIdStore((xid), &(tup)->t_cid); \ +} while (0) +#endif /* diff -ru ../base/src/include/pg_config.h.in src/include/pg_config.h.in --- ../base/src/include/pg_config.h.in 2002-06-17 21:04:03.000000000 +0200 +++ src/include/pg_config.h.in 2002-06-25 16:02:40.000000000 +0200 @@ -39,6 +39,9 @@ /* Set to 1 if you want cyrillic recode (--enable-recode) */ #undef CYR_RECODE +/* Set to 1 if you want version 7.2 page format (--enable-pg72format) */ +#undef PG72FORMAT + /* Set to 1 if you want to use multibyte characters (--enable-multibyte) */ #undef MULTIBYTE
pgsql-patches by date: