查询数据库中组合键的某一属性

发布于 2024-10-04 12:21:35 字数 140 浏览 0 评论 0原文

复合键包含两列:col1 和 col2。如果我只对 col1 运行查询,是否会使用索引?为什么

我猜不会,因为索引通常是作为 B+ 树实现的。在B+树中,键存储在内部块中,所有记录都存储在树的最低层。如果我们从索引中进行查询,可能效率不高或者不可能。

A composite key contains two columns: col1, and col2. If I run a query on only col1, will the index be used? and why

I guess not, because typically index is implemented as B+ tree. And in B+ tree, keys are stored in interior blocks and all records are stored at the lowest level of the tree. It may be not efficient or impossible if we do the query from the index.

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

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

发布评论

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

评论(1

江南月 2024-10-11 12:21:35

一般来说,数据库能够使用复合索引的前导列。
索引是否实际上被使用,由数据库优化器决定。

In general, databases are capable of using the leading column(s) of a composite index.
Whether or not the index actualy will be used, is up to the database optimizer to decide.

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