2

I have query:

SELECT id, (SELECT `name` from `config` WHERE id = 1) AS 'config' FROM customers

How many times is the subquery executed? Does MySql cache this subquery constant or does it execute it for every row?

ArSeN
  • 5,133
  • 3
  • 19
  • 26
Konstantin Vahrushev
  • 1,110
  • 2
  • 11
  • 20
  • You could also have a look at this http://stackoverflow.com/questions/25777052/mysql-where-in-executes-slow-if-sub-query-is-used-where-as-using-list-executes –  Dec 29 '15 at 14:24

1 Answers1

1

For a simple question here is your simple answer:

The subquery is only executed once, and the result is indeed held in a cache. It does NOT get executed for each row. That is, of course, unless you add a modifier such as SQL_NO_CACHE to it.

ArSeN
  • 5,133
  • 3
  • 19
  • 26