What are the disadvantages of having many indices?

后端 未结 4 770
礼貌的吻别
礼貌的吻别 2021-01-01 16:43

I recently sped up a complicated query by an order of magnitude by giving SQLite a good index to work with. Results like this make me wonder if I should index a lot of other

相关标签:
4条回答
  • 2021-01-01 17:21

    In order to test your particular application you can put "EXPLAIN QUERY PLAN" in front of any query you run and check the results. It will show you where it is or is not using indexes.

    That way you can determine where you could use more indexes and where they would not make a difference.

    Sqlite Explain

    I use SqliteSpy to hand test query's that seem to be causing trouble.

    0 讨论(0)
  • 2021-01-01 17:22

    The cost of an index in disk space is generally trivial. The cost of additional writes to update the index when the table changes is often moderate. The cost in additional locking can be severe.

    It depends on the read vs write ratio on the table, and on how often the index is actually used to speed up a query.

    0 讨论(0)
  • 2021-01-01 17:25

    Indexes use up disc space to store, and take time to create and maintain. Unused ones don't give any benefit. If there are lots of candidate indexes for a query, the query may be slowed down by having the server choose the "wrong" one for the query.

    Use those factors to decide whether you need an index.

    It is usually possible to create indexes which will NEVER be used - for example, and index on a (not null) field with only two possible values, is almost certainly going to be useless.

    You need to explain your own application's queries to make sure that the frequently-performed ones are using sensible indexes if possible, and create no more indexes than required to do that.

    0 讨论(0)
  • 2021-01-01 17:46

    Indexes slow down inserts and updates (which can become a really serious issue with locking) and cost disk space. That's pretty much it.

    0 讨论(0)
提交回复
热议问题