title: Reset/clear MySQL user variables
body: <p>I have bunch of MySQL queries that use temporary tables to split complex/expensive queries into small pieces.</p>
  
  <pre><code>create temporary table product_stats (
       product_id int 
      ,count_vendors int 
      ,count_categories int
      ,...
  );
  
  -- Populate initial values.
  insert into product_stats(product_id) select product_id from product;
  
  -- Incrementally collect stats info.
  update product_stats ... join vendor ... set count_vendors = count(vendor_id);
  update product_stats ... join category... set count_categories = count(category_id);
  ....
  
  -- Consume the resulting temporary table.
  select * from product_stats;
  </code></pre>
  
  <p>The problem is that, as I use connection pool, these tables are not cleared even if I close the <code>java.sql.Connection</code>.</p>
  
  <p>I can manually remove them (<code>drop temporary table x;</code>) one by one before executing the needed queries, but that may take place for mistakes.</p>
  
  <p>Is there a way (JDBC/MySQL , API/configuration) to reset all the temporary tables created within the current session without closing the database connection (as you know, I'm not reffering to <code>java.sql.Connection.close()</code>), so that I can still use the advantages that provides connection pool?</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>It seems that only from MySQL version 5.7.3 they started imlpementing the "reset connection" feature. (Release note: <a href="https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-3.html" rel="nofollow">https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-3.html</a>) However, I will not use it for the moment because version 5.7 is still on a development release. </p>