Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL multiple joins being slow
    primarykey
    data
    text
    <p>I've got a table with the following structure:</p> <p><img src="https://i.stack.imgur.com/jyZEs.png" alt="db structure"></p> <p>I've got all my primary keys correct and every int &amp; date column has an index, and <code>(playerId, groupId)</code> in <code>player_groups</code> is an unique index. All tables are using InnoDB, and the relations you see are also references in InnoDB.</p> <p>Full database source, with data, roughly similar to the examples I'll demonstrate below: <a href="https://www.dropbox.com/s/kzf89occlq4legy/bf4_performance.sql" rel="nofollow noreferrer">https://www.dropbox.com/s/kzf89occlq4legy/bf4_performance.sql</a></p> <p>Queries:</p> <ul> <li><p>Query #1: <code>SELECT * FROM playerkills ORDER BY date DESC LIMIT 300;</code> </p></li> <li><p>Query #2: <code>SELECT p.playerName AS player, p2.playerName AS target, w.weaponName AS weapon, date, headshot, s.serverName AS server FROM playerkills JOIN players p ON playerkills.playerId = p.playerId JOIN players p2 ON playerkills.targetId = p2.playerId JOIN weapons w ON playerkills.weaponId = w.weaponId JOIN servers s ON playerkills.serverId = s.serverId ORDER BY date DESC LIMIT 300;</code></p></li> </ul> <p>Performance on my own machine, which has a lot of resources:</p> <ul> <li>Query #1: 0.0016 sec</li> <li>Query #2: 1.3050 sec</li> </ul> <p>Performance on the live database host, which has considerably less resources:</p> <ul> <li>Query #1: 0.046 sec</li> <li>Query #2: 1.297 sec</li> </ul> <p>I'm afraid something is highly impacting the performance as it works fine without any <code>JOIN</code> statements. Can anyone shed some more light on this?</p> <p>ps (<strong>edit</strong>). Also possibly important to add: This database is in live being updated every few seconds, so the results of the queries cannot be cached the same way as queries on static data could be.</p> <p><strong>EDIT 2:</strong> Profiling on the static version (on <code>localhost</code>) gave me this picture:</p> <p><img src="https://i.stack.imgur.com/w6gjR.png" alt="db profile"></p> <p>Output of <code>EXPLAIN</code>:</p> <p><img src="https://i.stack.imgur.com/y30PQ.png" alt="db explain"></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.
 

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