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

Commit89bda95

Browse files
committed
Remove the 'slow' path for btree index build, which built the btree
incrementally by successive inserts rather than by sorting the data.We were only using the slow path during bootstrap, apparently becausewhen first written it failed during bootstrap --- but it works fine nowAFAICT. Removing it saves a hundred or so lines of code and producesnoticeably (~10%) smaller initial states of the system catalog indexes.While that won't make much difference for heavily-modified catalogs,for the more static ones there may be a useful long-term performanceimprovement.
1 parenta8b8f4d commit89bda95

File tree

4 files changed

+25
-161
lines changed

4 files changed

+25
-161
lines changed

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

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.94 2006/03/31 23:32:05 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.95 2006/04/01 03:03:36 tgl Exp $
1313
*
1414
*NOTES
1515
* Postgres btree pages look like ordinary relation pages.The opaque
@@ -28,73 +28,6 @@
2828
#include"storage/lmgr.h"
2929

3030

31-
/*
32-
*_bt_metapinit() -- Initialize the metadata page of a new btree.
33-
*
34-
* Note: this is actually not used for standard btree index building;
35-
* nbtsort.c prefers not to make the metadata page valid until completion
36-
* of build.
37-
*
38-
* Note: there's no real need for any locking here. Since the transaction
39-
* creating the index hasn't committed yet, no one else can even see the index
40-
* much less be trying to use it. (In a REINDEX-in-place scenario, that's
41-
* not true, but we assume the caller holds sufficient locks on the index.)
42-
*/
43-
void
44-
_bt_metapinit(Relationrel)
45-
{
46-
Bufferbuf;
47-
Pagepg;
48-
BTMetaPageData*metad;
49-
50-
if (RelationGetNumberOfBlocks(rel)!=0)
51-
elog(ERROR,"cannot initialize non-empty btree index \"%s\"",
52-
RelationGetRelationName(rel));
53-
54-
buf=ReadBuffer(rel,P_NEW);
55-
Assert(BufferGetBlockNumber(buf)==BTREE_METAPAGE);
56-
LockBuffer(buf,BT_WRITE);
57-
pg=BufferGetPage(buf);
58-
59-
/* NO ELOG(ERROR) from here till newmeta op is logged */
60-
START_CRIT_SECTION();
61-
62-
_bt_initmetapage(pg,P_NONE,0);
63-
metad=BTPageGetMeta(pg);
64-
65-
MarkBufferDirty(buf);
66-
67-
/* XLOG stuff */
68-
if (!rel->rd_istemp)
69-
{
70-
xl_btree_newmetaxlrec;
71-
XLogRecPtrrecptr;
72-
XLogRecDatardata[1];
73-
74-
xlrec.node=rel->rd_node;
75-
xlrec.meta.root=metad->btm_root;
76-
xlrec.meta.level=metad->btm_level;
77-
xlrec.meta.fastroot=metad->btm_fastroot;
78-
xlrec.meta.fastlevel=metad->btm_fastlevel;
79-
80-
rdata[0].data= (char*)&xlrec;
81-
rdata[0].len=SizeOfBtreeNewmeta;
82-
rdata[0].buffer=InvalidBuffer;
83-
rdata[0].next=NULL;
84-
85-
recptr=XLogInsert(RM_BTREE_ID,
86-
XLOG_BTREE_NEWMETA,
87-
rdata);
88-
89-
PageSetLSN(pg,recptr);
90-
PageSetTLI(pg,ThisTimeLineID);
91-
}
92-
93-
END_CRIT_SECTION();
94-
95-
UnlockReleaseBuffer(buf);
96-
}
97-
9831
/*
9932
*_bt_initmetapage() -- Fill a page buffer with a correct metapage image
10033
*/

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

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.143 2006/03/31 23:32:05 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.144 2006/04/01 03:03:37 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -32,7 +32,6 @@
3232
/* Working state for btbuild and its callback */
3333
typedefstruct
3434
{
35-
boolusefast;
3635
boolisUnique;
3736
boolhaveDead;
3837
RelationheapRel;
@@ -48,8 +47,6 @@ typedef struct
4847
}BTBuildState;
4948

5049

51-
boolFastBuild= true;/* use SORT instead of insertion build */
52-
5350
staticvoid_bt_restscan(IndexScanDescscan);
5451
staticvoidbtbuildCallback(Relationindex,
5552
HeapTuplehtup,
@@ -71,13 +68,6 @@ btbuild(PG_FUNCTION_ARGS)
7168
doublereltuples;
7269
BTBuildStatebuildstate;
7370

74-
/*
75-
* bootstrap processing does something strange, so don't use sort/build
76-
* for initial catalog indices. at some point i need to look harder at
77-
* this. (there is some kind of incremental processing going on there.)
78-
* -- pma 08/29/95
79-
*/
80-
buildstate.usefast= (FastBuild&&IsNormalProcessingMode());
8171
buildstate.isUnique=indexInfo->ii_Unique;
8272
buildstate.haveDead= false;
8373
buildstate.heapRel=heap;
@@ -98,22 +88,14 @@ btbuild(PG_FUNCTION_ARGS)
9888
elog(ERROR,"index \"%s\" already contains data",
9989
RelationGetRelationName(index));
10090

101-
if (buildstate.usefast)
102-
{
103-
buildstate.spool=_bt_spoolinit(index,indexInfo->ii_Unique, false);
91+
buildstate.spool=_bt_spoolinit(index,indexInfo->ii_Unique, false);
10492

105-
/*
106-
* If building a unique index, put dead tuples in a second spool to
107-
* keep them out of the uniqueness check.
108-
*/
109-
if (indexInfo->ii_Unique)
110-
buildstate.spool2=_bt_spoolinit(index, false, true);
111-
}
112-
else
113-
{
114-
/* if using slow build, initialize the btree index metadata page */
115-
_bt_metapinit(index);
116-
}
93+
/*
94+
* If building a unique index, put dead tuples in a second spool to
95+
* keep them out of the uniqueness check.
96+
*/
97+
if (indexInfo->ii_Unique)
98+
buildstate.spool2=_bt_spoolinit(index, false, true);
11799

118100
/* do the heap scan */
119101
reltuples=IndexBuildHeapScan(heap,index,indexInfo,
@@ -128,17 +110,14 @@ btbuild(PG_FUNCTION_ARGS)
128110
}
129111

130112
/*
131-
*if we are doing bottom-up btree build, finishthebuild by (1)
132-
*completing thesort of the spool file, (2) inserting thesorted tuples
133-
*into btree pages and (3) building the upperlevels.
113+
*Finish the build by (1) completing the sort ofthespool file, (2)
114+
*inserting thesorted tuples into btree pages and (3) building theupper
115+
* levels.
134116
*/
135-
if (buildstate.usefast)
136-
{
137-
_bt_leafbuild(buildstate.spool,buildstate.spool2);
138-
_bt_spooldestroy(buildstate.spool);
139-
if (buildstate.spool2)
140-
_bt_spooldestroy(buildstate.spool2);
141-
}
117+
_bt_leafbuild(buildstate.spool,buildstate.spool2);
118+
_bt_spooldestroy(buildstate.spool);
119+
if (buildstate.spool2)
120+
_bt_spooldestroy(buildstate.spool2);
142121

143122
#ifdefBTREE_BUILD_STATS
144123
if (log_btree_build_stats)
@@ -173,24 +152,16 @@ btbuildCallback(Relation index,
173152
itup->t_tid=htup->t_self;
174153

175154
/*
176-
*if we are doing bottom-up btree build, weinsert the index intoaspool
177-
*file for subsequentprocessing.otherwise, we insert into the btree.
155+
* insert the indextupleintothe appropriatespool file for subsequent
156+
* processing
178157
*/
179-
if (buildstate->usefast)
180-
{
181-
if (tupleIsAlive||buildstate->spool2==NULL)
182-
_bt_spool(itup,buildstate->spool);
183-
else
184-
{
185-
/* dead tuples are put into spool2 */
186-
buildstate->haveDead= true;
187-
_bt_spool(itup,buildstate->spool2);
188-
}
189-
}
158+
if (tupleIsAlive||buildstate->spool2==NULL)
159+
_bt_spool(itup,buildstate->spool);
190160
else
191161
{
192-
_bt_doinsert(index,itup,
193-
buildstate->isUnique,buildstate->heapRel);
162+
/* dead tuples are put into spool2 */
163+
buildstate->haveDead= true;
164+
_bt_spool(itup,buildstate->spool2);
194165
}
195166

196167
buildstate->indtuples+=1;

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

Lines changed: 1 addition & 27 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/nbtree/nbtxlog.c,v 1.30 2006/03/31 23:32:05 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtxlog.c,v 1.31 2006/04/01 03:03:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -556,18 +556,6 @@ btree_xlog_newroot(XLogRecPtr lsn, XLogRecord *record)
556556
}
557557
}
558558

559-
staticvoid
560-
btree_xlog_newmeta(XLogRecPtrlsn,XLogRecord*record)
561-
{
562-
xl_btree_newmeta*xlrec= (xl_btree_newmeta*)XLogRecGetData(record);
563-
Relationreln;
564-
565-
reln=XLogOpenRelation(xlrec->node);
566-
_bt_restore_meta(reln,lsn,
567-
xlrec->meta.root,xlrec->meta.level,
568-
xlrec->meta.fastroot,xlrec->meta.fastlevel);
569-
}
570-
571559

572560
void
573561
btree_redo(XLogRecPtrlsn,XLogRecord*record)
@@ -609,9 +597,6 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
609597
caseXLOG_BTREE_NEWROOT:
610598
btree_xlog_newroot(lsn,record);
611599
break;
612-
caseXLOG_BTREE_NEWMETA:
613-
btree_xlog_newmeta(lsn,record);
614-
break;
615600
default:
616601
elog(PANIC,"btree_redo: unknown op code %u",info);
617602
}
@@ -727,17 +712,6 @@ btree_desc(StringInfo buf, uint8 xl_info, char *rec)
727712
xlrec->rootblk,xlrec->level);
728713
break;
729714
}
730-
caseXLOG_BTREE_NEWMETA:
731-
{
732-
xl_btree_newmeta*xlrec= (xl_btree_newmeta*)rec;
733-
734-
appendStringInfo(buf,"newmeta: rel %u/%u/%u; root %u lev %u fast %u lev %u",
735-
xlrec->node.spcNode,xlrec->node.dbNode,
736-
xlrec->node.relNode,
737-
xlrec->meta.root,xlrec->meta.level,
738-
xlrec->meta.fastroot,xlrec->meta.fastlevel);
739-
break;
740-
}
741715
default:
742716
appendStringInfo(buf,"UNKNOWN");
743717
break;

‎src/include/access/nbtree.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2006, 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.94 2006/03/31 23:32:06 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.95 2006/04/01 03:03:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -176,7 +176,6 @@ typedef struct BTMetaPageData
176176
#defineXLOG_BTREE_DELETE_PAGE0x80/* delete an entire page */
177177
#defineXLOG_BTREE_DELETE_PAGE_META 0x90/* same, plus update metapage */
178178
#defineXLOG_BTREE_NEWROOT0xA0/* new root page */
179-
#defineXLOG_BTREE_NEWMETA0xB0/* update metadata page */
180179

181180
/*
182181
* All that we need to find changed index tuple
@@ -291,18 +290,6 @@ typedef struct xl_btree_newroot
291290

292291
#defineSizeOfBtreeNewroot(offsetof(xl_btree_newroot, level) + sizeof(uint32))
293292

294-
/*
295-
* New metapage log record. This is not issued during routine operations;
296-
* it's only used when initializing an empty index.
297-
*/
298-
typedefstructxl_btree_newmeta
299-
{
300-
RelFileNodenode;
301-
xl_btree_metadatameta;
302-
}xl_btree_newmeta;
303-
304-
#defineSizeOfBtreeNewmeta(sizeof(xl_btree_newmeta))
305-
306293

307294
/*
308295
*Operator strategy numbers for B-tree have been moved to access/skey.h,
@@ -410,7 +397,6 @@ extern void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf,
410397
/*
411398
* prototypes for functions in nbtpage.c
412399
*/
413-
externvoid_bt_metapinit(Relationrel);
414400
externvoid_bt_initmetapage(Pagepage,BlockNumberrootbknum,uint32level);
415401
externBuffer_bt_getroot(Relationrel,intaccess);
416402
externBuffer_bt_gettrueroot(Relationrel);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp