Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0966516

Browse files
committed
Tighten short-circuit tests for deciding whether we need to invoke
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.
1 parent b897441 commit 0966516

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

src/backend/access/common/heaptuple.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.88 2003/11/29 19:51:39 pgsql Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.89 2004/01/16 20:51:30 tgl Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -303,7 +303,7 @@ nocachegetattr(HeapTuple tuple,
303303
return fetchatt(att[attnum],
304304
tp + att[attnum]->attcacheoff);
305305
}
306-
else if (!HeapTupleAllFixed(tuple))
306+
else if (HeapTupleHasVarWidth(tuple))
307307
{
308308
int j;
309309

@@ -378,13 +378,10 @@ nocachegetattr(HeapTuple tuple,
378378

379379
for (i = 0; i < attnum; i++)
380380
{
381-
if (!HeapTupleNoNulls(tuple))
381+
if (HeapTupleHasNulls(tuple) && att_isnull(i, bp))
382382
{
383-
if (att_isnull(i, bp))
384-
{
385-
usecache = false;
386-
continue;
387-
}
383+
usecache = false;
384+
continue;
388385
}
389386

390387
/* If we know the next offset, we can skip the rest */

src/backend/access/heap/heapam.c

+13-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.161 2004/01/07 18:56:24 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.162 2004/01/16 20:51:30 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1091,16 +1091,13 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
10911091
HeapTupleHeaderSetCmin(tup->t_data, cid);
10921092
tup->t_tableOid = relation->rd_id;
10931093

1094-
#ifdef TUPLE_TOASTER_ACTIVE
1095-
10961094
/*
10971095
* If the new tuple is too big for storage or contains already toasted
1098-
* attributes from some other relation, invoke the toaster.
1096+
* out-of-line attributes from some other relation, invoke the toaster.
10991097
*/
1100-
if (HeapTupleHasExtended(tup) ||
1098+
if (HeapTupleHasExternal(tup) ||
11011099
(MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD))
11021100
heap_tuple_toast_attrs(relation, tup, NULL);
1103-
#endif
11041101

11051102
/* Find buffer to insert this tuple into */
11061103
buffer = RelationGetBufferForTuple(relation, tup->t_len, InvalidBuffer);
@@ -1352,17 +1349,14 @@ heap_delete(Relation relation, ItemPointer tid,
13521349

13531350
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
13541351

1355-
#ifdef TUPLE_TOASTER_ACTIVE
1356-
13571352
/*
1358-
* If the relation has toastable attributes, we need to delete no
1359-
* longer needed items there too. We have to do this before
1360-
* WriteBuffer because we need to look at the contents of the tuple,
1361-
* but it's OK to release the context lock on the buffer first.
1353+
* If the tuple has toasted out-of-line attributes, we need to delete
1354+
* those items too. We have to do this before WriteBuffer because we need
1355+
* to look at the contents of the tuple, but it's OK to release the
1356+
* context lock on the buffer first.
13621357
*/
1363-
if (HeapTupleHasExtended(&tp))
1364-
heap_tuple_toast_attrs(relation, NULL, &(tp));
1365-
#endif
1358+
if (HeapTupleHasExternal(&tp))
1359+
heap_tuple_toast_attrs(relation, NULL, &tp);
13661360

13671361
pgstat_count_heap_delete(&relation->pgstat_info);
13681362

@@ -1572,11 +1566,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
15721566
* implement UNDO and will re-use transaction IDs after postmaster
15731567
* startup.
15741568
*
1575-
* We need to invoke the toaster if there are already any toasted values
1576-
* present, or if the new tuple is over-threshold.
1569+
* We need to invoke the toaster if there are already any out-of-line
1570+
* toasted values present, or if the new tuple is over-threshold.
15771571
*/
1578-
need_toast = (HeapTupleHasExtended(&oldtup) ||
1579-
HeapTupleHasExtended(newtup) ||
1572+
need_toast = (HeapTupleHasExternal(&oldtup) ||
1573+
HeapTupleHasExternal(newtup) ||
15801574
(MAXALIGN(newtup->t_len) > TOAST_TUPLE_THRESHOLD));
15811575

15821576
newtupsize = MAXALIGN(newtup->t_len);

src/include/access/htup.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.63 2003/11/29 22:40:55 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.64 2004/01/16 20:51:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -436,9 +436,15 @@ typedef HeapTupleData *HeapTuple;
436436
*/
437437
#define HeapTupleIsValid(tuple) PointerIsValid(tuple)
438438

439+
#define HeapTupleHasNulls(tuple) \
440+
(((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
441+
439442
#define HeapTupleNoNulls(tuple) \
440443
(!((tuple)->t_data->t_infomask & HEAP_HASNULL))
441444

445+
#define HeapTupleHasVarWidth(tuple) \
446+
(((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)
447+
442448
#define HeapTupleAllFixed(tuple) \
443449
(!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))
444450

src/include/postgres.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1995, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.67 2004/01/04 05:57:21 tgl Exp $
13+
* $PostgreSQL: pgsql/src/include/postgres.h,v 1.68 2004/01/16 20:51:30 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -59,8 +59,6 @@
5959
* TOASTed.
6060
* ----------------
6161
*/
62-
#define TUPLE_TOASTER_ACTIVE
63-
6462
typedef struct varattrib
6563
{
6664
int32 va_header; /* External/compressed storage */

0 commit comments

Comments
 (0)