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

Commit3140437

Browse files
author
Neil Conway
committed
This patch refactors away some duplicated code in the index AM build
methods: they all invoke UpdateStats() since they have computed thenumber of heap tuples, so I created a function in catalog/index.c thateach AM now calls.
1 parentff868d8 commit3140437

File tree

6 files changed

+48
-92
lines changed

6 files changed

+48
-92
lines changed

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

Lines changed: 3 additions & 22 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/gist.c,v 1.113 2005/03/21 01:23:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.114 2005/05/11 06:24:50 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -184,27 +184,8 @@ gistbuild(PG_FUNCTION_ARGS)
184184

185185
/* okay, all heap tuples are indexed */
186186

187-
/*
188-
* Since we just counted the tuples in the heap, we update its stats
189-
* in pg_class to guarantee that the planner takes advantage of the
190-
* index we just created. But, only update statistics during normal
191-
* index definitions, not for indices on system catalogs created
192-
* during bootstrap processing. We must close the relations before
193-
* updating statistics to guarantee that the relcache entries are
194-
* flushed when we increment the command counter in UpdateStats(). But
195-
* we do not release any locks on the relations; those will be held
196-
* until end of transaction.
197-
*/
198-
if (IsNormalProcessingMode())
199-
{
200-
Oidhrelid=RelationGetRelid(heap);
201-
Oidirelid=RelationGetRelid(index);
202-
203-
heap_close(heap,NoLock);
204-
index_close(index);
205-
UpdateStats(hrelid,reltuples);
206-
UpdateStats(irelid,buildstate.indtuples);
207-
}
187+
/* since we just counted the # of tuples, may as well update stats */
188+
IndexCloseAndUpdateStats(heap,reltuples,index,buildstate.indtuples);
208189

209190
freeGISTstate(&buildstate.giststate);
210191
#ifdefGISTDEBUG

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.78 2005/03/27 23:52:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.79 2005/05/11 06:24:51 neilc Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -72,27 +72,8 @@ hashbuild(PG_FUNCTION_ARGS)
7272
reltuples=IndexBuildHeapScan(heap,index,indexInfo,
7373
hashbuildCallback, (void*)&buildstate);
7474

75-
/*
76-
* Since we just counted the tuples in the heap, we update its stats
77-
* in pg_class to guarantee that the planner takes advantage of the
78-
* index we just created. But, only update statistics during normal
79-
* index definitions, not for indices on system catalogs created
80-
* during bootstrap processing. We must close the relations before
81-
* updating statistics to guarantee that the relcache entries are
82-
* flushed when we increment the command counter in UpdateStats(). But
83-
* we do not release any locks on the relations; those will be held
84-
* until end of transaction.
85-
*/
86-
if (IsNormalProcessingMode())
87-
{
88-
Oidhrelid=RelationGetRelid(heap);
89-
Oidirelid=RelationGetRelid(index);
90-
91-
heap_close(heap,NoLock);
92-
index_close(index);
93-
UpdateStats(hrelid,reltuples);
94-
UpdateStats(irelid,buildstate.indtuples);
95-
}
75+
/* since we just counted the # of tuples, may as well update stats */
76+
IndexCloseAndUpdateStats(heap,reltuples,index,buildstate.indtuples);
9677

9778
PG_RETURN_VOID();
9879
}

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

Lines changed: 3 additions & 22 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.129 2005/05/07 21:32:23 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.130 2005/05/11 06:24:53 neilc Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -148,27 +148,8 @@ btbuild(PG_FUNCTION_ARGS)
148148
}
149149
#endif/* BTREE_BUILD_STATS */
150150

151-
/*
152-
* Since we just counted the tuples in the heap, we update its stats
153-
* in pg_class to guarantee that the planner takes advantage of the
154-
* index we just created. But, only update statistics during normal
155-
* index definitions, not for indices on system catalogs created
156-
* during bootstrap processing. We must close the relations before
157-
* updating statistics to guarantee that the relcache entries are
158-
* flushed when we increment the command counter in UpdateStats(). But
159-
* we do not release any locks on the relations; those will be held
160-
* until end of transaction.
161-
*/
162-
if (IsNormalProcessingMode())
163-
{
164-
Oidhrelid=RelationGetRelid(heap);
165-
Oidirelid=RelationGetRelid(index);
166-
167-
heap_close(heap,NoLock);
168-
index_close(index);
169-
UpdateStats(hrelid,reltuples);
170-
UpdateStats(irelid,buildstate.indtuples);
171-
}
151+
/* since we just counted the # of tuples, may as well update stats */
152+
IndexCloseAndUpdateStats(heap,reltuples,index,buildstate.indtuples);
172153

173154
PG_RETURN_VOID();
174155
}

‎src/backend/access/rtree/rtree.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.88 2005/03/21 01:24:00 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.89 2005/05/11 06:24:54 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -142,27 +142,8 @@ rtbuild(PG_FUNCTION_ARGS)
142142

143143
/* okay, all heap tuples are indexed */
144144

145-
/*
146-
* Since we just counted the tuples in the heap, we update its stats
147-
* in pg_class to guarantee that the planner takes advantage of the
148-
* index we just created. But, only update statistics during normal
149-
* index definitions, not for indices on system catalogs created
150-
* during bootstrap processing. We must close the relations before
151-
* updating statistics to guarantee that the relcache entries are
152-
* flushed when we increment the command counter in UpdateStats(). But
153-
* we do not release any locks on the relations; those will be held
154-
* until end of transaction.
155-
*/
156-
if (IsNormalProcessingMode())
157-
{
158-
Oidhrelid=RelationGetRelid(heap);
159-
Oidirelid=RelationGetRelid(index);
160-
161-
heap_close(heap,NoLock);
162-
index_close(index);
163-
UpdateStats(hrelid,reltuples);
164-
UpdateStats(irelid,buildstate.indtuples);
165-
}
145+
/* since we just counted the # of tuples, may as well update stats */
146+
IndexCloseAndUpdateStats(heap,reltuples,index,buildstate.indtuples);
166147

167148
PG_RETURN_VOID();
168149
}

‎src/backend/catalog/index.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.254 2005/05/06 17:24:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.255 2005/05/11 06:24:54 neilc Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -62,6 +62,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
6262
Oid*classOids,
6363
boolprimary);
6464
staticOidIndexGetRelation(OidindexId);
65+
staticvoidUpdateStats(Oidrelid,doublereltuples);
6566

6667

6768
/*
@@ -1149,6 +1150,36 @@ setNewRelfilenode(Relation relation)
11491150
}
11501151

11511152

1153+
/*
1154+
* This is invoked by the various index AMs once they have finished
1155+
* constructing an index. Constructing an index involves counting the
1156+
* number of tuples in both the relation and the index, so we take
1157+
* advantage of the opportunity to update pg_class to ensure that the
1158+
* planner takes advantage of the index we just created. But, only
1159+
* update statistics during normal index definitions, not for indices
1160+
* on system catalogs created during bootstrap processing. We must
1161+
* close the relations before updating statistics to guarantee that
1162+
* the relcache entries are flushed when we increment the command
1163+
* counter in UpdateStats(). But we do not release any locks on the
1164+
* relations; those will be held until end of transaction.
1165+
*/
1166+
void
1167+
IndexCloseAndUpdateStats(Relationheap,doubleheapTuples,
1168+
Relationindex,doubleindexTuples)
1169+
{
1170+
Oidhrelid=RelationGetRelid(heap);
1171+
Oidirelid=RelationGetRelid(index);
1172+
1173+
if (!IsNormalProcessingMode())
1174+
return;
1175+
1176+
heap_close(heap,NoLock);
1177+
index_close(index);
1178+
UpdateStats(hrelid,heapTuples);
1179+
UpdateStats(irelid,indexTuples);
1180+
}
1181+
1182+
11521183
/* ----------------
11531184
*UpdateStats
11541185
*
@@ -1157,7 +1188,7 @@ setNewRelfilenode(Relation relation)
11571188
* in the context of VACUUM, only CREATE INDEX.
11581189
* ----------------
11591190
*/
1160-
void
1191+
staticvoid
11611192
UpdateStats(Oidrelid,doublereltuples)
11621193
{
11631194
RelationwhichRel;

‎src/include/catalog/index.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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/catalog/index.h,v 1.62 2005/04/14 01:38:20 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.63 2005/05/11 06:24:55 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -52,7 +52,8 @@ extern void FormIndexDatum(IndexInfo *indexInfo,
5252
Datum*values,
5353
bool*isnull);
5454

55-
externvoidUpdateStats(Oidrelid,doublereltuples);
55+
externvoidIndexCloseAndUpdateStats(Relationheap,doubleheapTuples,
56+
Relationindex,doubleindexTuples);
5657

5758
externvoidsetRelhasindex(Oidrelid,boolhasindex,
5859
boolisprimary,Oidreltoastidxid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp