I didn't get any responses on pgsql-sql, so I'm re-posting here...

> Is the GiST examples I've looked through, in the picksplit functions,
> I see code that looks roughly like this:
>
>   bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
>   OffsetNumber i, maxoff;
>
>   maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1;
>
>   for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
>     {
>       ... DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i].key)) ...
>     }
>
> I'm wondering, since FirstOffsetNumber is 1, what about the 0'th index
> in entryvec?  Is it just not set?

In backend/access/gist/gist.c I see how entryvec is built:

   storage = palloc(MAXALIGN(VARHDRSZ) + (*len + 1) * sizeof(GISTENTRY));
   entryvec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
   decompvec = (bool *) palloc((*len + 1) * sizeof(bool));
   VARATT_SIZEP(entryvec) = (*len + 1) * sizeof(GISTENTRY) + VARHDRSZ;
   for (i = 1; i <= *len; i++)
   {
     [...] gistdentryinit(giststate, 0, &((GISTENTRY *) VARDATA(entryvec))[i], [...]
   }

So it looks like the 0'th entry indeed is empty.  Why?

Also, in gist.c the index "i" has type "int".  No mention of
OffsetNumber anywhere.  Any reason for that?

-- 
Itai Zukerman  <http://www.math-hat.com/~zukerman/>

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



-- 
Itai Zukerman  <http://www.math-hat.com/~zukerman/>
Thu, 27 Feb 2003 17:21:37 -0500
Itai Zukerman <zukerman@math-hat.com>
Re: [SQL] OffsetNumber, picksplit, and GiST
Just historical reasons...

Itai Zukerman wrote:
> I didn't get any responses on pgsql-sql, so I'm re-posting here...
> 
> 
>>Is the GiST examples I've looked through, in the picksplit functions,
>>I see code that looks roughly like this:
>>
>>  bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
>>  OffsetNumber i, maxoff;
>>
>>  maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1;
>>
>>  for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
>>    {
>>      ... DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i].key)) ...
>>    }
>>
>>I'm wondering, since FirstOffsetNumber is 1, what about the 0'th index
>>in entryvec?  Is it just not set?
> 
> 
> In backend/access/gist/gist.c I see how entryvec is built:
> 
>    storage = palloc(MAXALIGN(VARHDRSZ) + (*len + 1) * sizeof(GISTENTRY));
>    entryvec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
>    decompvec = (bool *) palloc((*len + 1) * sizeof(bool));
>    VARATT_SIZEP(entryvec) = (*len + 1) * sizeof(GISTENTRY) + VARHDRSZ;
>    for (i = 1; i <= *len; i++)
>    {
>      [...] gistdentryinit(giststate, 0, &((GISTENTRY *) VARDATA(entryvec))[i], [...]
>    }
> 
> So it looks like the 0'th entry indeed is empty.  Why?
> 
> Also, in gist.c the index "i" has type "int".  No mention of
> OffsetNumber anywhere.  Any reason for that?
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org

-- 
Teodor Sigaev
teodor@stack.net



Mon, 03 Mar 2003 12:46:00 +0300
Teodor Sigaev <teodor@stack.net>
Re: [SQL] OffsetNumber, picksplit, and GiST