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

Commit79a3efb

Browse files
author
Amit Kapila
committed
Fix the computation of max dead tuples during the vacuum.
In commit40d964e, we changed the way memory is allocated for deadtuples but forgot to update the place where we compute the maximumnumber of dead tuples. This could lead to invalid memory requests.Reported-by: Andres FreundDiagnosed-by: Andres FreundAuthor: Masahiko SawadaReviewed-by: Amit Kapila and Dilip KumarDiscussion:https://postgr.es/m/20200121060020.e3cr7s7fj5rw4lok@alap3.anarazel.de
1 parenta904abe commit79a3efb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ typedef struct LVDeadTuples
159159
* ItemPointerData */
160160
}LVDeadTuples;
161161

162-
#defineSizeOfLVDeadTuples(cnt) \
163-
add_size((offsetof(LVDeadTuples, itemptrs)), \
164-
mul_size(sizeof(ItemPointerData), cnt))
162+
/* The dead tuple space consists of LVDeadTuples and dead tuple TIDs */
163+
#defineSizeOfDeadTuples(cnt) \
164+
add_size(offsetof(LVDeadTuples, itemptrs), \
165+
mul_size(sizeof(ItemPointerData), cnt))
166+
#defineMAXDEADTUPLES(max_size) \
167+
(((max_size) - offsetof(LVDeadTuples, itemptrs)) / sizeof(ItemPointerData))
165168

166169
/*
167170
* Shared information among parallel workers. So this is allocated in the DSM
@@ -2708,9 +2711,9 @@ compute_max_dead_tuples(BlockNumber relblocks, bool useindex)
27082711

27092712
if (useindex)
27102713
{
2711-
maxtuples= (vac_work_mem*1024L) /sizeof(ItemPointerData);
2714+
maxtuples=MAXDEADTUPLES(vac_work_mem*1024L);
27122715
maxtuples=Min(maxtuples,INT_MAX);
2713-
maxtuples=Min(maxtuples,MaxAllocSize /sizeof(ItemPointerData));
2716+
maxtuples=Min(maxtuples,MAXDEADTUPLES(MaxAllocSize));
27142717

27152718
/* curious coding here to ensure the multiplication can't overflow */
27162719
if ((BlockNumber) (maxtuples /LAZY_ALLOC_TUPLES)>relblocks)
@@ -2738,7 +2741,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
27382741

27392742
maxtuples=compute_max_dead_tuples(relblocks,vacrelstats->useindex);
27402743

2741-
dead_tuples= (LVDeadTuples*)palloc(SizeOfLVDeadTuples(maxtuples));
2744+
dead_tuples= (LVDeadTuples*)palloc(SizeOfDeadTuples(maxtuples));
27422745
dead_tuples->num_tuples=0;
27432746
dead_tuples->max_tuples= (int)maxtuples;
27442747

@@ -3146,7 +3149,7 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
31463149

31473150
/* Estimate size for dead tuples -- PARALLEL_VACUUM_KEY_DEAD_TUPLES */
31483151
maxtuples=compute_max_dead_tuples(nblocks, true);
3149-
est_deadtuples=MAXALIGN(SizeOfLVDeadTuples(maxtuples));
3152+
est_deadtuples=MAXALIGN(SizeOfDeadTuples(maxtuples));
31503153
shm_toc_estimate_chunk(&pcxt->estimator,est_deadtuples);
31513154
shm_toc_estimate_keys(&pcxt->estimator,1);
31523155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp