Note that there are some explanatory texts on larger screens.

plurals
  1. POShort-circuit logic evaluation operators
    primarykey
    data
    text
    <p>Are there any short-circuit logic operators (specifically short-circuit <code>AND</code> and short-circuit <code>OR</code>) that I can use in a <code>WHERE</code> clause in MySQL 5.5? If there isn't, what are the alternatives?</p> <p>An abstract view at my problem along with an explanation as to why I need this can be found at this fiddle:</p> <p><a href="http://sqlfiddle.com/#!2/97fd1/3" rel="nofollow">http://sqlfiddle.com/#!2/97fd1/3</a></p> <p>In reality we are looking at millions of books in millions of bookstores in thousands of cities in hundreds of countries, which is why we cannot accept the overhead of receiving the unneeded information with every query we dispatch and seriously need to find a way to make the evaluation stop as soon as we have all rows that satisfy the current condition, before moving on to the next OR.</p> <p>Let me know if you need more information. Thanks in advance.</p> <hr> <p>As requested, here is the schema used in the fiddle:</p> <pre><code>CREATE TABLE quantitycache ( id INT AUTO_INCREMENT, quantity INT, book_id INT NOT NULL, bookstore_id INT NULL, city_id INT NULL, country_id INT NULL, PRIMARY KEY (id) ); </code></pre> <p>As well as some example data:</p> <pre><code>INSERT INTO quantitycache (quantity, book_id, bookstore_id, city_id, country_id) VALUES (5, 1, 1, NULL, NULL), (100, 2, 1, NULL, NULL), (7, 1, 2, NULL, NULL), (12, 1, NULL, 1, NULL), (12, 1, NULL, NULL, 1), (100, 2, NULL, 1, NULL), (100, 2, NULL, NULL, 1), (200, 3, NULL, 1, NULL), (250, 3, NULL, NULL, 1); </code></pre>
    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