Reputation: 267059
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.
Upvotes: 2
Views: 72
Reputation: 134961
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.
Upvotes: 3
Reputation: 1365
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.
Upvotes: 2
Reputation: 32936
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)
Upvotes: 3
Reputation: 20602
You only need indexes on columns that are used for sorting or searching.
ie. they appear in JOIN
, WHERE
, HAVING
, GROUP
or ORDER BY
clauses.
Even then, it is not strictly necessary.
Upvotes: 6