Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry for answering my own question, but at least I have an answer. I try to write it in a such a way that's helpful for others.</p> <p>Since it's a MEMORY table, I excluded I/O problems.</p> <p>Next, the query is a simple (const) select by the primary key, so it cannot be an indexing problem either.</p> <p>The next guess was locking. There are/were some very slow selects in my application on this table. And it can be a problem: slow selects delay updates that delay other selects, so in the end this very simple and fast select can be delayed.</p> <p>I checked the <code>slow query log</code> and found two frequent and slow selects that were using this particular table (and others as well). The cause was a badly formed join on a case:</p> <pre><code>A left join B on case when A.x=1 then B.id=A.id2 when A.x=2 then B.id=A.id3 else B.id=0 end </code></pre> <p>instead of</p> <pre><code>A left join B on B.id = case when A.x=1 then A.id2 when A.x=2 then A.id3 else 0 end </code></pre> <p>Both give the same result, but the latter can use an index of <code>B.id</code>, the former cannot.</p> <p>Once I corrected these queries the performance of the <em>original</em> query was greatly enhanced: <code>5ms</code> instead of <code>500ms</code> on average. And <code>98%</code> faster than average.</p> <p>The moral:</p> <ul> <li>use <code>slow query log</code>, analyse it, and improve slow queries</li> <li>if you encounter inexplicable slow-downs, always check for "crossing" queries that slow down your query by locking the same table</li> </ul>
    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