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

Commit059e361

Browse files
committed
Although we can't support out-of-line TOAST storage in indexes (yet),
compressed storage works perfectly well. Might as well have a coherentstrategy for applying it, rather than the haphazard store-what-you-getapproach that was in the code before. The strategy I've set up here isto attempt compression of any compressible index value exceedingBLCKSZ/16, or about 500 bytes by default.
1 parent5341cdd commit059e361

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed

‎src/backend/access/common/indextuple.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
*
33
* indextuple.c
44
* This file contains index tuple accessor and mutator routines,
5-
* as well asa fewvarious tuple utilities.
5+
* as well as various tuple utilities.
66
*
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.50 2001/01/24 19:42:47 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.51 2001/02/15 20:57:01 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -57,25 +57,45 @@ index_formtuple(TupleDesc tupleDescriptor,
5757
#ifdefTOAST_INDEX_HACK
5858
for (i=0;i<numberOfAttributes;i++)
5959
{
60-
if (null[i]!=' '||tupleDescriptor->attrs[i]->attlen >=0)
60+
Form_pg_attributeatt=tupleDescriptor->attrs[i];
61+
62+
untoasted_value[i]=value[i];
63+
untoasted_free[i]= false;
64+
65+
/* Do nothing if value is NULL or not of varlena type */
66+
if (null[i]!=' '||att->attlen >=0)
67+
continue;
68+
69+
/*
70+
* If value is stored EXTERNAL, must fetch it so we are not
71+
* depending on outside storage. This should be improved someday.
72+
*/
73+
if (VARATT_IS_EXTERNAL(value[i]))
6174
{
62-
untoasted_value[i]=value[i];
63-
untoasted_free[i]= false;
75+
untoasted_value[i]=PointerGetDatum(
76+
heap_tuple_fetch_attr(
77+
(varattrib*)DatumGetPointer(value[i])));
78+
untoasted_free[i]= true;
6479
}
65-
else
80+
81+
/*
82+
* If value is above size target, and is of a compressible datatype,
83+
* try to compress it in-line.
84+
*/
85+
if (VARATT_SIZE(untoasted_value[i])>TOAST_INDEX_TARGET&&
86+
!VARATT_IS_EXTENDED(untoasted_value[i])&&
87+
(att->attstorage=='x'||att->attstorage=='m'))
6688
{
67-
if (VARATT_IS_EXTERNAL(value[i]))
89+
Datumcvalue=toast_compress_datum(untoasted_value[i]);
90+
91+
if (DatumGetPointer(cvalue)!=NULL)
6892
{
69-
untoasted_value[i]=PointerGetDatum(
70-
heap_tuple_fetch_attr(
71-
(varattrib*)DatumGetPointer(value[i])));
93+
/* successful compression */
94+
if (untoasted_free[i])
95+
pfree(DatumGetPointer(untoasted_value[i]));
96+
untoasted_value[i]=cvalue;
7297
untoasted_free[i]= true;
7398
}
74-
else
75-
{
76-
untoasted_value[i]=value[i];
77-
untoasted_free[i]= false;
78-
}
7999
}
80100
}
81101
#endif
@@ -137,10 +157,9 @@ index_formtuple(TupleDesc tupleDescriptor,
137157
* Here we make sure that the size will fit in the field reserved for
138158
* it in t_info.
139159
*/
140-
141160
if ((size&INDEX_SIZE_MASK)!=size)
142-
elog(ERROR,"index_formtuple: data takes %lu bytes: too big",
143-
(unsigned long)size);
161+
elog(ERROR,"index_formtuple: data takes %lu bytes, max is %d",
162+
(unsigned long)size,INDEX_SIZE_MASK);
144163

145164
infomask |=size;
146165

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.16 2001/02/09 17:30:03 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.17 2001/02/15 20:57:01 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -45,7 +45,6 @@ static voidtoast_delete(Relation rel, HeapTuple oldtup);
4545
staticvoidtoast_delete_datum(Relationrel,Datumvalue);
4646
staticvoidtoast_insert_or_update(Relationrel,HeapTuplenewtup,
4747
HeapTupleoldtup);
48-
staticDatumtoast_compress_datum(Datumvalue);
4948
staticDatumtoast_save_datum(Relationrel,Oidmainoid,int16attno,Datumvalue);
5049
staticvarattrib*toast_fetch_datum(varattrib*attr);
5150

@@ -721,7 +720,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
721720
*the tuple!
722721
* ----------
723722
*/
724-
staticDatum
723+
Datum
725724
toast_compress_datum(Datumvalue)
726725
{
727726
varattrib*tmp;

‎src/include/access/tuptoaster.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 2000, PostgreSQL Development Team
88
*
9-
* $Id: tuptoaster.h,v 1.8 2000/08/04 04:16:10 tgl Exp $
9+
* $Id: tuptoaster.h,v 1.9 2001/02/15 20:57:01 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -40,6 +40,12 @@
4040

4141
#defineTOAST_TUPLE_TARGET(MaxTupleSize / 4)
4242

43+
/*
44+
* If an index value is larger than TOAST_INDEX_TARGET, we will try to
45+
* compress it (we can't move it out-of-line, however). Note that this
46+
* number is per-datum, not per-tuple, for simplicity in index_formtuple().
47+
*/
48+
#defineTOAST_INDEX_TARGET(MaxTupleSize / 16)
4349

4450
/*
4551
* When we store an oversize datum externally, we divide it into chunks
@@ -95,6 +101,14 @@ extern varattrib *heap_tuple_fetch_attr(varattrib * attr);
95101
*/
96102
externvarattrib*heap_tuple_untoast_attr(varattrib*attr);
97103

104+
/* ----------
105+
* toast_compress_datum -
106+
*
107+
*Create a compressed version of a varlena datum, if possible
108+
* ----------
109+
*/
110+
externDatumtoast_compress_datum(Datumvalue);
111+
98112
#endif/* TUPLE_TOASTER_ACTIVE */
99113

100114

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp