sql - indexing large MySQL table -


I've lost a bit of indexing a large table I used to use different filters to query this For example in a table:

  id is required. Key_1 | Key_2 | ... | Key_n   

There may be one filter for one or more keys, adding each (I am using the Zend Framework to create a query using the prepared statement):

  $ select- & gt; Where ($ this-> _db-> quoteInto ('key_n =?', $ Filter- & gt; key_N));   

If I correctly understand the speed of the query, then I should list some columns. Therefore, he inspired some questions:

    < Li> What does it mean to add indexes to all the columns that will be used to filter the data?
  • If I index a lot of columns, how will it affect the speed with which the data is written in the table?
  • Is it possible to add index to the combination of columns? There are some answers in the post in link @ bodi0 but I will add the following:

    Should all the indexes add to the columns used to filter the data?

    Generally, an index speeds up data retrieval. But in some cases this does not happen: If the indexed column is low, then the index can not provide any or little benefit that the adapter can decide to ignore it, for example, think of the column "Gender" , With only two values ​​"M" or "F". If each one applies to about 50% of the rows, then an index can provide a little improvement. Or, if 75% of the records are "M" and you are inquiring for "M" then the index will not be used the most.

    Does it make sense to add index to the combination of columns?

    Perhaps if you know that a certain combination of columns is often used to filter in a SELECT , then such index might prove beneficial. Note that the index should be usable, its first column should be in the filter criteria. For example: An index can be used only when the gender (and optionally state ) on the column (gender, state) ) Are used as criteria in the query. If only state is filtered by index, then it will not be used.

    Again, seeing that MySQL uses only one index per table for a query, a composite index can really be understood, because without it only a indexed column can be used by the DB engine is.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -