Thread: Comparing Datum's at aminsert() stage

Comparing Datum's at aminsert() stage

From
"Victor Y. Yegorov"
Date:
Hi!

For bitmaps, I need to search each value being inserted (for each column of
the index) in the list of already existing values (stored in index's header
area). To do that I need:

1) create Datum from PageItem's value (I store each value in it's own  PageItem);
2) compare newly inserted Datum with on-disk existing one.

For hash access method (maybe others too, haven't checked), this is done
via index_keytest() function. But it uses ScanKey, there's no such
at aminsert() stage.


So, I'd like to ask -- what is the "reverse" function for heap_fill_tuple(),
is it OK to use index_getattr()?
And how do I compare 2 Datums? I need FmgrInfo pointer for the equality
operator of the corresponding data type. Are there any API calls to obtain one?

Thank you.


-- 

Victor Y. Yegorov


Re: Comparing Datum's at aminsert() stage

From
Tom Lane
Date:
"Victor Y. Yegorov" <viy@mits.lv> writes:
> So, I'd like to ask -- what is the "reverse" function for heap_fill_tuple(),
> is it OK to use index_getattr()?

That's probably what you *have* to use, since the normal deconstructors
assume they are working with heap tuples, which are different.  But I
don't understand why you are waiting till after the index tuple is
formed.  The aminsert function gets an array of Datums to start with.
Why not do it there?

> And how do I compare 2 Datums? I need FmgrInfo pointer for the equality
> operator of the corresponding data type. Are there any API calls to obtain one?

Look at the array comparison functions for some ideas.  Be wary about
memory leaks: index AM code generally runs in a context that won't get
cleaned up until query end, so if you leak a little bit of memory per
call, you will have a problem you won't notice until it goes into the
field.
        regards, tom lane


Re: Comparing Datum's at aminsert() stage

From
"Victor Y. Yegorov"
Date:
* Tom Lane <tgl@sss.pgh.pa.us> [19.04.2005 19:48]:
> That's probably what you *have* to use, since the normal deconstructors
> assume they are working with heap tuples, which are different.  But I
> don't understand why you are waiting till after the index tuple is
> formed.  The aminsert function gets an array of Datums to start with.
> Why not do it there?

Well, I need that exactly in aminsert.

Each value is stored only once in the index (along with it's own
series-of-bits). Thus, I need to compare each Datum from aminsert()'s
array with the existing ones.

Also, I cannot form tuple the ordinary way (I need all values separated),
so I copy each TuplDesc->attrs[i] into temporary TupleDesc (1 attribute big)
and call heap_fill_tuple(). Actually, I'm not sure this is the right way...

I think, storing some kind of hash-value from the Datum is a good idea, but
it's need to be unique. Is it possible with any existing API?


-- 

Victor Y. Yegorov