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

Commit7ac1e2e

Browse files
author
Nikita Glukhov
committed
Optimize recompression in ATRewriteTable()
1 parenta3d9903 commit7ac1e2e

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ heap_insert(Relation relation, HeapTuple tup, TupleDesc tupdesc,
25712571
returnHeapTupleGetOid(tup);
25722572
}
25732573

2574-
staticinlinebool
2574+
bool
25752575
tuple_attr_compression_equals(TupleDesctd1,TupleDesctd2,AttrNumberattidx)
25762576
{
25772577
if (td1->attrs[attidx]->attcompression!=

‎src/backend/commands/tablecmds.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,6 +4554,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
45544554
List*dropped_attrs=NIL;
45554555
ListCell*lc;
45564556
Snapshotsnapshot;
4557+
bool*recompress;
45574558

45584559
if (newrel)
45594560
ereport(DEBUG1,
@@ -4602,6 +4603,22 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
46024603
dropped_attrs=lappend_int(dropped_attrs,i);
46034604
}
46044605

4606+
if (tab->newvals!=NIL)
4607+
recompress=NULL;/* recompress all */
4608+
else
4609+
{
4610+
intnatts=Min(oldTupDesc->natts,newTupDesc->natts);
4611+
4612+
recompress=palloc0(sizeof(bool)*oldTupDesc->natts);
4613+
4614+
for (i=0;i<natts;i++)
4615+
if (!tuple_attr_compression_equals(oldTupDesc,newTupDesc,i))
4616+
recompress[i]= true;
4617+
4618+
foreach(lc,dropped_attrs)
4619+
recompress[lfirst_int(lc)]= false;
4620+
}
4621+
46054622
/*
46064623
* Scan through the rows, generating a new row if needed and then
46074624
* checking all the constraints.
@@ -4622,7 +4639,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
46224639
OidtupOid=InvalidOid;
46234640

46244641
/* Extract data from old tuple */
4625-
heap_deform_tuple(tuple,oldTupDesc,values,isnull);
4642+
heap_deform_tuple_decompress(tuple,oldTupDesc,values,isnull,
4643+
recompress);
46264644
if (oldTupDesc->tdhasoid)
46274645
tupOid=HeapTupleGetOid(tuple);
46284646

@@ -4650,7 +4668,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
46504668
* Form the new tuple. Note that we don't explicitly pfree it,
46514669
* since the per-tuple memory context will be reset shortly.
46524670
*/
4653-
tuple=heap_form_tuple(newTupDesc,values,isnull);
4671+
tuple=heap_form_tuple_compress(newTupDesc,values,isnull,
4672+
recompress);
46544673

46554674
/* Preserve OID, if any */
46564675
if (newTupDesc->tdhasoid)

‎src/include/access/heapam.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
181181
externvoidheap_sync(Relationrelation);
182182
externvoidheap_update_snapshot(HeapScanDescscan,Snapshotsnapshot);
183183

184+
externbooltuple_attr_compression_equals(TupleDesctd1,TupleDesctd2,
185+
AttrNumberattidx);
186+
184187
/* in heap/pruneheap.c */
185188
externvoidheap_page_prune_opt(Relationrelation,Bufferbuffer);
186189
externintheap_page_prune(Relationrelation,Bufferbuffer,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp