query optimization - MySQL indexing strategy -


I am trying to use the following query on the table with ~ 200k records on it are all other types of fields Which can be filtered, but this is a base example.

  SELECT b.isbn is not books b WHERE b.price and not b.deleted = '' and B. publication_date & lt; = '2009-12-04' and (b.subject1_id IN ('CAT1', 'CAT2', 'CAT3', 'CAT4', 'CAT5') or B. Subject2_id IN ('CAT1', 'CAT2' 'CAT1', 'CAT2', 'CAT3', 'CAT4', 'CAT5') in 'CAT3', 'Cat 4', 'Cat5') or B. No. 3 EID  / Pre> 

Currently, I have a different index on all of these fields and this query takes ~ 4.5 seconds, which is a very long way expin lists NULL Under the key of .

I also tried to create a large index, which included all the fields in the above query, but EXPLAIN indicates that this multi-field index is not used.

How can I direct these fields to speed up my queries?

Edit: These are my current index

  • Index (publication_date)
  • >
  • Index (subject 1_id)
  • Index (subject 2_id)
  • Index (subject 3_id)
  • Index (value, deleted, publication_data, subject 1_d, subject 2_d, subject 3_id)
  • < / Ul>

    EDIT2: Answer to ıeu - After normalizing tables and basically using your query, something increments it (time is now ~ 3.5 seconds), but not as much as I 'M k A. I see I am being indexed in the new table as the primary key (ISBN, Visy_aidi) and to join the index.

    EDIT3: I added an additional index on the second table (topic_ID, ISBN), which helps other than the other index which is mentioned below helps a bit, but only when used I use "force INDEX" on the query. It comes down to about 1.5 seconds. Is it expected to be very low?

    Help your case before indexing needs to be normalized.

    You can create a second table in which indexes can be added (topic, ISBN), book and topic, then join that table like:

      B . Select books from ISBN, B Inner in Book BookSubscribe BS on BISIN = BISBN, where B.Prices are not blank and B.Diet! = 'Deleted' and BPaccation_Date & lt; = '2009-12-04' and Rule # 1 (literally) in Schema Normalization: "" BSBI in "" ('CAT1', 'CAT2' ...)  

    In the 3 section column where in the section you or the operation prevented from being able to take advantage of an index for that part of the query Are going to

    (The primary key that shows the ISBN)


    Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    php - Multiple Select with Explode: only returns the word "Array" -

    php - jQuery AJAX Post not working -