关于btree和数据库索引的问题

发布于 2024-09-30 12:00:44 字数 411 浏览 1 评论 0原文

我读了很多关于数据库 btree 定理的文章..总是令人困惑。
假设我有一个如下所述的表格:
表用户信息:
(user_id为主键,用户名作为字符串,密码作为字符串)
正如一些文章中所描述的,user_id被创建为表userinfo索引,如果我通过索引选择记录,我将获得高效的性能user_id.. 但如果我通过用户名选择,据说它会将行一一比较...... 我在 MYSQL 中尝试了这个,它并不像预期的那么慢......
为什么?
mysql 如何进行此选择? 谢谢

I read tons of articles about btree theorem about database..thing there is always bewildering.
assuming I have a table as described as follow:
table userinfo:
(user_id as primary key, username as string, password as string)
as described in some articles, the user_id is created as index for the table userinfo, I will get efficient preformance, if i select records by index of user_id..
but if i select by username, it's said it campares the lines one by one.....
I try this in MYSQL , it is not as slow as expected....
why?
how does mysql do with this selcetion??
thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2024-10-07 12:00:44

如果您的 WHERE 子句按用户名(未索引)进行比较,它可能会进行全表扫描。但是,如果表中的行数很少,这可能仍然很快。如今,计算机速度非常快,数据库可以智能地组织数据以进行高效的表扫描。

If your WHERE clause compares by username (which is not indexed), it will probably do a full table scan. But, this may still be fast if the number of rows in the table is small. Computers are very fast these days and DBs are smart about organizing data for efficient table scans.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文