简体   繁体   English

内联字符串应该使用哪些索引?

[英]Which indexes should I use for inline strings?

I storing some strings like: Barcelona, Real Madrid, Athletico.我存储了一些字符串,例如:巴塞罗那、皇家马德里、Athletico。 My program need to search full match of this,我的程序需要搜索这个完全匹配,

For example:例如:

Barcelona    -> true
Real Madrid  -> true
Real M       -> false
Athletic     -> false

I think to store it inline in text/varchar field, like (just rude example):我想将它内联存储在 text/varchar 字段中,例如(只是粗鲁的示例):

|Barcelona|Real Madrid|Athletico| and then just make LIKE %|Real Madrid|%然后就做LIKE %|Real Madrid|%

I don't want to use any heavy things like trigram, just inline string, but which indexing system should I use?我不想使用任何繁重的东西,比如三元组,只是内联字符串,但是我应该使用哪个索引系统?

Thx谢谢

In your case you can use Arrays type for store your data and use ANY keyword in WHERE statement:在您的情况下,您可以使用Arrays 类型来存储您的数据并在WHERE语句中使用ANY关键字:

CREATE TABLE games (
    teams   text[]
);

INSERT INTO games (teams) 
VALUES ({'Real Madrid','Maccabi Haifa', 'Manchester United'})

SELECT * FROM table WHERE 'Real Madrid'= ANY (teams);

For improve performance GIN Index can be used with Array field:为了提高性能GIN 索引可以与 Array 字段一起使用:

    CREATE INDEX ON games USING gin(teams);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM