Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56218fb

Browse files
committed
Minor tweaking of index special-space definitions so that the various
index types can be reliably distinguished by examining the special spaceon an index page. Per my earlier proposal, plus the realization thatthere's no need for btree's vacuum cycle ID to cycle through every possible16-bit value. Restricting its range a little costs nearly nothing andeliminates the possibility of collisions.Memo to self: remember to make bitmap indexes play along with this scheme,assuming that patch ever gets accepted.
1 parent485d9ca commit56218fb

File tree

9 files changed

+78
-64
lines changed

9 files changed

+78
-64
lines changed

‎src/backend/access/gist/gistutil.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.21 2007/01/05 22:19:22 momjian Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.22 2007/04/09 22:03:57 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include"postgres.h"
@@ -559,10 +559,11 @@ GISTInitBuffer(Buffer b, uint32 f)
559559
PageInit(page,pageSize,sizeof(GISTPageOpaqueData));
560560

561561
opaque=GistPageGetOpaque(page);
562-
opaque->flags=f;
563-
opaque->rightlink=InvalidBlockNumber;
564562
/* page was already zeroed by PageInit, so this is not needed: */
565563
/* memset(&(opaque->nsn), 0, sizeof(GistNSN)); */
564+
opaque->rightlink=InvalidBlockNumber;
565+
opaque->flags=f;
566+
opaque->gist_page_id=GIST_PAGE_ID;
566567
}
567568

568569
/*

‎src/backend/access/hash/hashovfl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.54 2007/01/05 22:19:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.55 2007/04/09 22:03:57 tgl Exp $
1212
*
1313
* NOTES
1414
* Overflow pages look like ordinary relation pages.
@@ -141,7 +141,7 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf)
141141
ovflopaque->hasho_nextblkno=InvalidBlockNumber;
142142
ovflopaque->hasho_bucket=pageopaque->hasho_bucket;
143143
ovflopaque->hasho_flag=LH_OVERFLOW_PAGE;
144-
ovflopaque->hasho_filler=HASHO_FILL;
144+
ovflopaque->hasho_page_id=HASHO_PAGE_ID;
145145

146146
MarkBufferDirty(ovflbuf);
147147

@@ -529,7 +529,7 @@ _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno)
529529
op->hasho_nextblkno=InvalidBlockNumber;
530530
op->hasho_bucket=-1;
531531
op->hasho_flag=LH_BITMAP_PAGE;
532-
op->hasho_filler=HASHO_FILL;
532+
op->hasho_page_id=HASHO_PAGE_ID;
533533

534534
/* set all of the bits to 1 */
535535
freep=HashPageGetBitmap(pg);

‎src/backend/access/hash/hashpage.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.64 2007/01/29 23:22:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.65 2007/04/0922:03:57 tgl Exp $
1212
*
1313
* NOTES
1414
* Postgres hash pages look like ordinary relation pages. The opaque
@@ -252,7 +252,7 @@ _hash_metapinit(Relation rel)
252252
pageopaque->hasho_nextblkno=InvalidBlockNumber;
253253
pageopaque->hasho_bucket=-1;
254254
pageopaque->hasho_flag=LH_META_PAGE;
255-
pageopaque->hasho_filler=HASHO_FILL;
255+
pageopaque->hasho_page_id=HASHO_PAGE_ID;
256256

257257
metap= (HashMetaPage)pg;
258258

@@ -310,7 +310,7 @@ _hash_metapinit(Relation rel)
310310
pageopaque->hasho_nextblkno=InvalidBlockNumber;
311311
pageopaque->hasho_bucket=i;
312312
pageopaque->hasho_flag=LH_BUCKET_PAGE;
313-
pageopaque->hasho_filler=HASHO_FILL;
313+
pageopaque->hasho_page_id=HASHO_PAGE_ID;
314314
_hash_wrtbuf(rel,buf);
315315
}
316316

@@ -654,7 +654,7 @@ _hash_splitbucket(Relation rel,
654654
nopaque->hasho_nextblkno=InvalidBlockNumber;
655655
nopaque->hasho_bucket=nbucket;
656656
nopaque->hasho_flag=LH_BUCKET_PAGE;
657-
nopaque->hasho_filler=HASHO_FILL;
657+
nopaque->hasho_page_id=HASHO_PAGE_ID;
658658

659659
/*
660660
* Partition the tuples in the old bucket between the old bucket and the

‎src/backend/access/nbtree/nbtutils.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.84 2007/04/06 22:33:42 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.85 2007/04/09 22:04:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1263,11 +1263,13 @@ _bt_start_vacuum(Relation rel)
12631263

12641264
LWLockAcquire(BtreeVacuumLock,LW_EXCLUSIVE);
12651265

1266-
/* Assign the next cycle ID, being careful to avoid zero */
1267-
do
1268-
{
1269-
result=++(btvacinfo->cycle_ctr);
1270-
}while (result==0);
1266+
/*
1267+
* Assign the next cycle ID, being careful to avoid zero as well as
1268+
* the reserved high values.
1269+
*/
1270+
result=++(btvacinfo->cycle_ctr);
1271+
if (result==0||result>MAX_BT_CYCLE_ID)
1272+
result=btvacinfo->cycle_ctr=1;
12711273

12721274
/* Let's just make sure there's no entry already for this index */
12731275
for (i=0;i<btvacinfo->num_vacuums;i++)

‎src/include/access/gin.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* header file for postgres inverted index access method implementation.
44
*
55
*Copyright (c) 2006, PostgreSQL Global Development Group
6-
*$PostgreSQL: pgsql/src/include/access/gin.h,v 1.10 2007/01/31 15:09:45 teodor Exp $
6+
*$PostgreSQL: pgsql/src/include/access/gin.h,v 1.11 2007/04/09 22:04:04 tgl Exp $
77
*--------------------------------------------------------------------------
88
*/
99

@@ -31,41 +31,27 @@
3131
#defineGIN_CONSISTENT_PROC 4
3232
#defineGINNProcs 4
3333

34-
typedefXLogRecPtrGinNSN;
35-
3634
/*
3735
* Page opaque data in a inverted index page.
36+
*
37+
* Note: GIN does not include a page ID word as do the other index types.
38+
* This is OK because the opaque data is only 8 bytes and so can be reliably
39+
* distinguished by size. Revisit this if the size ever increases.
3840
*/
3941
typedefstructGinPageOpaqueData
4042
{
41-
uint16flags;
43+
BlockNumberrightlink;/* next page if any */
4244
OffsetNumbermaxoff;/* number entries on GIN_DATA page: number of
4345
* heap ItemPointer on GIN_DATA|GIN_LEAF page
4446
* and number of records on GIN_DATA &
4547
* ~GIN_LEAF page */
46-
BlockNumberrightlink;
48+
uint16flags;/* see bit definitions below */
4749
}GinPageOpaqueData;
4850

4951
typedefGinPageOpaqueData*GinPageOpaque;
5052

5153
#defineGIN_ROOT_BLKNO(0)
5254

53-
typedefstruct
54-
{
55-
BlockIdDatachild_blkno;/* use it instead of BlockNumber to save space
56-
* on page */
57-
ItemPointerDatakey;
58-
}PostingItem;
59-
60-
#definePostingItemGetBlockNumber(pointer) \
61-
BlockIdGetBlockNumber(&(pointer)->child_blkno)
62-
63-
#definePostingItemSetBlockNumber(pointer,blockNumber) \
64-
BlockIdSet(&((pointer)->child_blkno), (blockNumber))
65-
66-
/*
67-
* Page opaque data in a inverted index page.
68-
*/
6955
#defineGIN_DATA (1 << 0)
7056
#defineGIN_LEAF (1 << 1)
7157
#defineGIN_DELETED (1 << 2)
@@ -98,8 +84,21 @@ typedef struct
9884
#defineGinItemPointerGetOffsetNumber(pointer) \
9985
((pointer)->ip_posid)
10086

87+
typedefstruct
88+
{
89+
BlockIdDatachild_blkno;/* use it instead of BlockNumber to save space
90+
* on page */
91+
ItemPointerDatakey;
92+
}PostingItem;
93+
94+
#definePostingItemGetBlockNumber(pointer) \
95+
BlockIdGetBlockNumber(&(pointer)->child_blkno)
96+
97+
#definePostingItemSetBlockNumber(pointer,blockNumber) \
98+
BlockIdSet(&((pointer)->child_blkno), (blockNumber))
99+
101100
/*
102-
* Support work onIndexTuuple on leaf pages
101+
* Support work onIndexTuple on leaf pages
103102
*/
104103
#defineGinGetNPosting(itup)GinItemPointerGetOffsetNumber(&(itup)->t_tid)
105104
#defineGinSetNPosting(itup,n)ItemPointerSetOffsetNumber(&(itup)->t_tid,(n))

‎src/include/access/gist.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $PostgreSQL: pgsql/src/include/access/gist.h,v 1.57 2007/01/05 22:19:50 momjian Exp $
12+
* $PostgreSQL: pgsql/src/include/access/gist.h,v 1.58 2007/04/09 22:04:05 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -56,25 +56,30 @@
5656
/*
5757
* Page opaque data in a GiST index page.
5858
*/
59-
#defineF_LEAF(1 << 0)
60-
#defineF_DELETED(1 << 1)
59+
#defineF_LEAF(1 << 0)
60+
#defineF_DELETED(1 << 1)
6161
#defineF_TUPLES_DELETED(1 << 2)
6262

6363
typedefXLogRecPtrGistNSN;
6464

6565
typedefstructGISTPageOpaqueData
6666
{
67-
uint32flags;/* 29 bits are unused for now */
68-
BlockNumberrightlink;
69-
70-
/*
71-
* the only meaning - change this value if page split.
72-
*/
73-
GistNSNnsn;
67+
GistNSNnsn;/* this value must change on page split */
68+
BlockNumberrightlink;/* next page if any */
69+
uint16flags;/* see bit definitions above */
70+
uint16gist_page_id;/* for identification of GiST indexes */
7471
}GISTPageOpaqueData;
7572

7673
typedefGISTPageOpaqueData*GISTPageOpaque;
7774

75+
/*
76+
* The page ID is for the convenience of pg_filedump and similar utilities,
77+
* which otherwise would have a hard time telling pages of different index
78+
* types apart. It should be the last 2 bytes on the page. This is more or
79+
* less "free" due to alignment considerations.
80+
*/
81+
#defineGIST_PAGE_ID0xFF81
82+
7883
/*
7984
* This is the Split Vector to be returned by the PickSplit method.
8085
* PickSplit should check spl_(r|l)datum_exists. If it is 'true',

‎src/include/access/hash.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/hash.h,v 1.77 2007/04/02 03:49:40 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/hash.h,v 1.78 2007/04/09 22:04:05 tgl Exp $
1111
*
1212
* NOTES
1313
*modeled after Margo Seltzer's hash implementation for unix.
@@ -56,20 +56,18 @@ typedef struct HashPageOpaqueData
5656
BlockNumberhasho_nextblkno;/* next ovfl blkno */
5757
Buckethasho_bucket;/* bucket number this pg belongs to */
5858
uint16hasho_flag;/* page type code, see above */
59-
uint16hasho_filler;/* available for future use */
60-
61-
/*
62-
* We presently set hasho_filler to HASHO_FILL (0x1234); this is for the
63-
* convenience of pg_filedump, which otherwise would have a hard time
64-
* telling HashPageOpaqueData from BTPageOpaqueData. If we ever need that
65-
* space for some other purpose, pg_filedump will have to find another
66-
* way.
67-
*/
59+
uint16hasho_page_id;/* for identification of hash indexes */
6860
}HashPageOpaqueData;
6961

7062
typedefHashPageOpaqueData*HashPageOpaque;
7163

72-
#defineHASHO_FILL0x1234
64+
/*
65+
* The page ID is for the convenience of pg_filedump and similar utilities,
66+
* which otherwise would have a hard time telling pages of different index
67+
* types apart. It should be the last 2 bytes on the page. This is more or
68+
* less "free" due to alignment considerations.
69+
*/
70+
#defineHASHO_PAGE_ID0xFF80
7371

7472
/*
7573
*HashScanOpaqueData is private state for a hash index scan.

‎src/include/access/nbtree.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.111 2007/02/08 05:05:53 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.112 2007/04/09 22:04:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -40,8 +40,8 @@ typedef uint16 BTCycleId;
4040
*stored into both halves of the split page.(If VACUUM is not running,
4141
*both pages receive zero cycleids.)This allows VACUUM to detect whether
4242
*a page was split since it started, with a small probability of false match
43-
*if the page was last split some exact multiple of65536 VACUUMs ago.
44-
*Also, during a split, the BTP_SPLIT_END flag is cleared in the left
43+
*if the page was last split some exact multiple ofMAX_BT_CYCLE_ID VACUUMs
44+
*ago.Also, during a split, the BTP_SPLIT_END flag is cleared in the left
4545
*(original) page, and set in the right page, but only if the next page
4646
*to its right has a different cycleid.
4747
*
@@ -73,6 +73,15 @@ typedef BTPageOpaqueData *BTPageOpaque;
7373
#defineBTP_SPLIT_END(1 << 5)/* rightmost page of split group */
7474
#defineBTP_HAS_GARBAGE (1 << 6)/* page has LP_DELETEd tuples */
7575

76+
/*
77+
* The max allowed value of a cycle ID is a bit less than 64K. This is
78+
* for convenience of pg_filedump and similar utilities: we want to use
79+
* the last 2 bytes of special space as an index type indicator, and
80+
* restricting cycle ID lets btree use that space for vacuum cycle IDs
81+
* while still allowing index type to be identified.
82+
*/
83+
#defineMAX_BT_CYCLE_ID0xFF7F
84+
7685

7786
/*
7887
* The Meta page is always the first page in the btree index.

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.401 2007/04/06 22:33:43 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.402 2007/04/09 22:04:08 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200704061
56+
#defineCATALOG_VERSION_NO200704091
5757

5858
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp