简体   繁体   English

如何在不使用全文搜索的情况下提高查询速度?

[英]How to increase query speed without using full-text search?

This is my simple query; 这是我的简单查询; By searching selectnothing I'm sure I'll have no hits. 通过搜索selectnothing我相信我没有命中。

SELECT nome_t FROM myTable WHERE nome_t ILIKE '%selectnothing%';

This is the EXPLAIN ANALYZE VERBOSE 这是EXPLAIN ANALYZE VERBOSE

Seq Scan on myTable  (cost=0.00..15259.04 rows=37 width=29) (actual time=2153.061..2153.061 rows=0 loops=1)
  Output: nome_t
  Filter: (nome_t ~~* '%selectnothing%'::text)
Total runtime: 2153.116 ms

myTable has around 350k rows and the table definition is something like: myTable有大约350k行,表定义如下:

CREATE TABLE myTable (
    nome_t text NOT NULL,
)

I have an index on nome_t as stated below: 我有一个关于nome_t的索引,如下所述:

CREATE INDEX idx_m_nome_t ON myTable
USING btree (nome_t);

Although this is clearly a good candidate for Fulltext search I would like to rule that option out for now. 虽然这显然是全文搜索的一个很好的候选者,但我想暂时将该选项排除在外。
This query is meant to be run from a web application and currently it's taking around 2 seconds which is obviously too much; 此查询旨在从Web应用程序运行,目前大约需要2秒,这显然太多了;
Is there anything I can do, like using other index methods, to improve the speed of this query? 有什么我可以做的,比如使用其他索引方法,来提高这个查询的速度?

No, ILIKE '%selectnothing%' always needs a full table scan, every index is useless. 不,ILIKE'%selectnothing%'总是需要全表扫描,每个索引都没用。 You need full text search, it's not that hard to implement. 您需要全文搜索,这并不难实现。


Edit: You could use a Wildspeed, I forgot about this option. 编辑:您可以使用Wildspeed,我忘了这个选项。 The indexes will be huge, but your performance will also be much better. 索引将是巨大的,但你的表现也会好得多。

Wildspeed extension provides GIN index support for wildcard search for LIKE operator. Wildspeed扩展为LIKE运算符的通配符搜索提供GIN索引支持。

http://www.sai.msu.su/~megera/wiki/wildspeed http://www.sai.msu.su/~megera/wiki/wildspeed

another thing you can do-- is break this nome_t column in table myTable into it's own table. 你可以做的另一件事 - 将表myTable中的这个nome_t列拆分为它自己的表。 Searching one column out of a table is slow (if there are fifty other wide columns) because the other data effectively slows down the scan against that column (because there are less records per page/extent). 从表中搜索一列很慢(如果有其他五十个宽列),因为其他数据有效地减慢了对该列的扫描速度(因为每页/范围的记录较少)。

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

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