Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I speed up this giant query against a MyISAM table?
    primarykey
    data
    text
    <p>This query goes against a single table. The table has 60 attributes called "attribute1" through "attribute60", and they are all of type:</p> <pre><code>varchar(255) </code></pre> <p>There is also a column called "brand_id" that is:</p> <pre><code>int(11) </code></pre> <p>The following key exists on the table:</p> <pre><code>brand_id, attribute1, attribute2, attribute3 </code></pre> <p>The query is as follows:</p> <pre><code>SELECT distinct attribute1 from brands b inner join product_applications pa on pa.brand_id = b.id where b.id in (1,372,373,374,375,376,378,381,452, 453,454,455,456,457,458,461,474,476, 544,480,563,508,512,513,516,517,519,520,521, 522,524,525,527,528,529,533,538,539,540,542, 546,547,548,555,556,557,642,643,644,645,646, 647,648,649,650,651,652,653,654,655) </code></pre> <p>It takes over 10 seconds. The table has 5,735,673 rows.</p> <p>This query needs to take no more than 2 seconds. I cannot figure out how to write it, or if I need some sort of alternate table structure, to do this. Can anyone offer a recommendation?</p> <p>I used to use an IN in the WHERE clause, but it was recommended in another forum that this ugly way was faster because of the join. I don't really know what that means, but it IS faster, but still incredibly slow.</p> <pre> +----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+ | 1 | SIMPLE | b | range | PRIMARY | PRIMARY | 4 | NULL | 60 | Using where; Using index; Using temporary | | 1 | SIMPLE | pa | ref | brand_search_index,parttype_search_idx | brand_search_index | 5 | mcp5.b.id | 57356 | Using where; Using index | +----+-------------+-------+-------+----------------------------------------+--------------------+---------+-----------+-------+-------------------------------------------+ 2 rows in set (0.04 sec) </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload