Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on the circumstances. </p> <p>Advantages of derived tables: </p> <ol> <li><p>A derived table is part of a larger, single query, and will be optimized in the context of the rest of the query. This can be an advantage, if the query optimization helps performance (it usually does, with some exceptions). Example: if you populate a temp table, then consume the results in a second query, you are in effect tying the database engine to one execution method (run the first query in its entirety, save the whole result, run the second query) where with a derived table the optimizer might be able to find a faster execution method or access path.</p></li> <li><p>A derived table only "exists" in terms of the query execution plan - it's purely a logical construct. There really is no table.</p></li> </ol> <p>Advantages of temp tables</p> <ol> <li><p>The table "exists" - that is, it's materialized as a table, at least in memory, which contains the result set and can be reused.</p></li> <li><p>In some cases, performance can be improved or blocking reduced when you have to perform some elaborate transformation on the data - for example, if you want to fetch a 'snapshot' set of rows out of a base table that is busy, and then do some complicated calculation on that set, there can be less contention if you get the rows out of the base table and unlock it as quickly as possible, then do the work independently. In some cases the overhead of a real temp table is small relative to the advantage in concurrency.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload