fix(mssql): fix temporary table creation and implement cache
#9434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MSSQL has two kinds of temporary tables.
tempdb.dbo
, prefixed with asingle
#
and suffixed with ~~112 underscores and a number.tempdb.dbo
, and prefixed with adouble
#
.The suffixing on local temporary tables is to avoid name collisions
between separate user sessions trying to create the same temporary table
name.
Otherwise, the two types of temporary tables are functionally
equivalent. Users need specific access to look at temporary tables that
they didn't create, and all temp tables are cleaned up after the session
closes and all stored procedures referencing those tables have run.
Because of the slightly wacky semantics of local temporary tables, this
PR makes all temp tables created by the MSSQL backend "global". This
makes the names much more predictable.
A user creating a temporary table with the name "hithere", will find
that there is no table called "hithere" in the output of
con.list_tables()
. Instead, they will find a table called "##hithere"if they run
con.list_tables(database=("tempdb", "dbo"))
.The returned table reference from the
create_table
call works the sameas any other table reference, and you can create persistent tables from
temporary tables. The only major hiccough is the perpending of the
##
on the table name, but that is the behavior of MSSQL.
I've also added in support for passing in explicit
catalog
anddatabase
tocreate_table
, which was missing (I believe this was anoversight, since MSSQL definitely supports this).
Resolves #9431