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

Commit378c79d

Browse files
committed
Cleanup for pglz_compress code: remove dead code, const-ify API of
remaining functions, simplify pglz_compress's API to not require a uselessdata copy when compression fails. Also add a check in pglz_decompress thatthe expected amount of data was decompressed.
1 parente378f82 commit378c79d

File tree

3 files changed

+96
-396
lines changed

3 files changed

+96
-396
lines changed

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

Lines changed: 23 additions & 27 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.65 2006/10/04 00:29:48 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.66 2006/10/05 23:33:33 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -100,15 +100,12 @@ heap_tuple_untoast_attr(varattrib *attr)
100100
* Fetch it from the toast heap and decompress.
101101
* ----------
102102
*/
103-
varattrib*tmp;
104-
105-
tmp=toast_fetch_datum(attr);
106-
result= (varattrib*)palloc(attr->va_content.va_external.va_rawsize
107-
+VARHDRSZ);
108-
VARATT_SIZEP(result)=attr->va_content.va_external.va_rawsize
109-
+VARHDRSZ;
110-
pglz_decompress((PGLZ_Header*)tmp,VARATT_DATA(result));
103+
PGLZ_Header*tmp;
111104

105+
tmp= (PGLZ_Header*)toast_fetch_datum(attr);
106+
result= (varattrib*)palloc(PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
107+
VARATT_SIZEP(result)=PGLZ_RAW_SIZE(tmp)+VARHDRSZ;
108+
pglz_decompress(tmp,VARATT_DATA(result));
112109
pfree(tmp);
113110
}
114111
else
@@ -124,11 +121,11 @@ heap_tuple_untoast_attr(varattrib *attr)
124121
/*
125122
* This is a compressed value inside of the main tuple
126123
*/
127-
result= (varattrib*)palloc(attr->va_content.va_compressed.va_rawsize
128-
+VARHDRSZ);
129-
VARATT_SIZEP(result)=attr->va_content.va_compressed.va_rawsize
130-
+VARHDRSZ;
131-
pglz_decompress((PGLZ_Header*)attr,VARATT_DATA(result));
124+
PGLZ_Header*tmp= (PGLZ_Header*)attr;
125+
126+
result=(varattrib*)palloc(PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
127+
VARATT_SIZEP(result)=PGLZ_RAW_SIZE(tmp)+VARHDRSZ;
128+
pglz_decompress(tmp,VARATT_DATA(result));
132129
}
133130
else
134131

@@ -157,19 +154,18 @@ heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelen
157154

158155
if (VARATT_IS_COMPRESSED(attr))
159156
{
160-
varattrib*tmp;
157+
PGLZ_Header*tmp;
161158

162159
if (VARATT_IS_EXTERNAL(attr))
163-
tmp=toast_fetch_datum(attr);
160+
tmp=(PGLZ_Header*)toast_fetch_datum(attr);
164161
else
165-
tmp=attr;/* compressed in main tuple */
162+
tmp=(PGLZ_Header*)attr;/* compressed in main tuple */
166163

167-
preslice= (varattrib*)palloc(attr->va_content.va_external.va_rawsize
168-
+VARHDRSZ);
169-
VARATT_SIZEP(preslice)=attr->va_content.va_external.va_rawsize+VARHDRSZ;
170-
pglz_decompress((PGLZ_Header*)tmp,VARATT_DATA(preslice));
164+
preslice= (varattrib*)palloc(PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
165+
VARATT_SIZEP(preslice)=PGLZ_RAW_SIZE(tmp)+VARHDRSZ;
166+
pglz_decompress(tmp,VARATT_DATA(preslice));
171167

172-
if (tmp!=attr)
168+
if (tmp!=(PGLZ_Header*)attr)
173169
pfree(tmp);
174170
}
175171
else
@@ -948,12 +944,12 @@ Datum
948944
toast_compress_datum(Datumvalue)
949945
{
950946
varattrib*tmp;
947+
int32valsize=VARATT_SIZE(value)-VARHDRSZ;
951948

952-
tmp= (varattrib*)palloc(sizeof(PGLZ_Header)+VARATT_SIZE(value));
953-
pglz_compress(VARATT_DATA(value),VARATT_SIZE(value)-VARHDRSZ,
954-
(PGLZ_Header*)tmp,
955-
PGLZ_strategy_default);
956-
if (VARATT_SIZE(tmp)<VARATT_SIZE(value))
949+
tmp= (varattrib*)palloc(PGLZ_MAX_OUTPUT(valsize));
950+
if (pglz_compress(VARATT_DATA(value),valsize,
951+
(PGLZ_Header*)tmp,PGLZ_strategy_default)&&
952+
VARATT_SIZE(tmp)<VARATT_SIZE(value))
957953
{
958954
/* successful compression */
959955
VARATT_SIZEP(tmp) |=VARATT_FLAG_COMPRESSED;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp