|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.19 2009/01/01 17:23:34 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.20 2009/06/06 02:39:40 tgl Exp $ |
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
14 | 14 |
|
|
20 | 20 | #include "utils/rel.h"
|
21 | 21 |
|
22 | 22 | /*
|
23 |
| - * forms tuple for entry tree. On leaf page, Index tuple has |
24 |
| - * non-traditional layout. Tuple may contain posting list or |
25 |
| - * root blocknumber of posting tree. Macros GinIsPostingTre: (itup) / GinSetPostingTree(itup, blkno) |
| 23 | + * Form a tuple for entry tree. |
| 24 | + * |
| 25 | + * On leaf pages, Index tuple has non-traditional layout. Tuple may contain |
| 26 | + * posting list or root blocknumber of posting tree. |
| 27 | + * Macros: GinIsPostingTree(itup) / GinSetPostingTree(itup, blkno) |
26 | 28 | * 1) Posting list
|
27 |
| - * - itup->t_info & INDEX_SIZE_MASK contains size of tuple as usual |
| 29 | + * - itup->t_info & INDEX_SIZE_MASK contains total size of tuple as usual |
28 | 30 | * - ItemPointerGetBlockNumber(&itup->t_tid) contains original
|
29 | 31 | * size of tuple (without posting list).
|
30 |
| - * Macroses: GinGetOrigSizePosting(itup) / GinSetOrigSizePosting(itup,n) |
| 32 | + * Macros: GinGetOrigSizePosting(itup) / GinSetOrigSizePosting(itup,n) |
31 | 33 | * - ItemPointerGetOffsetNumber(&itup->t_tid) contains number
|
32 |
| - * of elements in posting list (number of heap itempointer) |
33 |
| - * Macroses: GinGetNPosting(itup) / GinSetNPosting(itup,n) |
34 |
| - * - After usual part of tuple there is a posting list |
| 34 | + * of elements in posting list (number of heap itempointers) |
| 35 | + * Macros: GinGetNPosting(itup) / GinSetNPosting(itup,n) |
| 36 | + * - After standard part of tuple there is a posting list, ie, array |
| 37 | + * of heap itempointers |
35 | 38 | * Macros: GinGetPosting(itup)
|
36 | 39 | * 2) Posting tree
|
37 | 40 | * - itup->t_info & INDEX_SIZE_MASK contains size of tuple as usual
|
38 | 41 | * - ItemPointerGetBlockNumber(&itup->t_tid) contains block number of
|
39 | 42 | * root of posting tree
|
40 |
| - * - ItemPointerGetOffsetNumber(&itup->t_tid) contains magic number GIN_TREE_POSTING |
| 43 | + * - ItemPointerGetOffsetNumber(&itup->t_tid) contains magic number |
| 44 | + * GIN_TREE_POSTING, which distinguishes this from posting-list case |
41 | 45 | *
|
42 |
| - * Storage of attributes of tuple are different for single and multicolumn index. |
43 |
| - * For single-column index tuple stores only value to be indexed and for |
44 |
| - * multicolumn variant it stores two attributes: column number of value and value. |
| 46 | + * Attributes of an index tuple are different for single and multicolumn index. |
| 47 | + * For single-column case, index tuple stores only value to be indexed. |
| 48 | + * For multicolumn case, it stores two attributes: column number of value |
| 49 | + * and value. |
45 | 50 | */
|
46 | 51 | IndexTuple
|
47 | 52 | GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key, ItemPointerData *ipd, uint32 nipd)
|
@@ -89,6 +94,28 @@ GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key, ItemPointerData
|
89 | 94 | return itup;
|
90 | 95 | }
|
91 | 96 |
|
| 97 | +/* |
| 98 | + * Sometimes we reduce the number of posting list items in a tuple after |
| 99 | + * having built it with GinFormTuple. This function adjusts the size |
| 100 | + * fields to match. |
| 101 | + */ |
| 102 | +void |
| 103 | +GinShortenTuple(IndexTuple itup, uint32 nipd) |
| 104 | +{ |
| 105 | + uint32 newsize; |
| 106 | + |
| 107 | + Assert(nipd <= GinGetNPosting(itup)); |
| 108 | + |
| 109 | + newsize = MAXALIGN(SHORTALIGN(GinGetOrigSizePosting(itup)) + sizeof(ItemPointerData) * nipd); |
| 110 | + |
| 111 | + Assert(newsize <= (itup->t_info & INDEX_SIZE_MASK)); |
| 112 | + |
| 113 | + itup->t_info &= ~INDEX_SIZE_MASK; |
| 114 | + itup->t_info |= newsize; |
| 115 | + |
| 116 | + GinSetNPosting(itup, nipd); |
| 117 | +} |
| 118 | + |
92 | 119 | /*
|
93 | 120 | * Entry tree is a "static", ie tuple never deletes from it,
|
94 | 121 | * so we don't use right bound, we use rightest key instead.
|
|
0 commit comments