Skip to content

Commit

Permalink
Make vacuum of output tables in XMatchPlanner optional
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 14, 2024
1 parent a0550fa commit 913db7f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python/target_selection/xmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,9 @@ def run(
Parameters
----------
vacuum : bool
Vacuum all output tables before processing new catalogues.
Vacuum all output tables before and after processing new catalogues.
analyze : bool
Analyze all output tables before processing new catalogues.
Analyze all output tables before and after processing new catalogues.
from_ : str
Table from which to start running the process. Useful in reruns
to skip tables already processed.
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def run(
self.process_model(model, force=force)

if not dry_run:
self.load_output_tables(model, keep_temp=keep_temp)
self.load_output_tables(model, keep_temp=keep_temp, vacuum=vacuum)

self.log.info(f"Cross-matching completed in {timer.interval:.3f} s.")

Expand Down Expand Up @@ -2031,16 +2031,16 @@ def _run_phase_3(self, model):

self._analyze(rel_model_sb, catalog=False)

def load_output_tables(self, model, keep_temp=False):
def load_output_tables(self, model, keep_temp=False, vacuum=True):
"""Loads the temporary tables into the output tables."""

self._load_output_table(TempCatalog, Catalog, keep_temp=keep_temp)
self._load_output_table(TempCatalog, Catalog, keep_temp=keep_temp, vacuum=vacuum)

rel_model_sb = self.get_relational_model(model, sandboxed=True, create=False)
rel_model = self.get_relational_model(model, sandboxed=False, create=True)
self._load_output_table(rel_model_sb, rel_model, keep_temp=keep_temp)
self._load_output_table(rel_model_sb, rel_model, keep_temp=keep_temp, vacuum=vacuum)

def _load_output_table(self, from_model, to_model, keep_temp=False):
def _load_output_table(self, from_model, to_model, keep_temp=False, vacuum=True):
"""Copies the temporary table to the real output table."""

to_table = f"{to_model._meta.schema}.{to_model._meta.table_name}"
Expand Down Expand Up @@ -2069,7 +2069,7 @@ def _load_output_table(self, from_model, to_model, keep_temp=False):
self.database.drop_tables([from_model])
self.log.info(f"Dropped temporary table {from_table}.")

if n_rows > 0:
if n_rows > 0 and vacuum:
self.log.debug(f"Running VACUUM ANALYZE on {to_table}.")
vacuum_table(self.database, to_table, vacuum=True, analyze=True)

Expand Down

0 comments on commit 913db7f

Please sign in to comment.