Getting the length of varlength data using PG_DETOAST_DATUM_SLICE or similar?

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема Getting the length of varlength data using PG_DETOAST_DATUM_SLICE or similar?
Дата
Msg-id dsjqc7$1pd7$1@news.hub.org
обсуждение исходный текст
Ответы Re: Getting the length of varlength data using PG_DETOAST_DATUM_SLICE  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
Hello, could anyone tell me, for a user contributed variable length data type, 
how can you access the length of the data without pulling the entire thing from 
disk?  Is there a function or macro for this?

As a first cut, I tried using the PG_DETOAST_DATUM_SLICE macro, but to no avail.  grep'ing through the release source
forversion 8.1.2, I find very little 
 
usage of the PG_GETARG_*_SLICE and PG_DETOAST_DATUM_SLICE macros (and hence 
little clue how they are intended to be used.)  The only files where I find them 
referenced are:
doc/src/sgml/xfunc.sgmlsrc/backend/utils/adt/varlena.csrc/include/fmgr.h


I am writing a variable length data type and trying to optimize the disk usage 
in certain functions.  There are cases where the return value of the function 
can be determined from the length of the data and a prefix of the data without 
fetching the whole data from disk.  (The prefix alone is insufficient -- I need 
to also know the length for the optimization to work.)

The first field of the data type is the length, as follows:
typedef struct datatype_foo {    int32 length;    char data[];} datatype_foo;

But when I fetch the function arguments using
datatype_foo * a = (datatype_foo *)    PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0),0,BLCKSZ);

the length field is set to the length of the fetched slice, not the length of 
the data as it exists on disk. Is there some other function that gets the length 
without pulling more than the first block?

Thanks for any insight,

--Mark


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Mark Kirkwood
Дата:
Сообщение: Re: What do the Windows pg hackers out there like for dev
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Getting the length of varlength data using PG_DETOAST_DATUM_SLICE