Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been digging around to find some <em>official</em> documentation to support what Paul DuBois (albeit a member of the MySQL documentation team) says in the fifth chapter "Query Optimization" of his book <a href="http://rads.stackoverflow.com/amzn/click/0321833872" rel="nofollow">MySQL (Developer's Library)</a>:</p> <blockquote> <p><strong>Make indexed columns stand alone in comparison expressions.</strong> If you use a column in a function call or as part of a more complex term in an arithmetic expression, MySQL can't use the index because it must compute the value of the expression for every row. Sometimes this is unavoidable, but many times you can rewrite a query to get the indexed column to appear by itself.</p> </blockquote> <p>The best I can find is the section on <a href="http://dev.mysql.com/doc/internals/en/optimizer-primary-optimizations.html#optimizer-transpositions" rel="nofollow">Optimizer Transpositions</a> in the Internals manual:</p> <blockquote> <p>However, MySQL does not support transpositions where arithmetic exists. Thus:</p> <pre><code>WHERE 5 = -column1 </code></pre> <p>is not treated the same as:</p> <pre><code>WHERE column1 = -5 </code></pre> <p>Transpositions to expressions of the form column = constant are ideal for index lookups.</p> </blockquote> <p>In this case, one can take advantage of the index on <code>approps_precio</code> by rewriting the filter criteria by dividing through by <code>moneda_valor</code>:</p> <pre><code>WHERE approps_precio BETWEEN 2000/moneda_valor AND 6000/moneda_valor </code></pre> <p>Note that MySQL will still need to evaluate the division for each record, so I'm not convinced that much will be saved.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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