3 ms·
Seems the temp table is around for the duration of the connection, or until dropped (we avoid stored procs)? We do a lot of queries like select x.a, (sele
by magicalhippo 7y ago
Seems the temp table is around for the duration of the connection, or until dropped (we avoid stored procs)?
We do a lot of queries like
select x.a, (select count(y.b) from tableY y where y.id = x.id) as cnt
from tableX x where x.ref = :ref
where cnt > 0
Typically a lot more going on than this, but this gets the point across I think. Would we have to drop for each select then?
- hobs 7y agoIt depends - generally you wouldnt ever drop a temp table because when it goes out of scope it dies. If you wanted the CTE/temp table to re-evaluate the query for each select, yeah, you'd effectively have to drop/truncate - but my read on your code is that the subquery would turn into a temp table, be re-used across all your selects, then go out of scope, and disappear.