Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two things are slow here.</p> <p>First - unnecessary outer / inner loop. It should be possible to do this in a single SQL query, which will be a huge time saving. Without seeing the definitions of your tables, this is the best I can suggest :</p> <pre><code> SELECT a.*, p.*, av.* FROM produkty p JOIN atributy a ON p.ATTRIBUTE_CODE LIKE CONCAT('%', a.code, '%') JOIN atributy_value av ON p.ATTRIBUTE_VALUE LIKE CONCAT('%', av.ValueCode, '%') WHERE KATEGORIA IN ('$kategoria_sql') </code></pre> <p>At least it's a starting point to test from.</p> <p>Second - Joining between the two tables using LIKE '%value%'. Is there not an integer ID that links these two tables together? Or at least, should the text be an exact match and you can remove the '%'s?</p> <p>EDIT (after adding table structure) :</p> <p>You have two joins, the first from a nice indexed integer atributy_value.ValueCode to a non-indexed text field produkty.ATTRIBUTE_CODE, the second from a non indexed text field atributy.code to another non-indexed text field produkty.ATTRIBUTE_CODE.</p> <p>It's not a good table structure, it would be easier and faster if every table had a unique integer ID to join on. But you might not have time to change this.</p> <p>Can you just remove the %'s in your original queries and insist on an exact match between the columns? To keep it simple, you could just replace :</p> <pre><code>LIKE CONCAT('%', a.code, '%') </code></pre> <p>replace with</p> <pre><code>= a.code </code></pre> <p>and</p> <pre><code>LIKE CONCAT('%', atributy_value.ValueCode, '%') </code></pre> <p>replace with</p> <pre><code>= CONVERT( varchar(500), atributy_value.ValueCode) </code></pre> <p>This will make it faster. If it's still not enough you could add indexes on Produkty.ATTRIBUTE_CODE and Produkty.ATTRIBUTE_VALUE and atributy.code.</p>
    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.
    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