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

Commit022350b

Browse files
committed
Minimize slot creation for multi-inserts of pg_shdepend
When doing multiple insertions in pg_shdepend for the copy ofdependencies from a template database in CREATE DATABASE, the samenumber of slots would have been created and used all the time. As thenumber of items to insert is not known in advance, this makes most ofthe slots created for nothing. This improves the slot handling so asslot creation only happens when needed, minimizing the overhead of theoperation.Author: Michael PaquierReviewed-by: Daniel GustafssonDiscussion:https://postgr.es/m/20200731024148.GB3317@paquier.xyz
1 parent84c0e4b commit022350b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎src/backend/catalog/pg_shdepend.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,15 +809,19 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
809809
intslotCount;
810810
CatalogIndexStateindstate;
811811
TupleTableSlot**slot;
812-
intnslots;
812+
intnslots,
813+
max_slots;
814+
boolslot_init= true;
813815

814816
sdepRel=table_open(SharedDependRelationId,RowExclusiveLock);
815817
sdepDesc=RelationGetDescr(sdepRel);
816818

817-
nslots=MAX_PGSHDEPEND_INSERT_BYTES /sizeof(FormData_pg_shdepend);
818-
slot=palloc(sizeof(TupleTableSlot*)*nslots);
819-
for (inti=0;i<nslots;i++)
820-
slot[i]=MakeSingleTupleTableSlot(sdepDesc,&TTSOpsHeapTuple);
819+
/*
820+
* Allocate the slots to use, but delay initialization until we know that
821+
* they will be used.
822+
*/
823+
max_slots=MAX_PGSHDEPEND_INSERT_BYTES /sizeof(FormData_pg_shdepend);
824+
slot=palloc(sizeof(TupleTableSlot*)*max_slots);
821825

822826
indstate=CatalogOpenIndexes(sdepRel);
823827

@@ -842,6 +846,9 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
842846
{
843847
Form_pg_shdependshdep;
844848

849+
if (slot_init)
850+
slot[slotCount]=MakeSingleTupleTableSlot(sdepDesc,&TTSOpsHeapTuple);
851+
845852
ExecClearTuple(slot[slotCount]);
846853

847854
shdep= (Form_pg_shdepend)GETSTRUCT(tup);
@@ -858,10 +865,11 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
858865
slotCount++;
859866

860867
/* If slots are full, insert a batch of tuples */
861-
if (slotCount==nslots)
868+
if (slotCount==max_slots)
862869
{
863870
CatalogTuplesMultiInsertWithInfo(sdepRel,slot,slotCount,indstate);
864871
slotCount=0;
872+
slot_init= false;
865873
}
866874
}
867875

@@ -874,6 +882,8 @@ copyTemplateDependencies(Oid templateDbId, Oid newDbId)
874882
CatalogCloseIndexes(indstate);
875883
table_close(sdepRel,RowExclusiveLock);
876884

885+
/* Drop only the number of slots used */
886+
nslots=slot_init ?slotCount :max_slots;
877887
for (inti=0;i<nslots;i++)
878888
ExecDropSingleTupleTableSlot(slot[i]);
879889
pfree(slot);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp