Hi all,
Attached are more fixes.
Thanks,
Gavin, with Feng Tian
Index: src/backend/access/common/heaptuple.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/access/common/heaptuple.c,v
retrieving revision 1.120
diff -c -p -r1.120 heaptuple.c
*** src/backend/access/common/heaptuple.c 1 Jan 2008 19:45:45 -0000 1.120
--- src/backend/access/common/heaptuple.c 13 Apr 2008 13:06:53 -0000
*************** heap_form_tuple(TupleDesc tupleDescripto
*** 890,896 ****
else if (att[i]->attlen == -1 &&
att[i]->attalign == 'd' &&
att[i]->attndims == 0 &&
! !VARATT_IS_EXTENDED(values[i]))
{
values[i] = toast_flatten_tuple_attribute(values[i],
att[i]->atttypid,
--- 890,896 ----
else if (att[i]->attlen == -1 &&
att[i]->attalign == 'd' &&
att[i]->attndims == 0 &&
! !VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
{
values[i] = toast_flatten_tuple_attribute(values[i],
att[i]->atttypid,
*************** heap_formtuple(TupleDesc tupleDescriptor
*** 1001,1007 ****
else if (att[i]->attlen == -1 &&
att[i]->attalign == 'd' &&
att[i]->attndims == 0 &&
! !VARATT_IS_EXTENDED(values[i]))
{
values[i] = toast_flatten_tuple_attribute(values[i],
att[i]->atttypid,
--- 1001,1007 ----
else if (att[i]->attlen == -1 &&
att[i]->attalign == 'd' &&
att[i]->attndims == 0 &&
! !VARATT_IS_EXTENDED(DatumGetPointer(values[i])))
{
values[i] = toast_flatten_tuple_attribute(values[i],
att[i]->atttypid,
Index: src/backend/access/common/indextuple.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/access/common/indextuple.c,v
retrieving revision 1.85
diff -c -p -r1.85 indextuple.c
*** src/backend/access/common/indextuple.c 1 Jan 2008 19:45:45 -0000 1.85
--- src/backend/access/common/indextuple.c 13 Apr 2008 18:16:44 -0000
*************** index_form_tuple(TupleDesc tupleDescript
*** 73,79 ****
* If value is stored EXTERNAL, must fetch it so we are not depending
* on outside storage. This should be improved someday.
*/
! if (VARATT_IS_EXTERNAL(values[i]))
{
untoasted_values[i] =
PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
--- 73,79 ----
* If value is stored EXTERNAL, must fetch it so we are not depending
* on outside storage. This should be improved someday.
*/
! if (VARATT_IS_EXTERNAL(DatumGetPointer(values[i])))
{
untoasted_values[i] =
PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
*************** index_form_tuple(TupleDesc tupleDescript
*** 85,92 ****
* If value is above size target, and is of a compressible datatype,
* try to compress it in-line.
*/
! if (!VARATT_IS_EXTENDED(untoasted_values[i]) &&
! VARSIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
(att->attstorage == 'x' || att->attstorage == 'm'))
{
Datum cvalue = toast_compress_datum(untoasted_values[i]);
--- 85,92 ----
* If value is above size target, and is of a compressible datatype,
* try to compress it in-line.
*/
! if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) &&
! VARSIZE(DatumGetPointer(untoasted_values[i])) > TOAST_INDEX_TARGET &&
(att->attstorage == 'x' || att->attstorage == 'm'))
{
Datum cvalue = toast_compress_datum(untoasted_values[i]);
Index: src/backend/access/common/printtup.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/access/common/printtup.c,v
retrieving revision 1.101
diff -c -p -r1.101 printtup.c
*** src/backend/access/common/printtup.c 1 Jan 2008 19:45:45 -0000 1.101
--- src/backend/access/common/printtup.c 13 Apr 2008 13:14:52 -0000
*************** printtup(TupleTableSlot *slot, DestRecei
*** 340,346 ****
}
/* Clean up detoasted copy, if any */
! if (attr != origattr)
pfree(DatumGetPointer(attr));
}
--- 340,346 ----
}
/* Clean up detoasted copy, if any */
! if (DatumGetPointer(attr) != DatumGetPointer(origattr))
pfree(DatumGetPointer(attr));
}
*************** printtup_20(TupleTableSlot *slot, DestRe
*** 423,429 ****
pfree(outputstr);
/* Clean up detoasted copy, if any */
! if (attr != origattr)
pfree(DatumGetPointer(attr));
}
--- 423,429 ----
pfree(outputstr);
/* Clean up detoasted copy, if any */
! if (DatumGetPointer(attr) != DatumGetPointer(origattr))
pfree(DatumGetPointer(attr));
}
*************** debugtup(TupleTableSlot *slot, DestRecei
*** 537,543 ****
pfree(value);
/* Clean up detoasted copy, if any */
! if (attr != origattr)
pfree(DatumGetPointer(attr));
}
printf("\t----\n");
--- 537,543 ----
pfree(value);
/* Clean up detoasted copy, if any */
! if (DatumGetPointer(attr) != DatumGetPointer(origattr))
pfree(DatumGetPointer(attr));
}
printf("\t----\n");
*************** printtup_internal_20(TupleTableSlot *slo
*** 627,633 ****
pfree(outputbytes);
/* Clean up detoasted copy, if any */
! if (attr != origattr)
pfree(DatumGetPointer(attr));
}
--- 627,633 ----
pfree(outputbytes);
/* Clean up detoasted copy, if any */
! if (DatumGetPointer(attr) != DatumGetPointer(origattr))
pfree(DatumGetPointer(attr));
}
Index: src/backend/access/common/reloptions.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/access/common/reloptions.c,v
retrieving revision 1.9
diff -c -p -r1.9 reloptions.c
*** src/backend/access/common/reloptions.c 25 Mar 2008 22:42:42 -0000 1.9
--- src/backend/access/common/reloptions.c 13 Apr 2008 18:17:11 -0000
*************** transformRelOptions(Datum oldOptions, Li
*** 58,64 ****
astate = NULL;
/* Copy any oldOptions that aren't to be replaced */
! if (oldOptions != (Datum) 0)
{
ArrayType *array = DatumGetArrayTypeP(oldOptions);
Datum *oldoptions;
--- 58,64 ----
astate = NULL;
/* Copy any oldOptions that aren't to be replaced */
! if (PointerIsValid(DatumGetPointer(oldOptions)))
{
ArrayType *array = DatumGetArrayTypeP(oldOptions);
Datum *oldoptions;
*************** untransformRelOptions(Datum options)
*** 164,170 ****
int i;
/* Nothing to do if no options */
! if (options == (Datum) 0)
return result;
array = DatumGetArrayTypeP(options);
--- 164,170 ----
int i;
/* Nothing to do if no options */
! if (!PointerIsValid(DatumGetPointer(options)))
return result;
array = DatumGetArrayTypeP(options);
*************** parseRelOptions(Datum options, int numke
*** 220,226 ****
MemSet(values, 0, numkeywords * sizeof(char *));
/* Done if no options */
! if (options == (Datum) 0)
return;
array = DatumGetArrayTypeP(options);
--- 220,226 ----
MemSet(values, 0, numkeywords * sizeof(char *));
/* Done if no options */
! if (!PointerIsValid(DatumGetPointer(options)))
return;
array = DatumGetArrayTypeP(options);
*************** index_reloptions(RegProcedure amoptions,
*** 349,355 ****
Assert(RegProcedureIsValid(amoptions));
/* Assume function is strict */
! if (reloptions == (Datum) 0)
return NULL;
/* Can't use OidFunctionCallN because we might get a NULL result */
--- 349,355 ----
Assert(RegProcedureIsValid(amoptions));
/* Assume function is strict */
! if (!PointerIsValid(DatumGetPointer(reloptions)))
return NULL;
/* Can't use OidFunctionCallN because we might get a NULL result */
Index: src/backend/access/heap/tuptoaster.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/access/heap/tuptoaster.c,v
retrieving revision 1.86
diff -c -p -r1.86 tuptoaster.c
*** src/backend/access/heap/tuptoaster.c 12 Apr 2008 23:14:21 -0000 1.86
--- src/backend/access/heap/tuptoaster.c 13 Apr 2008 17:44:30 -0000
*************** toast_delete(Relation rel, HeapTuple old
*** 383,389 ****
{
Datum value = toast_values[i];
! if (!toast_isnull[i] && VARATT_IS_EXTERNAL(value))
toast_delete_datum(rel, value);
}
}
--- 383,389 ----
{
Datum value = toast_values[i];
! if (!toast_isnull[i] && VARATT_IS_EXTERNAL(PointerGetDatum(value)))
toast_delete_datum(rel, value);
}
}
*************** toast_insert_or_update(Relation rel, Hea
*** 615,623 ****
{
if (toast_action[i] != ' ')
continue;
! if (VARATT_IS_EXTERNAL(toast_values[i]))
continue; /* can't happen, toast_action would be 'p' */
! if (VARATT_IS_COMPRESSED(toast_values[i]))
continue;
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
continue;
--- 615,623 ----
{
if (toast_action[i] != ' ')
continue;
! if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
! if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
continue;
*************** toast_insert_or_update(Relation rel, Hea
*** 647,653 ****
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
! toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
--- 647,653 ----
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
! toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
need_change = true;
need_free = true;
}
*************** toast_insert_or_update(Relation rel, Hea
*** 707,713 ****
{
if (toast_action[i] == 'p')
continue;
! if (VARATT_IS_EXTERNAL(toast_values[i]))
continue; /* can't happen, toast_action would be 'p' */
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
continue;
--- 707,713 ----
{
if (toast_action[i] == 'p')
continue;
! if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
continue;
*************** toast_insert_or_update(Relation rel, Hea
*** 756,764 ****
{
if (toast_action[i] != ' ')
continue;
! if (VARATT_IS_EXTERNAL(toast_values[i]))
continue; /* can't happen, toast_action would be 'p' */
! if (VARATT_IS_COMPRESSED(toast_values[i]))
continue;
if (att[i]->attstorage != 'm')
continue;
--- 756,764 ----
{
if (toast_action[i] != ' ')
continue;
! if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
! if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
if (att[i]->attstorage != 'm')
continue;
*************** toast_insert_or_update(Relation rel, Hea
*** 786,792 ****
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
! toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
--- 786,792 ----
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
! toast_sizes[i] = VARSIZE(DatumGetPointer(toast_values[i]));
need_change = true;
need_free = true;
}
*************** toast_insert_or_update(Relation rel, Hea
*** 817,823 ****
{
if (toast_action[i] == 'p')
continue;
! if (VARATT_IS_EXTERNAL(toast_values[i]))
continue; /* can't happen, toast_action would be 'p' */
if (att[i]->attstorage != 'm')
continue;
--- 817,823 ----
{
if (toast_action[i] == 'p')
continue;
! if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
if (att[i]->attstorage != 'm')
continue;
*************** Datum
*** 1070,1079 ****
toast_compress_datum(Datum value)
{
struct varlena *tmp;
! int32 valsize = VARSIZE_ANY_EXHDR(value);
! Assert(!VARATT_IS_EXTERNAL(value));
! Assert(!VARATT_IS_COMPRESSED(value));
/*
* No point in wasting a palloc cycle if value size is out of the
--- 1070,1079 ----
toast_compress_datum(Datum value)
{
struct varlena *tmp;
! int32 valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
! Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
! Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
/*
* No point in wasting a palloc cycle if value size is out of the
*************** toast_compress_datum(Datum value)
*** 1095,1101 ****
* header byte and no padding if the value is short enough. So we insist
* on a savings of more than 2 bytes to ensure we have a gain.
*/
! if (pglz_compress(VARDATA_ANY(value), valsize,
(PGLZ_Header *) tmp, PGLZ_strategy_default) &&
VARSIZE(tmp) < valsize - 2)
{
--- 1095,1101 ----
* header byte and no padding if the value is short enough. So we insist
* on a savings of more than 2 bytes to ensure we have a gain.
*/
! if (pglz_compress(VARDATA_ANY(DatumGetPointer(value)), valsize,
(PGLZ_Header *) tmp, PGLZ_strategy_default) &&
VARSIZE(tmp) < valsize - 2)
{
*************** toast_save_datum(Relation rel, Datum val
*** 1141,1146 ****
--- 1141,1147 ----
int32 chunk_seq = 0;
char *data_p;
int32 data_todo;
+ Pointer dval = DatumGetPointer(value);
/*
* Open the toast relation and its index. We can use the index to check
*************** toast_save_datum(Relation rel, Datum val
*** 1159,1186 ****
*
* va_extsize is the actual size of the data payload in the toast records.
*/
! if (VARATT_IS_SHORT(value))
{
! data_p = VARDATA_SHORT(value);
! data_todo = VARSIZE_SHORT(value) - VARHDRSZ_SHORT;
toast_pointer.va_rawsize = data_todo + VARHDRSZ; /* as if not short */
toast_pointer.va_extsize = data_todo;
}
! else if (VARATT_IS_COMPRESSED(value))
{
! data_p = VARDATA(value);
! data_todo = VARSIZE(value) - VARHDRSZ;
/* rawsize in a compressed datum is just the size of the payload */
! toast_pointer.va_rawsize = VARRAWSIZE_4B_C(value) + VARHDRSZ;
toast_pointer.va_extsize = data_todo;
/* Assert that the numbers look like it's compressed */
Assert(VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
}
else
{
! data_p = VARDATA(value);
! data_todo = VARSIZE(value) - VARHDRSZ;
! toast_pointer.va_rawsize = VARSIZE(value);
toast_pointer.va_extsize = data_todo;
}
--- 1160,1187 ----
*
* va_extsize is the actual size of the data payload in the toast records.
*/
! if (VARATT_IS_SHORT(dval))
{
! data_p = VARDATA_SHORT(dval);
! data_todo = VARSIZE_SHORT(dval) - VARHDRSZ_SHORT;
toast_pointer.va_rawsize = data_todo + VARHDRSZ; /* as if not short */
toast_pointer.va_extsize = data_todo;
}
! else if (VARATT_IS_COMPRESSED(dval))
{
! data_p = VARDATA(dval);
! data_todo = VARSIZE(dval) - VARHDRSZ;
/* rawsize in a compressed datum is just the size of the payload */
! toast_pointer.va_rawsize = VARRAWSIZE_4B_C(dval) + VARHDRSZ;
toast_pointer.va_extsize = data_todo;
/* Assert that the numbers look like it's compressed */
Assert(VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer));
}
else
{
! data_p = VARDATA(dval);
! data_todo = VARSIZE(dval) - VARHDRSZ;
! toast_pointer.va_rawsize = VARSIZE(dval);
toast_pointer.va_extsize = data_todo;
}
Index: src/backend/utils/fmgr/fmgr.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/backend/utils/fmgr/fmgr.c,v
retrieving revision 1.114
diff -c -p -r1.114 fmgr.c
*** src/backend/utils/fmgr/fmgr.c 25 Mar 2008 22:42:45 -0000 1.114
--- src/backend/utils/fmgr/fmgr.c 13 Apr 2008 17:55:33 -0000
*************** fmgr_oldstyle(PG_FUNCTION_ARGS)
*** 827,833 ****
break;
}
! return (Datum) returnValue;
}
--- 827,833 ----
break;
}
! return PointerGetDatum(returnValue);
}
*************** fmgr(Oid procedureId,...)
*** 2008,2014 ****
flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
va_start(pvar, procedureId);
for (i = 0; i < n_arguments; i++)
! fcinfo.arg[i] = (Datum) va_arg(pvar, char *);
va_end(pvar);
}
--- 2008,2014 ----
flinfo.fn_oid, n_arguments, FUNC_MAX_ARGS)));
va_start(pvar, procedureId);
for (i = 0; i < n_arguments; i++)
! fcinfo.arg[i] = PointerGetDatum(va_arg(pvar, char *));
va_end(pvar);
}
*************** fmgr(Oid procedureId,...)
*** 2018,2024 ****
if (fcinfo.isnull)
elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
! return (char *) result;
}
--- 2018,2024 ----
if (fcinfo.isnull)
elog(ERROR, "function %u returned NULL", flinfo.fn_oid);
! return DatumGetPointer(result);
}
Index: src/pl/plpgsql/src/pl_exec.c
===================================================================
RCS file: /Users/swm/pgsql-cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v
retrieving revision 1.209
diff -c -p -r1.209 pl_exec.c
*** src/pl/plpgsql/src/pl_exec.c 6 Apr 2008 23:43:29 -0000 1.209
--- src/pl/plpgsql/src/pl_exec.c 13 Apr 2008 18:12:39 -0000
*************** plpgsql_exec_function(PLpgSQL_function *
*** 409,415 ****
* sure it is labeled with the caller-supplied tuple type.
*/
estate.retval =
! PointerGetDatum(SPI_returntuple((HeapTuple) (estate.retval),
tupdesc));
}
else
--- 409,415 ----
* sure it is labeled with the caller-supplied tuple type.
*/
estate.retval =
! PointerGetDatum(SPI_returntuple((HeapTuple)DatumGetPointer(estate.retval),
tupdesc));
}
else
*************** plpgsql_exec_trigger(PLpgSQL_function *f
*** 702,708 ****
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("returned tuple structure does not match table of trigger event")));
/* Copy tuple to upper executor memory */
! rettup = SPI_copytuple((HeapTuple) (estate.retval));
}
/*
--- 702,708 ----
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("returned tuple structure does not match table of trigger event")));
/* Copy tuple to upper executor memory */
! rettup = SPI_copytuple((HeapTuple) DatumGetPointer(estate.retval));
}
/*
*************** exec_stmt_return(PLpgSQL_execstate *esta
*** 1956,1962 ****
if (HeapTupleIsValid(rec->tup))
{
! estate->retval = (Datum) rec->tup;
estate->rettupdesc = rec->tupdesc;
estate->retisnull = false;
}
--- 1956,1962 ----
if (HeapTupleIsValid(rec->tup))
{
! estate->retval = PointerGetDatum(rec->tup);
estate->rettupdesc = rec->tupdesc;
estate->retisnull = false;
}
*************** exec_stmt_return(PLpgSQL_execstate *esta
*** 1968,1976 ****
PLpgSQL_row *row = (PLpgSQL_row *) retvar;
Assert(row->rowtupdesc);
! estate->retval = (Datum) make_tuple_from_row(estate, row,
! row->rowtupdesc);
! if (estate->retval == (Datum) NULL) /* should not happen */
elog(ERROR, "row not compatible with its own tupdesc");
estate->rettupdesc = row->rowtupdesc;
estate->retisnull = false;
--- 1968,1977 ----
PLpgSQL_row *row = (PLpgSQL_row *) retvar;
Assert(row->rowtupdesc);
! estate->retval =
! PointerGetDatum(make_tuple_from_row(estate, row,
! row->rowtupdesc));
! if (DatumGetPointer(estate->retval) == NULL) /* should not happen */
elog(ERROR, "row not compatible with its own tupdesc");
estate->rettupdesc = row->rowtupdesc;
estate->retisnull = false;
*************** exec_stmt_return(PLpgSQL_execstate *esta
*** 1991,1997 ****
exec_run_select(estate, stmt->expr, 1, NULL);
if (estate->eval_processed > 0)
{
! estate->retval = (Datum) estate->eval_tuptable->vals[0];
estate->rettupdesc = estate->eval_tuptable->tupdesc;
estate->retisnull = false;
}
--- 1992,1998 ----
exec_run_select(estate, stmt->expr, 1, NULL);
if (estate->eval_processed > 0)
{
! estate->retval = PointerGetDatum(estate->eval_tuptable->vals[0]);
estate->rettupdesc = estate->eval_tuptable->tupdesc;
estate->retisnull = false;
}
*************** exec_set_found(PLpgSQL_execstate *estate
*** 4998,5004 ****
PLpgSQL_var *var;
var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
! var->value = (Datum) state;
var->isnull = false;
}
--- 4999,5005 ----
PLpgSQL_var *var;
var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
! var->value = PointerGetDatum(state);
var->isnull = false;
}
--
Sent via pgsql-patches mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches