gpt4 book ai didi

postgresql - 索引已创建,但我得到了序列扫描

转载 作者:行者123 更新时间:2023-11-29 13:18:56 25 4
gpt4 key购买 nike

PostgreSQL 9.5.7

我已经为用户名创建了一个索引。

现在我这样做了:

explain analyze select * from authentification_user where username='Pele';

然后我得到:

QUERY PLAN                                                    
-----------------------------------------------------------------------------------------------------------------
Seq Scan on authentification_user (cost=0.00..1.25 rows=1 width=478) (actual time=0.017..0.019 rows=1 loops=1)
Filter: ((username)::text = 'Pele'::text)
Rows Removed by Filter: 19
Planning time: 0.101 ms
Execution time: 0.040 ms
(5 rows)

问题是:为什么是Seq Scan?它应该是索引扫描。你能帮我踢一下吗?

simple_project=# \d authentification_user
Table "public.authentification_user"
Column | Type | Modifiers
----------+------------------------+--------------------------------------------------------------------
id | integer | not null default nextval('authentification_user_id_seq'::regclass)
username | character varying(10) | not null
pw_hash | character varying(100) | not null
email | character varying(100) | not null
Indexes:
"authentification_user_pkey" PRIMARY KEY, btree (id)
"authentification_user_username_e9ac7af7" btree (username)
"authentification_user_username_e9ac7af7_like" btree (username varchar_pattern_ops)

simple_project=#

最佳答案

有好的Postgres Wiki page about Index vs Seq scan usage对此进行解释。

在您的情况下,只是没有足够的数据来利用索引扫描的任何好处。

关于postgresql - 索引已创建,但我得到了序列扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45082507/

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