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

Commit09a7218

Browse files
committed
Avoid some overhead with open and close of catalog indexes
This commit improves two code paths to open and close indexes aminimum amount of times when doing a series of catalog updates orinserts. CatalogTupleInsert() is costly when using it for multipleinserts or updates compared to CatalogTupleInsertWithInfo(), as it wouldneed to open and close the indexes of the catalog worked each time anoperation is done.This commit updates the following places:- REINDEX CONCURRENTLY when copying statistics from one index relationto the other. Multi-INSERTs are avoided here, as this would begin toshow benefits only for indexes with multiple expressions, for example,which may not be the most common pattern. This change is noticeable inprofiles with indexes having many expressions, for example, and it wouldimprove any callers of CopyStatistics().- Update of statistics on ANALYZE, that mixes inserts and updates.In each case, the catalog indexes are opened only if at least oneinsertion and/or update is required, to minimize the cost of theoperation. Like the previous coding, no indexes are opened as long asat least one insert or update of pg_statistic has happened.Author: Ranier VilelaReviewed-by: Kyotaro Horiguchi, Michael PaquierDiscussion:https://postgr.es/m/CAEudQAqh0F9y6Di_Wc8xW4zkWm_5SDd-nRfVsCn=h0Nm1C_mrg@mail.gmail.com
1 parent006b69f commit09a7218

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

‎src/backend/catalog/heap.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2856,6 +2856,7 @@ CopyStatistics(Oid fromrelid, Oid torelid)
28562856
SysScanDescscan;
28572857
ScanKeyDatakey[1];
28582858
Relationstatrel;
2859+
CatalogIndexStateindstate=NULL;
28592860

28602861
statrel=table_open(StatisticRelationId,RowExclusiveLock);
28612862

@@ -2878,13 +2879,20 @@ CopyStatistics(Oid fromrelid, Oid torelid)
28782879

28792880
/* update the copy of the tuple and insert it */
28802881
statform->starelid=torelid;
2881-
CatalogTupleInsert(statrel,tup);
2882+
2883+
/* fetch index information when we know we need it */
2884+
if (indstate==NULL)
2885+
indstate=CatalogOpenIndexes(statrel);
2886+
2887+
CatalogTupleInsertWithInfo(statrel,tup,indstate);
28822888

28832889
heap_freetuple(tup);
28842890
}
28852891

28862892
systable_endscan(scan);
28872893

2894+
if (indstate!=NULL)
2895+
CatalogCloseIndexes(indstate);
28882896
table_close(statrel,RowExclusiveLock);
28892897
}
28902898

‎src/backend/commands/analyze.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
16241624
{
16251625
Relationsd;
16261626
intattno;
1627+
CatalogIndexStateindstate=NULL;
16271628

16281629
if (natts <=0)
16291630
return;/* nothing to do */
@@ -1725,6 +1726,10 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
17251726
Int16GetDatum(stats->attr->attnum),
17261727
BoolGetDatum(inh));
17271728

1729+
/* Open index information when we know we need it */
1730+
if (indstate==NULL)
1731+
indstate=CatalogOpenIndexes(sd);
1732+
17281733
if (HeapTupleIsValid(oldtup))
17291734
{
17301735
/* Yes, replace it */
@@ -1734,18 +1739,20 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
17341739
nulls,
17351740
replaces);
17361741
ReleaseSysCache(oldtup);
1737-
CatalogTupleUpdate(sd,&stup->t_self,stup);
1742+
CatalogTupleUpdateWithInfo(sd,&stup->t_self,stup,indstate);
17381743
}
17391744
else
17401745
{
17411746
/* No, insert new tuple */
17421747
stup=heap_form_tuple(RelationGetDescr(sd),values,nulls);
1743-
CatalogTupleInsert(sd,stup);
1748+
CatalogTupleInsertWithInfo(sd,stup,indstate);
17441749
}
17451750

17461751
heap_freetuple(stup);
17471752
}
17481753

1754+
if (indstate!=NULL)
1755+
CatalogCloseIndexes(indstate);
17491756
table_close(sd,RowExclusiveLock);
17501757
}
17511758

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp