Robert Haas <robertmh...@gmail.com> writes: > On Thu, Dec 1, 2011 at 8:13 PM, Tom Lane <t...@sss.pgh.pa.us> wrote: >> What I want to see is some mechanism that pushes this out to the >> individual datatypes, so that both core and plug-in datatypes have >> access to the benefits. There are a number of ways that could be >> attacked, but the most obvious one is to invent additional, optional >> support function(s) for btree opclasses.
> I feel like what's missing here is a way for the catalogs to refer to > a function that doesn't take FunctionCallInfo as an argument. But it > strikes me that it wouldn't be very hard to design such a mechanism. IMO, entries in pg_proc ought to refer to functions that are callable by the standard interface: breaking that basic contract is not going to lead anywhere pleasant. Nor do I really want yet more columns in pg_proc. Nor does the "register a pointer" scheme you suggest make any sense to me: you still need to connect these things to catalog entries, pg_opclass entries in particular, and the intermediate handle adds nothing to the situation except for creating a risk of collisions. The scheme that was rolling around in my mind was about like this: * Define btree opclasses to have an optional support function, amprocnum 2, that has a SQL signature of func(internal) returns void. * The actual argument represented by the "internal" parameter would be a pointer to a struct which is to be filled in by the support function. We'd call the support function once, during tuplesort setup or btree index relcache entry setup, and save the struct somewhere. * The struct contents would be pointers to functions that have a non-FunctionCallInfo interface. We know we need at least two: a full qsort replacement, and a non-FCI comparator. We might want more in future, if someone convinces us that additional specializations of sorting are worth the trouble. So I imagine a struct like this: typedef struct SortSupportFunctions { void (*inline_qsort) (Datum *elements, int nelements); int (*comparator) (Datum a, Datum b); } SortSupportFunctions; with the agreement that the caller must zero out the struct before call, and then the btree support function sets the function pointers for any specializations it's going to offer. If we later add a third or fourth function pointer, datatypes that know about that could fill in those pointers, but datatypes that haven't been updated aren't broken. One thing I'm not too certain about is whether to define the APIs just as above, or to support a passthrough argument of some sort (and if so, what does it reference)? Possibly any datatype that we'd actually care about this for is going to be simple enough to not need any state data. Or possibly not. And what about collations? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers