Skip to content

Commit f67e790

Browse files
Jan WieckJan Wieck
authored andcommitted
2nd try for the index tuple toast hack. This time as suggested
by Tom. Jan
1 parent a5a1288 commit f67e790

File tree

4 files changed

+108
-206
lines changed

4 files changed

+108
-206
lines changed

src/backend/access/common/indextuple.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.43 2000/04/12 17:14:37 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.44 2000/07/22 11:18:45 wieck Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616

1717
#include "postgres.h"
1818

1919
#include "access/heapam.h"
20+
#include "access/tuptoaster.h"
2021
#include "access/itup.h"
2122
#include "catalog/pg_type.h"
2223

@@ -44,11 +45,40 @@ index_formtuple(TupleDesc tupleDescriptor,
4445
bool hasnull = false;
4546
uint16 tupmask = 0;
4647
int numberOfAttributes = tupleDescriptor->natts;
48+
#ifdef TOAST_INDEX_HACK
49+
Datum untoasted_value[MaxHeapAttributeNumber];
50+
bool untoasted_free[MaxHeapAttributeNumber];
51+
#endif
4752

4853
if (numberOfAttributes > INDEX_MAX_KEYS)
4954
elog(ERROR, "index_formtuple: numberOfAttributes %d > %d",
5055
numberOfAttributes, INDEX_MAX_KEYS);
5156

57+
#ifdef TOAST_INDEX_HACK
58+
for (i = 0; i < numberOfAttributes; i++)
59+
{
60+
if (null[i] != ' ' || tupleDescriptor->attrs[i]->attlen >= 0)
61+
{
62+
untoasted_value[i] = value[i];
63+
untoasted_free[i] = false;
64+
}
65+
else
66+
{
67+
if (VARATT_IS_EXTERNAL(value[i]))
68+
{
69+
untoasted_value[i] = PointerGetDatum(
70+
heap_tuple_fetch_attr(
71+
(varattrib *)DatumGetPointer(value[i])));
72+
untoasted_free[i] = true;
73+
}
74+
else
75+
{
76+
untoasted_value[i] = value[i];
77+
untoasted_free[i] = false;
78+
}
79+
}
80+
}
81+
#endif
5282
for (i = 0; i < numberOfAttributes && !hasnull; i++)
5383
{
5484
if (null[i] != ' ')
@@ -59,7 +89,11 @@ index_formtuple(TupleDesc tupleDescriptor,
5989
infomask |= INDEX_NULL_MASK;
6090

6191
hoff = IndexInfoFindDataOffset(infomask);
92+
#ifdef TOAST_INDEX_HACK
93+
size = hoff + ComputeDataSize(tupleDescriptor, untoasted_value, null);
94+
#else
6295
size = hoff + ComputeDataSize(tupleDescriptor, value, null);
96+
#endif
6397
size = MAXALIGN(size); /* be conservative */
6498

6599
tp = (char *) palloc(size);
@@ -68,11 +102,23 @@ index_formtuple(TupleDesc tupleDescriptor,
68102

69103
DataFill((char *) tp + hoff,
70104
tupleDescriptor,
105+
#ifdef TOAST_INDEX_HACK
106+
untoasted_value,
107+
#else
71108
value,
109+
#endif
72110
null,
73111
&tupmask,
74112
(hasnull ? (bits8 *) tp + sizeof(*tuple) : NULL));
75113

114+
#ifdef TOAST_INDEX_HACK
115+
for (i = 0; i < numberOfAttributes; i++)
116+
{
117+
if (untoasted_free[i])
118+
pfree(DatumGetPointer(untoasted_value[i]));
119+
}
120+
#endif
121+
76122
/*
77123
* We do this because DataFill wants to initialize a "tupmask" which
78124
* is used for HeapTuples, but we want an indextuple infomask. The

src/backend/access/heap/heapam.c

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.81 2000/07/21 11:18:51 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.82 2000/07/22 11:18:46 wieck Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1274,10 +1274,6 @@ Oid
12741274
heap_insert(Relation relation, HeapTuple tup)
12751275
{
12761276
Buffer buffer;
1277-
#ifndef TOAST_INDICES
1278-
HeapTupleHeader plaintdata = NULL;
1279-
int32 plaintlen = 0;
1280-
#endif
12811277

12821278
/* increment access statistics */
12831279
tup->tableOid = relation->rd_id;
@@ -1313,11 +1309,7 @@ heap_insert(Relation relation, HeapTuple tup)
13131309
*/
13141310
if (HeapTupleHasExtended(tup) ||
13151311
(MAXALIGN(tup->t_len) > (MaxTupleSize / 4)))
1316-
#ifdef TOAST_INDICES
13171312
heap_tuple_toast_attrs(relation, tup, NULL);
1318-
#else
1319-
heap_tuple_toast_attrs(relation, tup, NULL, &plaintdata, &plaintlen);
1320-
#endif
13211313
#endif
13221314

13231315
/* Find buffer for this tuple */
@@ -1355,20 +1347,6 @@ heap_insert(Relation relation, HeapTuple tup)
13551347
if (IsSystemRelationName(RelationGetRelationName(relation)))
13561348
RelationMark4RollbackHeapTuple(relation, tup);
13571349

1358-
#ifndef TOAST_INDICES
1359-
if (plaintdata != NULL && tup->t_data != plaintdata)
1360-
{
1361-
if (tup->t_datamcxt != NULL && (char *) (tup->t_data) !=
1362-
((char *) tup + HEAPTUPLESIZE))
1363-
{
1364-
MemoryContext oldcxt = MemoryContextSwitchTo(tup->t_datamcxt);
1365-
pfree(tup->t_data);
1366-
MemoryContextSwitchTo(oldcxt);
1367-
}
1368-
tup->t_data = plaintdata;
1369-
tup->t_len = plaintlen;
1370-
}
1371-
#endif
13721350
return tup->t_data->t_oid;
13731351
}
13741352

@@ -1483,11 +1461,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
14831461
* ----------
14841462
*/
14851463
if (HeapTupleHasExtended(&tp))
1486-
#ifdef TOAST_INDICES
14871464
heap_tuple_toast_attrs(relation, NULL, &(tp));
1488-
#else
1489-
heap_tuple_toast_attrs(relation, NULL, &(tp), NULL, NULL);
1490-
#endif
14911465
#endif
14921466

14931467
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
@@ -1512,10 +1486,6 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
15121486
PageHeader dp;
15131487
Buffer buffer, newbuf;
15141488
int result;
1515-
#ifndef TOAST_INDICES
1516-
HeapTupleHeader plaintdata = NULL;
1517-
int32 plaintlen = 0;
1518-
#endif
15191489

15201490
newtup->tableOid = relation->rd_id;
15211491
/* increment access statistics */
@@ -1604,11 +1574,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
16041574
if (HeapTupleHasExtended(&oldtup) ||
16051575
HeapTupleHasExtended(newtup) ||
16061576
(MAXALIGN(newtup->t_len) > (MaxTupleSize / 4)))
1607-
#ifdef TOAST_INDICES
16081577
heap_tuple_toast_attrs(relation, newtup, &oldtup);
1609-
#else
1610-
heap_tuple_toast_attrs(relation, newtup, &oldtup, &plaintdata, &plaintlen);
1611-
#endif
16121578
#endif
16131579

16141580
/* Find buffer for new tuple */
@@ -1671,21 +1637,6 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
16711637
RelationInvalidateHeapTuple(relation, &oldtup);
16721638
RelationMark4RollbackHeapTuple(relation, newtup);
16731639

1674-
#ifndef TOAST_INDICES
1675-
if (plaintdata != NULL && newtup->t_data != plaintdata)
1676-
{
1677-
if (newtup->t_datamcxt != NULL && (char *) (newtup->t_data) !=
1678-
((char *) newtup + HEAPTUPLESIZE))
1679-
{
1680-
MemoryContext oldcxt = MemoryContextSwitchTo(newtup->t_datamcxt);
1681-
pfree(newtup->t_data);
1682-
MemoryContextSwitchTo(oldcxt);
1683-
}
1684-
newtup->t_data = plaintdata;
1685-
newtup->t_len = plaintlen;
1686-
}
1687-
#endif
1688-
16891640
return HeapTupleMayBeUpdated;
16901641
}
16911642

0 commit comments

Comments
 (0)