11
Temporary tables
A table accessible during a single session
is stored in the system catalog
is not written to the log
Files are written to disk
Session-local memory caching (temp_buffers)
Vacuum and analysis
only performed manually
Intermediate data can be obtained using a complex algorithm, such as one
written in a procedural language. In such a scenario, the data cannot be
processed in a CTE but can be stored in a temporary table and reused
across multiple queries.
Temporary tables are more suitable for intermediate data than regular tables
because they exist only within a session or transaction (depending on the
mode specified during creation) and are automatically removed along with
the data and dependent objects like views and indexes. Moreover,
temporary tables are not logged and are cached in the local memory of the
backend process handling the session, making them more efficient to use.
The process's local memory is not accessible to autovacuum processes, so
vacuuming and analyzing must be done manually. The cache memory is
allocated on demand and restricted by the temp_buffer parameter for the
session (once the temporary table is accessed for the first time, the limit
cannot be modified).
However, temporary tables generate entries in the system catalog and are
stored as disk files. As a result, bulk processing of temporary tables—such
as in the 1C system—can lead to the system catalog growing and increased
strain on the file system. Therefore, 1C uses specific patches to mitigate
these unwanted side effects.