Skip to content

Commit

Permalink
perf(mssql): speed up existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Sep 11, 2024
1 parent cea9dfa commit 21509d1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ibis/backends/mssql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ def create_table(
namespace=ops.Namespace(catalog=catalog, database=db),
).to_expr()

def _in_memory_table_exists(self, name: str) -> bool:
# The single character U here means user-defined table
# see https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-objects-transact-sql?view=sql-server-ver16
sql = sg.select(sg.func("object_id", sge.convert(name), sge.convert("U"))).sql(
self.dialect
)
with self.begin() as cur:
[(result,)] = cur.execute(sql).fetchall()
return result is not None

def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
schema = op.schema
if null_columns := [col for col, dtype in schema.items() if dtype.is_null()]:
Expand Down

0 comments on commit 21509d1

Please sign in to comment.