关于btree和数据库索引的问题
我读了很多关于数据库 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 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.