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

Commit84fe899

Browse files
committed
Some small tuptoaster improvements from Greg Stark. Avoid unnecessary
decompression of an already-compressed external value when we have to copyit; save a few cycles when a value is too short for compression; andannotate various lines that are currently unreachable.
1 parentf18dfc4 commit84fe899

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.74 2007/04/06 04:21:41 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.75 2007/09/26 23:29:10 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -525,11 +525,16 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
525525
/*
526526
* We took care of UPDATE above, so any external value we find
527527
* still in the tuple must be someone else's we cannot reuse.
528-
* Expand it to plain (and, probably, toast it again below).
528+
* Fetch it back (without decompression, unless we are forcing
529+
* PLAIN storage). If necessary, we'll push it out as a new
530+
* external value below.
529531
*/
530532
if (VARATT_IS_EXTERNAL(new_value))
531533
{
532-
new_value=heap_tuple_untoast_attr(new_value);
534+
if (att[i]->attstorage=='p')
535+
new_value=heap_tuple_untoast_attr(new_value);
536+
else
537+
new_value=heap_tuple_fetch_attr(new_value);
533538
toast_values[i]=PointerGetDatum(new_value);
534539
toast_free[i]= true;
535540
need_change= true;
@@ -590,7 +595,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
590595
if (toast_action[i]!=' ')
591596
continue;
592597
if (VARATT_IS_EXTERNAL(toast_values[i]))
593-
continue;
598+
continue;/* can't happen, toast_action would be 'p' */
594599
if (VARATT_IS_COMPRESSED(toast_values[i]))
595600
continue;
596601
if (att[i]->attstorage!='x')
@@ -654,7 +659,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
654659
if (toast_action[i]=='p')
655660
continue;
656661
if (VARATT_IS_EXTERNAL(toast_values[i]))
657-
continue;
662+
continue;/* can't happen, toast_action would be 'p' */
658663
if (att[i]->attstorage!='x'&&att[i]->attstorage!='e')
659664
continue;
660665
if (toast_sizes[i]>biggest_size)
@@ -703,7 +708,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
703708
if (toast_action[i]!=' ')
704709
continue;
705710
if (VARATT_IS_EXTERNAL(toast_values[i]))
706-
continue;
711+
continue;/* can't happen, toast_action would be 'p' */
707712
if (VARATT_IS_COMPRESSED(toast_values[i]))
708713
continue;
709714
if (att[i]->attstorage!='m')
@@ -766,7 +771,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
766771
if (toast_action[i]=='p')
767772
continue;
768773
if (VARATT_IS_EXTERNAL(toast_values[i]))
769-
continue;
774+
continue;/* can't happen, toast_action would be 'p' */
770775
if (att[i]->attstorage!='m')
771776
continue;
772777
if (toast_sizes[i]>biggest_size)
@@ -1025,6 +1030,12 @@ toast_compress_datum(Datum value)
10251030
Assert(!VARATT_IS_EXTERNAL(value));
10261031
Assert(!VARATT_IS_COMPRESSED(value));
10271032

1033+
/*
1034+
* No point in wasting a palloc cycle if value is too short for compression
1035+
*/
1036+
if (valsize<PGLZ_strategy_default->min_input_size)
1037+
returnPointerGetDatum(NULL);
1038+
10281039
tmp= (structvarlena*)palloc(PGLZ_MAX_OUTPUT(valsize));
10291040
if (pglz_compress(VARDATA_ANY(value),valsize,
10301041
(PGLZ_Header*)tmp,PGLZ_strategy_default)&&
@@ -1438,10 +1449,18 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset, int32 length)
14381449
int32chcpystrt;
14391450
int32chcpyend;
14401451

1452+
Assert(VARATT_IS_EXTERNAL(attr));
1453+
14411454
/* Must copy to access aligned fields */
14421455
memcpy(&toast_pointer,VARDATA_SHORT(attr),
14431456
sizeof(structvaratt_external));
14441457

1458+
/*
1459+
* It's nonsense to fetch slices of a compressed datum -- this isn't lo_*
1460+
* we can't return a compressed datum which is meaningful to toast later
1461+
*/
1462+
Assert(!VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
1463+
14451464
attrsize=toast_pointer.va_extsize;
14461465
totalchunks= ((attrsize-1) /TOAST_MAX_CHUNK_SIZE)+1;
14471466

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp