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

Commitd2914c3

Browse files
committed
Delete pg_statistics rows for a relation during heap_destroy_with_catalog.
By dropping stats rows here, we eliminate the need for VACUUM to do awholesale remove of stats rows. Before, pg_statistics was wiped cleanat the start of VACUUM, ensuring poor planning results for any backendsrunning in parallel until VACUUM got around to rebuilding the stats forthe relations they are accessing.
1 parent0ffe17a commitd2914c3

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

‎src/backend/catalog/heap.c

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.110 1999/11/24 00:44:29 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.111 1999/11/28 02:03:04 tgl Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -44,6 +44,7 @@
4444
#include"catalog/pg_ipl.h"
4545
#include"catalog/pg_proc.h"
4646
#include"catalog/pg_relcheck.h"
47+
#include"catalog/pg_statistic.h"
4748
#include"catalog/pg_type.h"
4849
#include"commands/comment.h"
4950
#include"commands/trigger.h"
@@ -82,6 +83,7 @@ static void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
8283
staticvoidStoreRelCheck(Relationrel,char*ccname,char*ccbin);
8384
staticvoidStoreConstraints(Relationrel);
8485
staticvoidRemoveConstraints(Relationrel);
86+
staticvoidRemoveStatistics(Relationrel);
8587

8688

8789
/* ----------------------------------------------------------------
@@ -1232,7 +1234,7 @@ heap_truncate(char *relname)
12321234
/* Open relation for processing, and grab exclusive access on it. */
12331235

12341236
rel=heap_openr(relname,AccessExclusiveLock);
1235-
rid=rel->rd_id;
1237+
rid=RelationGetRelid(rel);
12361238

12371239
/* ----------------
12381240
*TRUNCATE TABLE within a transaction block is dangerous, because
@@ -1455,7 +1457,7 @@ heap_destroy_with_catalog(char *relname)
14551457
* ----------------
14561458
*/
14571459
rel=heap_openr(relname,AccessExclusiveLock);
1458-
rid=rel->rd_id;
1460+
rid=RelationGetRelid(rel);
14591461

14601462
/* ----------------
14611463
*prevent deletion of system relations
@@ -1512,12 +1514,17 @@ heap_destroy_with_catalog(char *relname)
15121514
DeleteAttributeTuples(rel);
15131515

15141516
/* ----------------
1515-
* delete comments
1516-
* ----------------
1517-
*/
1518-
1517+
*delete comments
1518+
* ----------------
1519+
*/
15191520
DeleteComments(RelationGetRelid(rel));
15201521

1522+
/* ----------------
1523+
*delete statistics
1524+
* ----------------
1525+
*/
1526+
RemoveStatistics(rel);
1527+
15211528
/* ----------------
15221529
*delete type tuple.here we want to see the effects
15231530
*of the deletions we just did, so we use setheapoverride().
@@ -1731,7 +1738,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
17311738
rte->skipAcl= false;
17321739
adsrc=deparse_expression(expr,lcons(lcons(rte,NIL),NIL), false);
17331740

1734-
values[Anum_pg_attrdef_adrelid-1]=rel->rd_id;
1741+
values[Anum_pg_attrdef_adrelid-1]=RelationGetRelid(rel);
17351742
values[Anum_pg_attrdef_adnum-1]=attnum;
17361743
values[Anum_pg_attrdef_adbin-1]=PointerGetDatum(textin(adbin));
17371744
values[Anum_pg_attrdef_adsrc-1]=PointerGetDatum(textin(adsrc));
@@ -1754,11 +1761,11 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
17541761

17551762
attrrel=heap_openr(AttributeRelationName,RowExclusiveLock);
17561763
atttup=SearchSysCacheTupleCopy(ATTNUM,
1757-
ObjectIdGetDatum(rel->rd_id),
1764+
ObjectIdGetDatum(RelationGetRelid(rel)),
17581765
(Datum)attnum,0,0);
17591766
if (!HeapTupleIsValid(atttup))
17601767
elog(ERROR,"cache lookup of attribute %d in relation %u failed",
1761-
attnum,rel->rd_id);
1768+
attnum,RelationGetRelid(rel));
17621769
attStruct= (Form_pg_attribute)GETSTRUCT(atttup);
17631770
if (!attStruct->atthasdef)
17641771
{
@@ -1810,7 +1817,7 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
18101817
rte->skipAcl= false;
18111818
ccsrc=deparse_expression(expr,lcons(lcons(rte,NIL),NIL), false);
18121819

1813-
values[Anum_pg_relcheck_rcrelid-1]=rel->rd_id;
1820+
values[Anum_pg_relcheck_rcrelid-1]=RelationGetRelid(rel);
18141821
values[Anum_pg_relcheck_rcname-1]=PointerGetDatum(namein(ccname));
18151822
values[Anum_pg_relcheck_rcbin-1]=PointerGetDatum(textin(ccbin));
18161823
values[Anum_pg_relcheck_rcsrc-1]=PointerGetDatum(textin(ccsrc));
@@ -2077,10 +2084,10 @@ AddRelationRawConstraints(Relation rel,
20772084
*/
20782085
relrel=heap_openr(RelationRelationName,RowExclusiveLock);
20792086
reltup=SearchSysCacheTupleCopy(RELOID,
2080-
ObjectIdGetDatum(rel->rd_id),
2087+
ObjectIdGetDatum(RelationGetRelid(rel)),
20812088
0,0,0);
20822089
if (!HeapTupleIsValid(reltup))
2083-
elog(ERROR,"cache lookup of relation %u failed",rel->rd_id);
2090+
elog(ERROR,"cache lookup of relation %u failed",RelationGetRelid(rel));
20842091
relStruct= (Form_pg_class)GETSTRUCT(reltup);
20852092

20862093
relStruct->relchecks=numchecks;
@@ -2120,7 +2127,7 @@ RemoveAttrDefault(Relation rel)
21202127
adrel=heap_openr(AttrDefaultRelationName,RowExclusiveLock);
21212128

21222129
ScanKeyEntryInitialize(&key,0,Anum_pg_attrdef_adrelid,
2123-
F_OIDEQ,rel->rd_id);
2130+
F_OIDEQ,RelationGetRelid(rel));
21242131

21252132
adscan=heap_beginscan(adrel,0,SnapshotNow,1,&key);
21262133

@@ -2142,7 +2149,7 @@ RemoveRelCheck(Relation rel)
21422149
rcrel=heap_openr(RelCheckRelationName,RowExclusiveLock);
21432150

21442151
ScanKeyEntryInitialize(&key,0,Anum_pg_relcheck_rcrelid,
2145-
F_OIDEQ,rel->rd_id);
2152+
F_OIDEQ,RelationGetRelid(rel));
21462153

21472154
rcscan=heap_beginscan(rcrel,0,SnapshotNow,1,&key);
21482155

@@ -2167,3 +2174,25 @@ RemoveConstraints(Relation rel)
21672174
if (constr->num_check>0)
21682175
RemoveRelCheck(rel);
21692176
}
2177+
2178+
staticvoid
2179+
RemoveStatistics(Relationrel)
2180+
{
2181+
Relationpgstatistic;
2182+
HeapScanDescscan;
2183+
ScanKeyDatakey;
2184+
HeapTupletuple;
2185+
2186+
pgstatistic=heap_openr(StatisticRelationName,RowExclusiveLock);
2187+
2188+
ScanKeyEntryInitialize(&key,0x0,Anum_pg_statistic_starelid,
2189+
F_OIDEQ,
2190+
ObjectIdGetDatum(RelationGetRelid(rel)));
2191+
scan=heap_beginscan(pgstatistic, false,SnapshotNow,1,&key);
2192+
2193+
while (HeapTupleIsValid(tuple=heap_getnext(scan,0)))
2194+
heap_delete(pgstatistic,&tuple->t_self,NULL);
2195+
2196+
heap_endscan(scan);
2197+
heap_close(pgstatistic,RowExclusiveLock);
2198+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp