Postgresql gist索引未命中

时间:2014-03-24 12:17:44

标签: postgresql

我正在使用PostgreSQL版本9.3。

我刚刚了解到普通b-tree索引不能用于&x 39; x%x%x'通配符,我找到gistgin索引,使我的通配符像查询一样到达索引。

所以我决定使用这些索引并使用PostgreSQL中的命令添加btree-gist扩展名;

CREATE EXTENSION btree_gist;

之后我将我的gist索引添加到我的表中,就像是;

CREATE INDEX ix_bras_interface_name ON bras_interface USING GIST (name);

在我添加之后,我可以看到它真的被添加了;

   table_name   |                index_name                 |    column_name
----------------+-------------------------------------------+-------------------
 bras_interface | bras_interface_context_id                 | context_id
 bras_interface | bras_interface_domain_id                  | domain_id
 bras_interface | bras_interface_managed_object_id          | managed_object_id
 bras_interface | bras_interface_name_59ec675d0b9537ac_uniq | context_id
 bras_interface | bras_interface_name_59ec675d0b9537ac_uniq | name
 bras_interface | bras_interface_name_idx                   | name
 bras_interface | bras_interface_pkey                       | id
 bras_interface | bras_interface_task_id                    | task_id
 **bras_interface | ix_bras_interface_name                    | name**
(9 rows)

但是,我的简单查询仍未达到索引。这是我的简单查询及其分析结果;

my_user=# explain ANALYZE select * from bras_interface where name like '%my_text%';
                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------
 Seq Scan on bras_interface  (cost=0.00..764.95 rows=1 width=1420) (actual time=5.589..5.589 rows=0 loops=1)
   Filter: ((name)::text ~~ '%my_text%'::text)
   Rows Removed by Filter: 27596
 Total runtime: 5.613 ms
(4 rows)

我认为它没有达到指数。我按照教程了解并且无法看到解决方案,甚至是问题。 我对gist索引缺少什么?

1 个答案:

答案 0 :(得分:0)

就像a_horse_with_no_name所说,你选择了错误的扩展名。

btree_gist扩展名允许您使用索引来支持"距离"运营商。它还允许您有一个跨越多列的gist索引,其中一个可能是例如一个tsearch矢量和另一个简单的int。

pg_trgm扩展名是匹配任意位置字符串索引的扩展名。请注意,它是一个相当昂贵的索引。

相关问题