Yes, absolutely possible. Use an index to express . The tricky part is the syntax for composite types .
B-tree index for an element of complex type:
CREATE TABLE tbl (tbl_id serial, co complex); CREATE INDEX tbl_co_r_idx ON tbl (((co).r));
SQL Fiddle with EXPLAIN ANALYZE .
The same thing works for array elements, even for an array of a composite type:
CREATE TABLE tbl2 (tbl2_id serial, co complex[]); CREATE INDEX tbl2_co1_idx ON tbl2 ((co[1]));
Note that an expression index can only be used for queries if the expression matches more or less literally.
But that doesn't make sense with the GIN index, as you mentioned. In the documentation :
GIN stands for Generalized Inverted Index. The GIN is designed to handle cases where the elements to be indexed are composite values โโand queries processed by the index must look for the element values โโthat appear in the composite elements.
The GIN index will make sense in an array of a complex type as a whole, so you can search for an element inside. But you need an implementation for your specific type. The following is a list of examples in standard Postgres (in addition to the basic support for all one-dimensional arrays).
Erwin brandstetter
source share