Skip to content

Commit

Permalink
Autoanalyze cache tables
Browse files Browse the repository at this point in the history
  • Loading branch information
greenape committed Jun 12, 2024
1 parent 582139d commit 8fc4270
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added

### Changed
- FlowDB now triggers an ANALYZE on newly created cache tables to generate statistics rather than waiting for autovacuum

### Fixed

Expand Down
7 changes: 7 additions & 0 deletions flowmachine/flowmachine/core/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def write_query_to_cache(
ddl_ops_func: Callable[[str, str], List[str]],
schema: Optional[str] = "cache",
sleep_duration: Optional[int] = 1,
analyze=True,
) -> "Query":
"""
Write a Query object into a postgres table and update the cache metadata about it.
Expand All @@ -159,6 +160,8 @@ def write_query_to_cache(
Name of the schema to write to
sleep_duration : int, default 1
Number of seconds to wait between polls when monitoring a query being written from elsewhere
analyze : bool, default True
Set to False to _disable_ running analyze on the newly created table to generate statistics
Returns
-------
Expand Down Expand Up @@ -203,6 +206,10 @@ def write_query_to_cache(
except Exception as exc:
logger.error(f"Error executing SQL. Error was {exc}")
raise exc
if analyze:
logger.debug(f"Running analyze for {schema}.{name}.")
trans.exec_driver_sql(f"ANALYZE {schema}.{name};")
logger.debug(f"Ran analyze for {schema}.{name}.")
if schema == "cache":
try:
write_cache_metadata(
Expand Down

0 comments on commit 8fc4270

Please sign in to comment.