我的postgresql-9.3.4(CentOS 6.5版)中有我自己的User Defined-Type
名为MYUDT
的运算符类
CREATE OPERATOR = (
LEFTARG = MYUDT,
RIGHTARG = MYUDT,
PROCEDURE = MYUDT_eq,
NEGATOR = <>,
COMMUTATOR = =,
JOIN = eqjoinsel,
HASHES,
MERGES
);
CREATE OPERATOR CLASS MYUDT_OPS
DEFAULT FOR TYPE MYUDT USING BTREE AS
OPERATOR 1 <,
OPERATOR 2 <=,
OPERATOR 3 =,
OPERATOR 4 >=,
OPERATOR 5 >,
FUNCTION 1 MYUDT_OUT_CMP(MYUDT, MYUDT);
我有两个MYUDT
表,其中已创建了B-Tree索引。
CREATE TABLE MY_TABLE1(C1 MYUDT, C2 VARCHAR(10));
CREATE INDEX IDX_MYUDT ON MY_TABLE1(C1);
CREATE TABLE MY_TABLE2(C1 MYUDT, C2 VARCHAR(10));
<
,<=
,>
,>=
,=
,<>
所需的运算符和函数都在那里,它可以正常运行nested Loop
/ Sort Merge
加入,Hash join
不起作用。
EXPLAIN SELECT * FROM MY_TABLE1 A, MY_TABLE2 B WHERE A.C1=B.C1;
QUERY PLAN
---------------------------------------------------------------------------------------------
Hash Join (cost=10000000012.30..10000000026.38 rows=9 width=500)
Hash Cond: (b.C1= a.C1)
-> Seq Scan on MY_TABLE2 b (cost=10000000000.00..10000000012.90 rows=290 width=250)
-> Hash (cost=12.22..12.22 rows=6 width=250)
-> Index Scan using IDX_MYUDT on MY_TABLE1 a (cost=0.13..12.22 rows=6 width=250)
(5 rows)
SELECT * FROM MY_TABLE1 A, MY_TABLE2 B WHERE A.C1=B.C1;
ERROR: could not find hash function for hash operator 610980
我听说它需要创建hash operator class
并且我这样做了。
CREATE FUNCTION MYUDT_hash(MYUDT)
RETURNS int LANGUAGE internal AS 'hashtext' IMMUTABLE;
CREATE OPERATOR CLASS MYUDT_HASH_OPS
DEFAULT FOR TYPE MYUDT USING hash AS
FUNCTION 1 MYUDT_hash(aria128);
但它仍然不起作用,我需要这个。我错过了什么?任何建议都将非常感激。