Skip to content

Commit

Permalink
Feat/apply vacuum to schema only (#69)
Browse files Browse the repository at this point in the history
* feat(vacuum): analyse only created pivot table

* feat(vacuum): analyse only created pgr tables

* feat(changelog): update for VACUUM ANALYSE
  • Loading branch information
jmkerloch authored Feb 1, 2024
1 parent 28c867a commit 3a5dc66
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## NEXT-VERSION

ADDED:
- VACUUM ANALYSE is done only on created tables

FIX:
- Durée de parcours incohérente sur OSRM entre car-fastest et car-shortest

Expand Down
21 changes: 20 additions & 1 deletion r2gg/_pivot_to_pgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,31 @@ def pivot_to_pgr(source, cost_calculation_file_path, connection_work, connection

old_isolation_level = connection_out.isolation_level
connection_out.set_isolation_level(0)
vacuum_query = "VACUUM ANALYZE;"

# VACCUM ANALYZE for ways
vacuum_query = f"VACUUM ANALYZE {ways_table_name};"
logger.info("SQL: {}".format(vacuum_query))
st_execute = time.time()
cursor_out.execute(vacuum_query)
et_execute = time.time()
logger.info("Execution ended. Elapsed time : %s seconds." %(et_execute - st_execute))

# VACCUM ANALYZE for ways_vertices_pgr
vacuum_query = f"VACUUM ANALYZE {ways_table_name}_vertices_pgr;"
logger.info("SQL: {}".format(vacuum_query))
st_execute = time.time()
cursor_out.execute(vacuum_query)
et_execute = time.time()
logger.info("Execution ended. Elapsed time : %s seconds." %(et_execute - st_execute))

# VACCUM ANALYZE for turn_restrictions
vacuum_query = f"VACUUM ANALYZE {schema}.turn_restrictions;"
logger.info("SQL: {}".format(vacuum_query))
st_execute = time.time()
cursor_out.execute(vacuum_query)
et_execute = time.time()
logger.info("Execution ended. Elapsed time : %s seconds." %(et_execute - st_execute))

connection_out.set_isolation_level(old_isolation_level)
connection_out.commit()

Expand Down
4 changes: 3 additions & 1 deletion sql/bdtopo_v3.3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,6 @@ DROP FOREIGN TABLE IF EXISTS {output_schema}.troncon_de_route CASCADE;
DROP FOREIGN TABLE IF EXISTS {output_schema}.non_communication CASCADE;

END TRANSACTION;
VACUUM ANALYZE;
VACUUM ANALYZE {output_schema}.non_comm;
VACUUM ANALYZE {output_schema}.edges;
VACUUM ANALYZE {output_schema}.nodes;
4 changes: 3 additions & 1 deletion sql/bduni_convert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,6 @@ DROP FOREIGN TABLE IF EXISTS {output_schema}.troncon_de_route CASCADE;
DROP FOREIGN TABLE IF EXISTS {output_schema}.non_communication CASCADE;

END TRANSACTION;
VACUUM ANALYZE;
VACUUM ANALYZE {output_schema}.non_comm;
VACUUM ANALYZE {output_schema}.edges;
VACUUM ANALYZE {output_schema}.nodes;

0 comments on commit 3a5dc66

Please sign in to comment.