Non-persistent in-memory tables are not written to disk when the server shuts down. Therefore, any time that the server shuts down, whether normally or abnormally, the data in non-persistent tables is lost. Their data is not logged or checkpointed. That makes them unrecoverable but remarkably faster than persistent tables.
There are two different types of non-persistent in-memory tables: transient tables and temporary tables. The main difference between temporary tables and transient tables is that the data of a temporary table is visible to a single connection whereas data of a transient table is visible to all users.
Non-persistent tables are useful as scratchpads. For example, you can copy data from a persistent table, do a series of intensive operations on the data while it is in the temporary table, and then store the results back in a persistent table. This allows you to maximize performance, yet still keep part or all of the data when you are done. If, for some reason, your work is interrupted, the original data is still safe in the persistent table, and you can restart the processing.
Because transactions for non-persistent tables are not logged, they cannot be used with HotStandby.
Data in temporary tables is visible only to the connection that inserted the data, and the data is retained only for the duration of the connection. Temporary tables are like private scratchpads that no one else can see. Temporary tables are even faster than transient tables because they do not use logging or any type of concurrency control mechanism (such as record locking).
Limited visibility
Data in temporary tables has limited visibility because only the session (connection) that inserted the data can see it.
If your session creates a temporary table and inserts data into it, no other user session can see your data, even if you grant privileges on that table. Multiple sessions can use the same table simultaneously, but each session can see only its own data.
Since each session can see only its own data, you do not need to coordinate with other sessions to make sure that you insert unique values into the table, even if the table has a unique constraint. For example, if you create a temporary table that has a unique constraint on the ID column, you and another session might both insert records that have the ID set to the value 1. Since each session sees only its own data, operations such as UPDATE and DELETE affect only the data in the session.
Limited duration
Data in temporary tables has limited duration because as soon as you exit your current session (disconnect from the server), the data is discarded. If you connect again, you cannot see your data.
The word temporary in the term temporary tables refers to the data, not the table itself. The server stores the definition of the temporary table (but not the data) in the system tables and keeps that definition even after you disconnect. Thus, if you reconnect to the server later, you the table still exists, but it is empty. When you create the table, you do not need to create it again in future sessions. In fact, if you or another user try to create a temporary table with the same name as an existing
temporary table, you get an error message. The behavior can be unexpected if you think that a temporary table means that the table (not just the data) disappears as soon as you disconnect.
Because the tables persist (even though the data does not), use the DROP TABLE command to drop the table definition after you no longer need it. Also, because the table persists, if you export a database schema definition, the output includes the commands to re-create the temporary tables.
Because temporary tables are cleared when the user disconnects, the processor usage can seem high for some time after a session with a large amount of temporary table data.
▪If you use the HotStandby component, data in temporary tables is not replicated to the Secondary server. However, temporary table definitions themselves are replicated to the Secondary server. Thus, if you want to fail over to your Secondary, you do not need to re-create any temporary tables that are already created. However, you must re-create any data in them.
▪Temporary tables can be used only as replica tables in advanced replication systems, not as master tables.
▪Temporary tables have restrictions on how they can be used with referential constraints. A temporary table can reference another temporary table, but it cannot reference transient or persistent tables. No other type of table can reference a temporary table.
With the exceptions of the limitations listed in this section, temporary tables behave like normal (persistent) in-memory tables.
For example,
▪Temporary tables can have indexes on them.
▪Temporary tables can be used in Views.
▪Temporary tables can have triggers on them.
▪Temporary tables can contain BLOB columns (but the length of those columns is limited to a couple of kilobytes).
▪Temporary tables exist in a specific catalog and schema.
▪Privileges apply to temporary tables; in other words, the creator of the temporary table can grant and revoke privileges on the table. The DBA can also grant and revoke privileges on the table. However, when a session puts data into a temporary table, the data cannot be seen by any other session, even if that session is by a DBA or a user that has SELECT privilege on the temporary table. Therefore, granting privileges on a table merely grants the other user the right to use your table, not your data. Default privileges on temporary tables are the same as the default privileges on persistent tables.
Standards compliance
The solidDB® implementation of temporary tables fully complies with the ANSI SQL:1999 standard for global temporary tables. All solidDB® temporary tables are global. In the CREATE TABLE syntax, the keyword GLOBAL is supported for compatibility reasons. However, even if the keyword GLOBAL is not specified, all temporary tables are global.
The solidDB® server does not support local temporary tables as defined by ANSI.
Transient tables last until the database server shuts down. Multiple users can use the same transient table, and each user sees the data of all other users.
In most regards, transient tables behave like standard (persistent) in-memory tables.
For example:
▪Data in transient tables has the same scope or visibility as data in persistent tables. The data that you insert into a transient table can be seen by other users’ sessions, if those users have appropriate privileges.
▪Transient tables can be used in views.
▪Transient tables can have indexes on them.
▪Transient tables can have triggers on them.
▪Transient tables can contain BLOB columns. However, the length of BLOB columns is limited to few KB in all in-memory tables.
▪Privileges apply to transient tables.
▪Transient tables reside in a specific catalog and schema.
▪You can import data into transient tables by using the solidDB® Speed Loader (solload) utility.
If you export a database with a transient table, the data in the transient tables and the structure of the tables are exported.
The server stores the definition of the transient table (but not the data) in the system tables and keeps that definition even after the server is shut down. If you restart the server later, the table still exists, but the data does not. Thus, you need to create the table only once. In fact, if you or another user try to create a transient table with the same name as an existing transient table, you get an error message, even if the server has been shut down and restarted since the time that the table with that name was originally created. This behavior can be unexpected if you think that a transient table disappears as soon as you shut down the server.
Also, since a transient table persists (even though the data does not), you can use the DROP TABLE command to drop the table after you no longer need it.
Limitations
Transient tables have some limitations when compared to persistent in-memory tables.
▪Transient table data is not replicated to the Secondary server when you use the HotStandby component. Transient tables themselves (but not their data) are replicated to the HotStandby Secondary server. Thus, for failover to Secondary, you do not have to re-create transient tables. However, you must re-create any data in them.
▪Transient tables have restrictions on how they can be used with referential constraints. Transient tables can reference other transient tables and persistent tables. They cannot reference temporary tables. Temporary tables and persistent tables cannot reference a transient table.
▪Transient tables can be used only as replica tables in advanced replication systems, not as master tables.
Standards compliance
Transient tables are not defined by the ANSI standard for SQL. Transient tables are a solidDB® extension to the SQL standard.
Differences between temporary and transient tables
The main differences between temporary tables and transient tables are:
▪Transient tables allow all sessions (connections) in the system to see the same data. Temporary tables allow only the user who created a piece of data to see that data.
▪Because users may access the same data, transient tables use concurrency control. Only pessimistic concurrency control (locking) is supported.
▪Temporary tables are faster than transient tables because they do not use concurrency control.
▪The data in transient tables lasts until the server is shut down, while data in temporary tables lasts only until the user logs out of the session. This means that if one session inserts data into a transient table, then other sessions may see that data even after the creator of the data disconnects.
▪Data in transient tables is exportable using solexp tool. Data in temporary tables is not.
▪The referential integrity rules for the two table types are different.