If we could avoid having separate temporary table names, we could avoid this prepare.  Or alternatively, if we have a limited set of possible temporary table names, we could pre-prepare the queries for those.  Doing a prepare is quite an expensive operation.