我应该在这些列上创建索引吗?
我的数据库中有一些列,大部分是 varchar 255。它们仅被访问一次,但对于登录用户来说,每个页面加载/请求都会加载一次。 (大多数情况下它们包含用户偏好等内容)。
我的问题是,我是否应该在这些列上创建索引?我已经在其他列上建立了索引,这些索引用于多个查询,而不是像这些列一样只读取一次并存储。
I have some columns in my database, mostly varchar 255s. They are only accessed once, but they're loaded once per page load/request for logged in users. (Mostly they contain things like the user's preferences).
My question is, should I create indexes on these columns or not? I've already got indexes on other columns which are used in multiple queries as opposed to just read once and stored like these columns.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您只需要用于排序或搜索的列上的索引。
IE。它们出现在
JOIN
、WHERE
、HAVING
、GROUP
或ORDER BY
子句中。即便如此,这也不是绝对必要的。
You only need indexes on columns that are used for sorting or searching.
ie. they appear in
JOIN
,WHERE
,HAVING
,GROUP
orORDER BY
clauses.Even then, it is not strictly necessary.
我认为答案取决于列是否仅在选择中使用,或者是否在 where 子句或联接以及其他排序/查询操作中使用。
如果前者,没有索引,如果后者,那么使用索引查询会更快(通常)
I think the answer depends on if the columns are just used in selects, or if they are used in where clauses or joins and other sort/query operations.
If the former, don't have indexes, if the latter then the queries will be quicker with an index (well usually)
答案是这取决于......看看你的查询计划,添加索引是否有好处?
您的查询可能已被当前存在的索引覆盖。
请记住,添加索引会减慢更新/插入速度。
The answer is it depends.....take a look at the plan for your queries, will it benefit adding the indexes?
Your query might already be covered by the indexes presently there.
Keep in mind that adding the indexes will slow down update/inserts.
如果我没记错的话,对列进行索引还取决于有多少用户以及每个用户的偏好大小。例如,如果您存储了 1000000 个用户首选项,那么对其建立索引肯定会有所帮助。
If I am not wrong, indexing a column will also depend on how many users are there and the size of the preference of each user. For instance if you have 1000000 users preferences stored, it would definitely help indexing it.