summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorTom Lane2007-04-06 04:21:44 +0000
committerTom Lane2007-04-06 04:21:44 +0000
commit3e23b68dac006e8deb0afa327e855258df8de064 (patch)
treef5a555955dd954265dea1107e08dadd917714551 /contrib
parentd44163953c2ce74d6db9d9807e030a0a3b725da5 (diff)
Support varlena fields with single-byte headers and unaligned storage.
This commit breaks any code that assumes that the mere act of forming a tuple (without writing it to disk) does not "toast" any fields. While all available regression tests pass, I'm not totally sure that we've fixed every nook and cranny, especially in contrib. Greg Stark with some help from Tom Lane
Diffstat (limited to 'contrib')
-rw-r--r--contrib/dblink/dblink.c6
-rw-r--r--contrib/hstore/hstore_gist.c20
-rw-r--r--contrib/intarray/_int_gist.c9
-rw-r--r--contrib/pg_trgm/trgm_gist.c22
-rw-r--r--contrib/tsearch2/ts_cfg.c4
5 files changed, 52 insertions, 9 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 568ac1e5f73..b42dd026724 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -8,7 +8,7 @@
* Darko Prenosil <Darko.Prenosil@finteh.hr>
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
*
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.62 2007/02/07 00:52:35 petere Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.63 2007/04/06 04:21:41 tgl Exp $
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
@@ -1752,8 +1752,8 @@ get_text_array_contents(ArrayType *array, int *numitems)
{
values[i] = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(ptr)));
- ptr = att_addlength(ptr, typlen, PointerGetDatum(ptr));
- ptr = (char *) att_align(ptr, typalign);
+ ptr = att_addlength_pointer(ptr, typlen, ptr);
+ ptr = (char *) att_align_nominal(ptr, typalign);
}
/* advance bitmap pointer if any */
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index fbee64be7da..19ed74933f8 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -170,7 +170,25 @@ ghstore_compress(PG_FUNCTION_ARGS)
Datum
ghstore_decompress(PG_FUNCTION_ARGS)
{
- PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval;
+ HStore *key;
+
+ key = (HStore *) PG_DETOAST_DATUM(entry->key);
+
+ if (key != (HStore *) DatumGetPointer(entry->key))
+ {
+ /* need to pass back the decompressed item */
+ retval = palloc(sizeof(GISTENTRY));
+ gistentryinit(*retval, PointerGetDatum(key),
+ entry->rel, entry->page, entry->offset, entry->leafkey);
+ PG_RETURN_POINTER(retval);
+ }
+ else
+ {
+ /* we can return the entry as-is */
+ PG_RETURN_POINTER(entry);
+ }
}
Datum
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 56eb0c08c2e..3c34cb67a7a 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -232,7 +232,16 @@ g_int_decompress(PG_FUNCTION_ARGS)
CHECKARRVALID(in);
if (ARRISVOID(in))
+ {
+ if (in != (ArrayType *) DatumGetPointer(entry->key)) {
+ retval = palloc(sizeof(GISTENTRY));
+ gistentryinit(*retval, PointerGetDatum(in),
+ entry->rel, entry->page, entry->offset, FALSE);
+ PG_RETURN_POINTER(retval);
+ }
+
PG_RETURN_POINTER(entry);
+ }
lenin = ARRNELEMS(in);
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
index 476cb1b9763..260fe01da42 100644
--- a/contrib/pg_trgm/trgm_gist.c
+++ b/contrib/pg_trgm/trgm_gist.c
@@ -97,7 +97,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
if (entry->leafkey)
{ /* trgm */
TRGM *res;
- text *val = (text *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ text *val = DatumGetTextP(entry->key);
res = generate_trgm(VARDATA(val), VARSIZE(val) - VARHDRSZ);
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
@@ -134,7 +134,25 @@ gtrgm_compress(PG_FUNCTION_ARGS)
Datum
gtrgm_decompress(PG_FUNCTION_ARGS)
{
- PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval;
+ text *key;
+
+ key = DatumGetTextP(entry->key);
+
+ if (key != (text *) DatumGetPointer(entry->key))
+ {
+ /* need to pass back the decompressed item */
+ retval = palloc(sizeof(GISTENTRY));
+ gistentryinit(*retval, PointerGetDatum(key),
+ entry->rel, entry->page, entry->offset, entry->leafkey);
+ PG_RETURN_POINTER(retval);
+ }
+ else
+ {
+ /* we can return the entry as-is */
+ PG_RETURN_POINTER(entry);
+ }
}
Datum
diff --git a/contrib/tsearch2/ts_cfg.c b/contrib/tsearch2/ts_cfg.c
index 0dc17703c38..646ffc14811 100644
--- a/contrib/tsearch2/ts_cfg.c
+++ b/contrib/tsearch2/ts_cfg.c
@@ -62,9 +62,7 @@ init_cfg(Oid id, TSCfgInfo * cfg)
ts_error(ERROR, "SPI_execp return %d", stat);
if (SPI_processed > 0)
{
- prsname = (text *) DatumGetPointer(
- SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull)
- );
+ prsname = DatumGetTextP(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull));
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
prsname = ptextdup(prsname);
MemoryContextSwitchTo(oldcontext);