gpt4 book ai didi

postgresql - 为什么 Postgres 不使用我的 Gin 索引?

转载 作者:行者123 更新时间:2023-11-29 11:51:42 31 4
gpt4 key购买 nike

有了这张表:

=> \d "user"
Table "public.user"
Column | Type | Modifiers
----------------------+-----------------------------+---------------------------------------------------
id | integer | not null default nextval('user_id_seq'::regclass)
email | character varying(255) |
Indexes:
"user_pkey" PRIMARY KEY, btree (id)
"user_email_key" UNIQUE CONSTRAINT, btree (email)
"user_email_idx" gin (email gin_trgm_ops)

这个查询没有使用 gin 索引:

=> explain select email from "user" where email ilike '%j%';
QUERY PLAN
--------------------------------------------------------------
Seq Scan on "user" (cost=0.00..3986.42 rows=11886 width=22)
Filter: ((email)::text ~~* '%j%'::text)
(2 rows)

为什么?

最佳答案

https://hashrocket.com/blog/posts/exploring-postgres-gin-index

注意事项这种方法的唯一缺点是输入查询必须至少包含 3 个字母,因为 Postgres 需要能够从输入查询中提取至少一个三元组才能使用我们的三元组索引。

关于postgresql - 为什么 Postgres 不使用我的 Gin 索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35299633/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com