This patch refactors away some duplicated code in the index AM build
methods: they all invoke UpdateStats() since they have computed the number of heap tuples, so I created a function in catalog/index.c that each AM now calls.
This commit is contained in:
parent
ff868d8161
commit
3140437495
|
@ -8,7 +8,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.113 2005/03/21 01:23:56 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.114 2005/05/11 06:24:50 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -184,27 +184,8 @@ gistbuild(PG_FUNCTION_ARGS)
|
||||||
|
|
||||||
/* okay, all heap tuples are indexed */
|
/* okay, all heap tuples are indexed */
|
||||||
|
|
||||||
/*
|
/* since we just counted the # of tuples, may as well update stats */
|
||||||
* Since we just counted the tuples in the heap, we update its stats
|
IndexCloseAndUpdateStats(heap, reltuples, index, buildstate.indtuples);
|
||||||
* in pg_class to guarantee that the planner takes advantage of the
|
|
||||||
* index we just created. But, only update statistics during normal
|
|
||||||
* index definitions, not for indices on system catalogs created
|
|
||||||
* during bootstrap processing. We must close the relations before
|
|
||||||
* updating statistics to guarantee that the relcache entries are
|
|
||||||
* flushed when we increment the command counter in UpdateStats(). But
|
|
||||||
* we do not release any locks on the relations; those will be held
|
|
||||||
* until end of transaction.
|
|
||||||
*/
|
|
||||||
if (IsNormalProcessingMode())
|
|
||||||
{
|
|
||||||
Oid hrelid = RelationGetRelid(heap);
|
|
||||||
Oid irelid = RelationGetRelid(index);
|
|
||||||
|
|
||||||
heap_close(heap, NoLock);
|
|
||||||
index_close(index);
|
|
||||||
UpdateStats(hrelid, reltuples);
|
|
||||||
UpdateStats(irelid, buildstate.indtuples);
|
|
||||||
}
|
|
||||||
|
|
||||||
freeGISTstate(&buildstate.giststate);
|
freeGISTstate(&buildstate.giststate);
|
||||||
#ifdef GISTDEBUG
|
#ifdef GISTDEBUG
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.78 2005/03/27 23:52:57 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.79 2005/05/11 06:24:51 neilc Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* This file contains only the public interface routines.
|
* This file contains only the public interface routines.
|
||||||
|
@ -72,27 +72,8 @@ hashbuild(PG_FUNCTION_ARGS)
|
||||||
reltuples = IndexBuildHeapScan(heap, index, indexInfo,
|
reltuples = IndexBuildHeapScan(heap, index, indexInfo,
|
||||||
hashbuildCallback, (void *) &buildstate);
|
hashbuildCallback, (void *) &buildstate);
|
||||||
|
|
||||||
/*
|
/* since we just counted the # of tuples, may as well update stats */
|
||||||
* Since we just counted the tuples in the heap, we update its stats
|
IndexCloseAndUpdateStats(heap, reltuples, index, buildstate.indtuples);
|
||||||
* in pg_class to guarantee that the planner takes advantage of the
|
|
||||||
* index we just created. But, only update statistics during normal
|
|
||||||
* index definitions, not for indices on system catalogs created
|
|
||||||
* during bootstrap processing. We must close the relations before
|
|
||||||
* updating statistics to guarantee that the relcache entries are
|
|
||||||
* flushed when we increment the command counter in UpdateStats(). But
|
|
||||||
* we do not release any locks on the relations; those will be held
|
|
||||||
* until end of transaction.
|
|
||||||
*/
|
|
||||||
if (IsNormalProcessingMode())
|
|
||||||
{
|
|
||||||
Oid hrelid = RelationGetRelid(heap);
|
|
||||||
Oid irelid = RelationGetRelid(index);
|
|
||||||
|
|
||||||
heap_close(heap, NoLock);
|
|
||||||
index_close(index);
|
|
||||||
UpdateStats(hrelid, reltuples);
|
|
||||||
UpdateStats(irelid, buildstate.indtuples);
|
|
||||||
}
|
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.129 2005/05/07 21:32:23 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.130 2005/05/11 06:24:53 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -148,27 +148,8 @@ btbuild(PG_FUNCTION_ARGS)
|
||||||
}
|
}
|
||||||
#endif /* BTREE_BUILD_STATS */
|
#endif /* BTREE_BUILD_STATS */
|
||||||
|
|
||||||
/*
|
/* since we just counted the # of tuples, may as well update stats */
|
||||||
* Since we just counted the tuples in the heap, we update its stats
|
IndexCloseAndUpdateStats(heap, reltuples, index, buildstate.indtuples);
|
||||||
* in pg_class to guarantee that the planner takes advantage of the
|
|
||||||
* index we just created. But, only update statistics during normal
|
|
||||||
* index definitions, not for indices on system catalogs created
|
|
||||||
* during bootstrap processing. We must close the relations before
|
|
||||||
* updating statistics to guarantee that the relcache entries are
|
|
||||||
* flushed when we increment the command counter in UpdateStats(). But
|
|
||||||
* we do not release any locks on the relations; those will be held
|
|
||||||
* until end of transaction.
|
|
||||||
*/
|
|
||||||
if (IsNormalProcessingMode())
|
|
||||||
{
|
|
||||||
Oid hrelid = RelationGetRelid(heap);
|
|
||||||
Oid irelid = RelationGetRelid(index);
|
|
||||||
|
|
||||||
heap_close(heap, NoLock);
|
|
||||||
index_close(index);
|
|
||||||
UpdateStats(hrelid, reltuples);
|
|
||||||
UpdateStats(irelid, buildstate.indtuples);
|
|
||||||
}
|
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.88 2005/03/21 01:24:00 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.89 2005/05/11 06:24:54 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -142,27 +142,8 @@ rtbuild(PG_FUNCTION_ARGS)
|
||||||
|
|
||||||
/* okay, all heap tuples are indexed */
|
/* okay, all heap tuples are indexed */
|
||||||
|
|
||||||
/*
|
/* since we just counted the # of tuples, may as well update stats */
|
||||||
* Since we just counted the tuples in the heap, we update its stats
|
IndexCloseAndUpdateStats(heap, reltuples, index, buildstate.indtuples);
|
||||||
* in pg_class to guarantee that the planner takes advantage of the
|
|
||||||
* index we just created. But, only update statistics during normal
|
|
||||||
* index definitions, not for indices on system catalogs created
|
|
||||||
* during bootstrap processing. We must close the relations before
|
|
||||||
* updating statistics to guarantee that the relcache entries are
|
|
||||||
* flushed when we increment the command counter in UpdateStats(). But
|
|
||||||
* we do not release any locks on the relations; those will be held
|
|
||||||
* until end of transaction.
|
|
||||||
*/
|
|
||||||
if (IsNormalProcessingMode())
|
|
||||||
{
|
|
||||||
Oid hrelid = RelationGetRelid(heap);
|
|
||||||
Oid irelid = RelationGetRelid(index);
|
|
||||||
|
|
||||||
heap_close(heap, NoLock);
|
|
||||||
index_close(index);
|
|
||||||
UpdateStats(hrelid, reltuples);
|
|
||||||
UpdateStats(irelid, buildstate.indtuples);
|
|
||||||
}
|
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.254 2005/05/06 17:24:52 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.255 2005/05/11 06:24:54 neilc Exp $
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* INTERFACE ROUTINES
|
* INTERFACE ROUTINES
|
||||||
|
@ -62,6 +62,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
|
||||||
Oid *classOids,
|
Oid *classOids,
|
||||||
bool primary);
|
bool primary);
|
||||||
static Oid IndexGetRelation(Oid indexId);
|
static Oid IndexGetRelation(Oid indexId);
|
||||||
|
static void UpdateStats(Oid relid, double reltuples);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1149,6 +1150,36 @@ setNewRelfilenode(Relation relation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is invoked by the various index AMs once they have finished
|
||||||
|
* constructing an index. Constructing an index involves counting the
|
||||||
|
* number of tuples in both the relation and the index, so we take
|
||||||
|
* advantage of the opportunity to update pg_class to ensure that the
|
||||||
|
* planner takes advantage of the index we just created. But, only
|
||||||
|
* update statistics during normal index definitions, not for indices
|
||||||
|
* on system catalogs created during bootstrap processing. We must
|
||||||
|
* close the relations before updating statistics to guarantee that
|
||||||
|
* the relcache entries are flushed when we increment the command
|
||||||
|
* counter in UpdateStats(). But we do not release any locks on the
|
||||||
|
* relations; those will be held until end of transaction.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
IndexCloseAndUpdateStats(Relation heap, double heapTuples,
|
||||||
|
Relation index, double indexTuples)
|
||||||
|
{
|
||||||
|
Oid hrelid = RelationGetRelid(heap);
|
||||||
|
Oid irelid = RelationGetRelid(index);
|
||||||
|
|
||||||
|
if (!IsNormalProcessingMode())
|
||||||
|
return;
|
||||||
|
|
||||||
|
heap_close(heap, NoLock);
|
||||||
|
index_close(index);
|
||||||
|
UpdateStats(hrelid, heapTuples);
|
||||||
|
UpdateStats(irelid, indexTuples);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* UpdateStats
|
* UpdateStats
|
||||||
*
|
*
|
||||||
|
@ -1157,7 +1188,7 @@ setNewRelfilenode(Relation relation)
|
||||||
* in the context of VACUUM, only CREATE INDEX.
|
* in the context of VACUUM, only CREATE INDEX.
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
UpdateStats(Oid relid, double reltuples)
|
UpdateStats(Oid relid, double reltuples)
|
||||||
{
|
{
|
||||||
Relation whichRel;
|
Relation whichRel;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.62 2005/04/14 01:38:20 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.63 2005/05/11 06:24:55 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,8 @@ extern void FormIndexDatum(IndexInfo *indexInfo,
|
||||||
Datum *values,
|
Datum *values,
|
||||||
bool *isnull);
|
bool *isnull);
|
||||||
|
|
||||||
extern void UpdateStats(Oid relid, double reltuples);
|
extern void IndexCloseAndUpdateStats(Relation heap, double heapTuples,
|
||||||
|
Relation index, double indexTuples);
|
||||||
|
|
||||||
extern void setRelhasindex(Oid relid, bool hasindex,
|
extern void setRelhasindex(Oid relid, bool hasindex,
|
||||||
bool isprimary, Oid reltoastidxid);
|
bool isprimary, Oid reltoastidxid);
|
||||||
|
|
Loading…
Reference in New Issue