Обсуждение: passing constant parameters to functional indices

Поиск
Список
Период
Сортировка

passing constant parameters to functional indices

От
Abhijit Menon-Sen
Дата:
I'd like to add support for specifying constant parameters when creating
a functional index, e.g. create index foo on bar (substr(baz, 1, 32));

Is this a good idea?

If so, I'd like to ask for some suggestions before I proceed any further
towards implementing it.

The arguments to the index function are represented as T_Strings. I need
to add some way to distinguish between field names and string constants.
I could create A_Const nodes for numeric or string constants, and leave
column names as T_Strings; alternatively, I could add a T_Name type and
use it to store column names. Which is preferable? What's the best way
to pass the parameters on to FormIndexDatum()?

Any other suggestions will be appreciated, since this is my first foray
into the PostgreSQL source (but it's been pleasant reading so far :).

-- ams

PS: Are mbox archives of the list available somewhere? I tried to look   for related threads in the web archive, but I
quicklytired of the   "Try to produce less restrictive search query." (sic) message.
 


Re: passing constant parameters to functional indices

От
Tom Lane
Дата:
Abhijit Menon-Sen <ams@wiw.org> writes:
> I'd like to add support for specifying constant parameters when creating
> a functional index, e.g. create index foo on bar (substr(baz, 1, 32));
> Is this a good idea?

I think you are thinking of it the wrong way.  Rather than restricting
yourself to a single function call, replace the entire "functional
index" facility with an "expressional index" facility --- ie you can
index on the result of any scalar expression, of which a function call
is just a special case.  Since you'll have to change the contents of
pg_index anyway, you may as well implement the more general solution.

The mechanisms associated with CHECK constraints already do everything
needed for this; it's just that they only allow expressions delivering
boolean results.  So you shouldn't have a great deal of trouble finding
prototype code to follow.

This has been discussed before.  Try searching the archives for
"expressional index" to see if there's anything useful.
        regards, tom lane