Flo*_*ume 16 arrays postgresql indexing uuid
我想使用GIN索引uuid[](对uuids数组进行有效的成员资格测试).但是当我尝试它时,PostgreSQL给了我一个错误:
mydb=> CREATE TABLE foo (val uuid[]);
CREATE TABLE
mydb=> CREATE INDEX foo_idx ON foo USING GIN(val);
ERROR: data type uuid[] has no default operator class for access method "gin"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
Run Code Online (Sandbox Code Playgroud)
如何添加必要的运算符类以使其有效?
请注意,这是类型的类似问题,citext但提供的答案不起作用.
Flo*_*ume 28
这可以使用以下运算符类来完成:
CREATE OPERATOR CLASS _uuid_ops DEFAULT
FOR TYPE _uuid USING gin AS
OPERATOR 1 &&(anyarray, anyarray),
OPERATOR 2 @>(anyarray, anyarray),
OPERATOR 3 <@(anyarray, anyarray),
OPERATOR 4 =(anyarray, anyarray),
FUNCTION 1 uuid_cmp(uuid, uuid),
FUNCTION 2 ginarrayextract(anyarray, internal, internal),
FUNCTION 3 ginqueryarrayextract(anyarray, internal, smallint, internal, internal, internal, internal),
FUNCTION 4 ginarrayconsistent(internal, smallint, anyarray, integer, internal, internal, internal, internal),
STORAGE uuid;
Run Code Online (Sandbox Code Playgroud)
归功于此,指出了我正确的方向.
相关文档在索引的接口扩展中,特别是GIN的操作员策略和功能编号.
对于PostgreSQL 10的运营商定制类_uuid_ops不再是必要的,因为现在有一种普遍的内置的opclass array_ops上anyarry(参见: https://www.postgresql.org/docs/current/static/gin-builtin-opclasses.html)