Reputation: 1208
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?
Upvotes: 2
Views: 958
Reputation: 5258
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.
Upvotes: 2