title: sql does the query optimizer optimize foreign key references for inserts?
body: <p>I need to insert into a table that references to another table (FK)
  I use the following query:</p>
  
  <pre><code>INSERT INTO order (customer_id, price) values
      ((select customer_id from customer where name = 'John'), 12.34),
      ((select customer_id from customer where name = 'John'), 3.33),
      ((select customer_id from customer where name = 'Peter'), 5)
  </code></pre>
  
  <p>USING EXPLAIN tells me that it executes all three subqueries instead of optimizing it to use a cached result of john. How can I efficiently do this?
  Do I need to get  the customer_ids in a separate query to use them later instead of using subqueries?</p>
  
  <p>Or what's the best join operation to use for it?</p>