Postgres 哈希用户定义类型
注意: 使用 m4,因此扩展了“_”前缀字符串(m4 是类似于 c 预处理器的宏预处理器)。
我的类型:
CREATE TYPE UrlPair AS (
HostName varchar( _LIMIT_HOSTNAME ),
ScriptName varchar( _LIMIT_SCRIPTNAME )
);
用于
CREATE TABLE SymbolTable_UrlPair (
Symbol _BIG_SYMBOL_SERIAL_TYPE PRIMARY KEY,
UrlPair UrlPair
);
索引
CREATE INDEX SymbolTable_UrlPair_UrlPair
ON SymbolTable_UrlPair USING hash (UrlPair);
给出:
psql:script:32: ERROR: data type urlpair has no default operator class
for access method "hash"
HINT: You must specify an operator class for the index or define a default
operator class for the data type.
问题
理想情况下,我希望引擎连接字符串并将其用于哈希。不过,我并不挑剔。有人可以告诉我为访问方法哈希声明这个“运算符类”的语法吗?
我期望用户定义类型有一些默认的哈希行为。我真的更愿意保留该类型——即,我不想扩展它,因为我可能会定义一些更复杂的 UDT。
Note: m4 is being used so "_" prefixed strings are expanded (m4 is a macro pre-processor similar to the c preprocessor).
My Type:
CREATE TYPE UrlPair AS (
HostName varchar( _LIMIT_HOSTNAME ),
ScriptName varchar( _LIMIT_SCRIPTNAME )
);
Used in
CREATE TABLE SymbolTable_UrlPair (
Symbol _BIG_SYMBOL_SERIAL_TYPE PRIMARY KEY,
UrlPair UrlPair
);
With index
CREATE INDEX SymbolTable_UrlPair_UrlPair
ON SymbolTable_UrlPair USING hash (UrlPair);
Gives:
psql:script:32: ERROR: data type urlpair has no default operator class
for access method "hash"
HINT: You must specify an operator class for the index or define a default
operator class for the data type.
Question
Ideally I would like the engine to concatinate the strings and use that for a hash. However, I am not fussy. Could someone show me the syntax for declaring this "Operator Class" for the access method hash.
I would have expected some default hashing behaviour for user defined types. I would really preffer to keep the type -- i.e., I don't want to expand it, as I will probably define a few more elaborate UDT's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哈希和哈希索引是两个不同的东西。哈希索引不支持多列索引,这可能是问题所在,您的类型 UrlPair 是多值。
Btree 索引有什么问题?需要解决什么问题?
Hashing and a hash index are two different things. Hash indexes don't support a multi column index, that might be the problem, your type UrlPair is multi value.
What's wrong with a Btree-index? What problem do have to solve?