DETOAST Datum
DETOAST Datum
От:
Nick Raj <nickrajjain@gmail.com>
Дата:
Hi,
I have defined some function and also used NDBOX structure that having variable length.
typedef struct NDBOX
{
int32 vl_len_; /* varlena length */
unsigned int dim;
double x[1];
} NDBOX;
When i called my function, it gives NDBOX to be null
On debugging, i found out ,FunctionInvokeCall invokes fmgr_oldstyle function, for getting argument
if (fnextra->arg_toastable[i]) //this returns false, not able to get arguments
fcinfo->arg[i] = PointerGetDatum(PG_DETOAST_DATUM(fcinfo->arg[i]));
}
"How to get arguments toastable??" and even my table pg_class.reltoastrelid entry is zero.
Can i have to tell explicitly to toast?
If i commented that if conditions then, it got stuck below:
struct varlena *
pg_detoast_datum(struct varlena * datum)
{
if (VARATT_IS_EXTENDED(datum)) //My code get stuck here
return heap_tuple_untoast_attr(datum);
else
return datum;
}
Can anyone tell me what VARATT_IS_EXTENDED(datum) mean?
Thanks
Re: DETOAST Datum
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, May 16, 2011 at 3:41 AM, Nick Raj wrote:
> When i called my function, it gives NDBOX to be null
> On debugging, i found out ,FunctionInvokeCall invokes fmgr_oldstyle
> function, for getting argument
>
> if (fnextra->arg_toastable[i]) //this returns false, not able to get
> arguments
> fcinfo->arg[i] =
> PointerGetDatum(PG_DETOAST_DATUM(fcinfo->arg[i]));
> }
>
> "How to get arguments toastable??" and even my table pg_class.reltoastrelid
> entry is zero.
It's pretty hard to guess what's going wrong here from the information
you've provided. But reltoastid should not be 0 if you're using a
variable-length data type. It's not exactly clear what you've done
wrong though. Are you sure that the type is defined properly, as a
variable-length type?
> Can i have to tell explicitly to toast?
No, you don't have to tell it that.
> If i commented that if conditions then, it got stuck below:
>
> struct varlena *
> pg_detoast_datum(struct varlena * datum)
> {
> if (VARATT_IS_EXTENDED(datum)) //My code get stuck here
> return heap_tuple_untoast_attr(datum);
> else
> return datum;
> }
>
> Can anyone tell me what VARATT_IS_EXTENDED(datum) mean?
VARATT_IS_EXTENDED() returns true for datums that can be detoasted,
because they are (1) they are stored out-of-line in the TOAST table,
(2) compressed, or (3) unaligned, using a 1-byte header. See
src/include/postgres.h. But I seriously doubt that you need to debug
pg_detoast_datum(). If you're getting a failure there, it's because
something wasn't done right much earlier on in the process.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Re: DETOAST Datum
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Robert Haas writes: > On Mon, May 16, 2011 at 3:41 AM, Nick Raj wrote: >> "How to get arguments toastable??" and even my table pg_class.reltoastrelid >> entry is zero. > It's pretty hard to guess what's going wrong here from the information > you've provided. But reltoastid should not be 0 if you're using a > variable-length data type. It could be if the type is not marked toastable (ie, has storage class PLAIN, which I think is the default even for varlena types). But in any case I suspect that 90% of the problem here is an incorrect declaration of the *function* not the type. We haven't seen the C function declaration, nor the SQL CREATE FUNCTION command, but if it's going through fmgr_oldstyle then there isn't a PG_FUNCTION_INFO_V1 marker, which maybe is the problem. regards, tom lane
Re: DETOAST Datum
От:
Nick Raj <nickrajjain@gmail.com>
Дата:
On Mon, May 16, 2011 at 7:52 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, May 16, 2011 at 3:41 AM, Nick Raj <nickrajjain@gmail.com> wrote:>> "How to get arguments toastable??" and even my table pg_class.reltoastrelidIt could be if the type is not marked toastable (ie, has storage class
>> entry is zero.
> It's pretty hard to guess what's going wrong here from the information
> you've provided. But reltoastid should not be 0 if you're using a
> variable-length data type.
PLAIN, which I think is the default even for varlena types).
But in any case I suspect that 90% of the problem here is an incorrect
declaration of the *function* not the type. We haven't seen the C
function declaration, nor the SQL CREATE FUNCTION command, but if it's
going through fmgr_oldstyle then there isn't a PG_FUNCTION_INFO_V1
marker, which maybe is the problem.
Thanks for your replies
Tom, you are correct. I missed PG_FUNCTION_INFO_V1 marker. After adding this marker, my code works fine.
Thanks a lot.
Tom, you are correct. I missed PG_FUNCTION_INFO_V1 marker. After adding this marker, my code works fine.
Thanks a lot.
regards, tom lane