Skip to content

Commit 617dd33

Browse files
committed
Eliminate duplicate hasnulls bit testing in index tuple access, and
clean up itup.h a little bit.
1 parent 926e8a0 commit 617dd33

File tree

3 files changed

+33
-64
lines changed

3 files changed

+33
-64
lines changed

src/backend/access/common/indextuple.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.73 2005/03/21 01:23:55 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.74 2005/03/27 18:38:26 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -137,7 +137,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
137137
isnull,
138138
(char *) tp + hoff,
139139
&tupmask,
140-
(hasnull ? (bits8 *) tp + sizeof(*tuple) : NULL));
140+
(hasnull ? (bits8 *) tp + sizeof(IndexTupleData) : NULL));
141141

142142
#ifdef TOAST_INDEX_HACK
143143
for (i = 0; i < numberOfAttributes; i++)
@@ -230,8 +230,7 @@ nocache_index_getattr(IndexTuple tup,
230230
*isnull = false;
231231
#endif
232232

233-
data_off = IndexTupleHasMinHeader(tup) ? sizeof *tup :
234-
IndexInfoFindDataOffset(tup->t_info);
233+
data_off = IndexInfoFindDataOffset(tup->t_info);
235234

236235
attnum--;
237236

@@ -256,7 +255,7 @@ nocache_index_getattr(IndexTuple tup,
256255
*/
257256

258257
/* XXX "knows" t_bits are just after fixed tuple header! */
259-
bp = (bits8 *) ((char *) tup + sizeof(*tup));
258+
bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData));
260259

261260
#ifdef IN_MACRO
262261
/* This is handled in the macro */

src/include/access/ibit.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/include/access/itup.h

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,31 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/itup.h,v 1.42 2005/03/21 01:24:04 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/itup.h,v 1.43 2005/03/27 18:38:27 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#ifndef ITUP_H
1515
#define ITUP_H
1616

17-
#include "access/ibit.h"
1817
#include "access/tupdesc.h"
1918
#include "access/tupmacs.h"
2019
#include "storage/itemptr.h"
2120

2221

22+
/*
23+
* Index tuple header structure
24+
*
25+
* All index tuples start with IndexTupleData. If the HasNulls bit is set,
26+
* this is followed by an IndexAttributeBitMapData. The index attribute
27+
* values follow, beginning at a MAXALIGN boundary.
28+
*
29+
* Note that the space allocated for the bitmap does not vary with the number
30+
* of attributes; that is because we don't have room to store the number of
31+
* attributes in the header. Given the MAXALIGN constraint there's no space
32+
* savings to be had anyway, for usual values of INDEX_MAX_KEYS.
33+
*/
34+
2335
typedef struct IndexTupleData
2436
{
2537
ItemPointerData t_tid; /* reference TID to heap tuple */
@@ -36,44 +48,40 @@ typedef struct IndexTupleData
3648

3749
unsigned short t_info; /* various info about tuple */
3850

39-
/*
40-
* please make sure sizeof(IndexTupleData) is MAXALIGN'ed. See
41-
* IndexInfoFindDataOffset() for the reason.
42-
*/
43-
4451
} IndexTupleData; /* MORE DATA FOLLOWS AT END OF STRUCT */
4552

4653
typedef IndexTupleData *IndexTuple;
4754

55+
typedef struct IndexAttributeBitMapData
56+
{
57+
bits8 bits[(INDEX_MAX_KEYS + 8 - 1) / 8];
58+
} IndexAttributeBitMapData;
59+
60+
typedef IndexAttributeBitMapData *IndexAttributeBitMap;
4861

49-
/* ----------------
50-
* externs
51-
* ----------------
62+
/*
63+
* t_info manipulation macros
5264
*/
53-
5465
#define INDEX_SIZE_MASK 0x1FFF
55-
#define INDEX_NULL_MASK 0x8000
66+
/* bit 0x2000 is not used at present */
5667
#define INDEX_VAR_MASK 0x4000
57-
/* bit 0x2000 is not used */
68+
#define INDEX_NULL_MASK 0x8000
5869

5970
#define IndexTupleSize(itup) ((Size) (((IndexTuple) (itup))->t_info & INDEX_SIZE_MASK))
6071
#define IndexTupleDSize(itup) ((Size) ((itup).t_info & INDEX_SIZE_MASK))
6172
#define IndexTupleHasNulls(itup) ((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK))
6273
#define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK))
6374

64-
#define IndexTupleHasMinHeader(itup) (!IndexTupleHasNulls(itup))
6575

6676
/*
6777
* Takes an infomask as argument (primarily because this needs to be usable
6878
* at index_form_tuple time so enough space is allocated).
69-
*
70-
* Change me if adding an attribute to IndexTuples!!!!!!!!!!!
7179
*/
7280
#define IndexInfoFindDataOffset(t_info) \
7381
( \
74-
(!((unsigned short)(t_info) & INDEX_NULL_MASK)) ? \
82+
(!((t_info) & INDEX_NULL_MASK)) ? \
7583
( \
76-
(Size)sizeof(IndexTupleData) \
84+
(Size)MAXALIGN(sizeof(IndexTupleData)) \
7785
) \
7886
: \
7987
( \
@@ -85,7 +93,7 @@ typedef IndexTupleData *IndexTuple;
8593
* index_getattr
8694
*
8795
* This gets called many times, so we macro the cacheable and NULL
88-
* lookups, and call noncachegetattr() for the rest.
96+
* lookups, and call nocache_index_getattr() for the rest.
8997
*
9098
* ----------------
9199
*/
@@ -98,21 +106,15 @@ typedef IndexTupleData *IndexTuple;
98106
(tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \
99107
( \
100108
fetchatt((tupleDesc)->attrs[(attnum)-1], \
101-
(char *) (tup) + \
102-
( \
103-
IndexTupleHasMinHeader(tup) ? \
104-
sizeof (*(tup)) \
105-
: \
106-
IndexInfoFindDataOffset((tup)->t_info) \
107-
) \
109+
(char *) (tup) + IndexInfoFindDataOffset((tup)->t_info) \
108110
+ (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \
109111
) \
110112
: \
111113
nocache_index_getattr((tup), (attnum), (tupleDesc), (isnull)) \
112114
) \
113115
: \
114116
( \
115-
(att_isnull((attnum)-1, (char *)(tup) + sizeof(*(tup)))) ? \
117+
(att_isnull((attnum)-1, (char *)(tup) + sizeof(IndexTupleData))) ? \
116118
( \
117119
*(isnull) = true, \
118120
(Datum)NULL \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy