Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL dependent subqueries when should be independent
    primarykey
    data
    text
    <p>when I explain this query:</p> <pre><code>SELECT DISTINCT(u.mail) FROM ep_point_transactions pt JOIN ep_transaction_status ts ON ts.tid = pt.tid JOIN users u ON u.uid = pt.uid WHERE ts.anulada IS NULL AND pt.anulada IS NULL AND ts.source = 'rake' AND (pt.educapuntos * pt.multiplicador) &gt;= 7500 AND ts.timestamp &lt; '2010-11-30 23:00:00' AND pt.uid NOT IN ( SELECT distinct(pt2.uid) FROM ep_point_transactions pt2 JOIN ep_transaction_status ts2 ON ts2.tid = pt2.tid WHERE ts2.anulada IS NULL AND pt2.anulada IS NULL AND ts2.source = 'rake' AND ts2.timestamp &gt; '2010-11-30 23:00:00' ); </code></pre> <p>I'm obtaining this output:</p> <pre><code>+----+--------------------+-------+--------+----------------+---------+---------+-------------------------+------+------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------------+-------+--------+----------------+---------+---------+-------------------------+------+------------------------------+ | 1 | PRIMARY | ts | ref | PRIMARY,source | source | 194 | const | 2997 | Using where; Using temporary | | 1 | PRIMARY | pt | ref | PRIMARY | PRIMARY | 4 | educapoker.ts.tid | 30 | Using where | | 1 | PRIMARY | u | eq_ref | PRIMARY | PRIMARY | 4 | educapoker.pt.uid | 1 | | | 2 | DEPENDENT SUBQUERY | ts2 | ref | PRIMARY,source | source | 194 | const | 2997 | Using where; Using temporary | | 2 | DEPENDENT SUBQUERY | pt2 | eq_ref | PRIMARY | PRIMARY | 8 | educapoker.ts2.tid,func | 1 | Using where | +----+--------------------+-------+--------+----------------+---------+---------+-------------------------+------+------------------------------+ </code></pre> <p>My doubt here is why MySQL is considering the subquery dependent if I can execute it isolately.</p> <p>As far as I know, in a dependent subquery, MySQL executes the subquery once for each parent query row, so it can be really inefficient.</p> <p>Can anyone bring me some light here, please? Thanks.</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.
 

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