]> granicus.if.org Git - postgresql/commitdiff
Tighten short-circuit tests for deciding whether we need to invoke
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 16 Jan 2004 20:51:30 +0000 (20:51 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 16 Jan 2004 20:51:30 +0000 (20:51 +0000)
tuptoaster.c --- fields that are compressed in-line are not a reason
to invoke the toaster.  Along the way, add a couple more htup.h macros
to eliminate confusing negated tests, and get rid of the already
vestigial TUPLE_TOASTER_ACTIVE symbol.

src/backend/access/common/heaptuple.c
src/backend/access/heap/heapam.c
src/include/access/htup.h
src/include/postgres.h

index 8bb4b7149f2f002dcb40f43be9802c4eecde3d9a..f1b20ff27323436f4c4ee2984ecafe937ae1c03f 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.88 2003/11/29 19:51:39 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.89 2004/01/16 20:51:30 tgl Exp $
  *
  * NOTES
  *       The old interface functions have been converted to macros
@@ -303,7 +303,7 @@ nocachegetattr(HeapTuple tuple,
                        return fetchatt(att[attnum],
                                                        tp + att[attnum]->attcacheoff);
                }
-               else if (!HeapTupleAllFixed(tuple))
+               else if (HeapTupleHasVarWidth(tuple))
                {
                        int                     j;
 
@@ -378,13 +378,10 @@ nocachegetattr(HeapTuple tuple,
 
                for (i = 0; i < attnum; i++)
                {
-                       if (!HeapTupleNoNulls(tuple))
+                       if (HeapTupleHasNulls(tuple) && att_isnull(i, bp))
                        {
-                               if (att_isnull(i, bp))
-                               {
-                                       usecache = false;
-                                       continue;
-                               }
+                               usecache = false;
+                               continue;
                        }
 
                        /* If we know the next offset, we can skip the rest */
index a4f9b3afd33eb0a3911bad3b3f8fc90bdabf0b11..d98e3fd16c248308c5ce748c29c4fa27fcf55b07 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.161 2004/01/07 18:56:24 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.162 2004/01/16 20:51:30 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -1091,16 +1091,13 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
        HeapTupleHeaderSetCmin(tup->t_data, cid);
        tup->t_tableOid = relation->rd_id;
 
-#ifdef TUPLE_TOASTER_ACTIVE
-
        /*
         * If the new tuple is too big for storage or contains already toasted
-        * attributes from some other relation, invoke the toaster.
+        * out-of-line attributes from some other relation, invoke the toaster.
         */
-       if (HeapTupleHasExtended(tup) ||
+       if (HeapTupleHasExternal(tup) ||
                (MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD))
                heap_tuple_toast_attrs(relation, tup, NULL);
-#endif
 
        /* Find buffer to insert this tuple into */
        buffer = RelationGetBufferForTuple(relation, tup->t_len, InvalidBuffer);
@@ -1352,17 +1349,14 @@ l1:
 
        LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
 
-#ifdef TUPLE_TOASTER_ACTIVE
-
        /*
-        * If the relation has toastable attributes, we need to delete no
-        * longer needed items there too.  We have to do this before
-        * WriteBuffer because we need to look at the contents of the tuple,
-        * but it's OK to release the context lock on the buffer first.
+        * If the tuple has toasted out-of-line attributes, we need to delete
+        * those items too.  We have to do this before WriteBuffer because we need
+        * to look at the contents of the tuple, but it's OK to release the
+        * context lock on the buffer first.
         */
-       if (HeapTupleHasExtended(&tp))
-               heap_tuple_toast_attrs(relation, NULL, &(tp));
-#endif
+       if (HeapTupleHasExternal(&tp))
+               heap_tuple_toast_attrs(relation, NULL, &tp);
 
        pgstat_count_heap_delete(&relation->pgstat_info);
 
@@ -1572,11 +1566,11 @@ l2:
         * implement UNDO and will re-use transaction IDs after postmaster
         * startup.
         *
-        * We need to invoke the toaster if there are already any toasted values
-        * present, or if the new tuple is over-threshold.
+        * We need to invoke the toaster if there are already any out-of-line
+        * toasted values present, or if the new tuple is over-threshold.
         */
-       need_toast = (HeapTupleHasExtended(&oldtup) ||
-                                 HeapTupleHasExtended(newtup) ||
+       need_toast = (HeapTupleHasExternal(&oldtup) ||
+                                 HeapTupleHasExternal(newtup) ||
                                  (MAXALIGN(newtup->t_len) > TOAST_TUPLE_THRESHOLD));
 
        newtupsize = MAXALIGN(newtup->t_len);
index f64925ea982bf84ee0923bde15a09ac9b2906d25..a47e668f9b26d1e242a881452ea3fb94ca8480aa 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.63 2003/11/29 22:40:55 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.64 2004/01/16 20:51:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -436,9 +436,15 @@ typedef HeapTupleData *HeapTuple;
  */
 #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
 
+#define HeapTupleHasNulls(tuple) \
+               (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
+
 #define HeapTupleNoNulls(tuple) \
                (!((tuple)->t_data->t_infomask & HEAP_HASNULL))
 
+#define HeapTupleHasVarWidth(tuple) \
+               (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)
+
 #define HeapTupleAllFixed(tuple) \
                (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))
 
index f3ce6e71d0e7f4202d356350ad4f4316cb4beb19..8fa6d08590dcd37272069933b343d40ca436c98f 100644 (file)
@@ -10,7 +10,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1995, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/postgres.h,v 1.67 2004/01/04 05:57:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/postgres.h,v 1.68 2004/01/16 20:51:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -59,8 +59,6 @@
  * TOASTed.
  * ----------------
  */
-#define TUPLE_TOASTER_ACTIVE
-
 typedef struct varattrib
 {
        int32           va_header;              /* External/compressed storage */