diff --git a/src/flex-table.cpp b/src/flex-table.cpp index 9e9676c53..370499197 100644 --- a/src/flex-table.cpp +++ b/src/flex-table.cpp @@ -242,6 +242,18 @@ bool flex_table_t::has_columns_with_expire() const noexcept [](auto const &column) { return column.has_expire(); }); } +void flex_table_t::prepare(pg_conn_t const &db_connection) const +{ + if (has_id_column() && has_columns_with_expire()) { + db_connection.exec(build_sql_prepare_get_wkb()); + } +} + +void flex_table_t::analyze(pg_conn_t const &db_connection) const +{ + analyze_table(db_connection, schema(), name()); +} + static void enable_check_trigger(pg_conn_t const &db_connection, flex_table_t const &table) { @@ -285,7 +297,7 @@ void table_connection_t::start(pg_conn_t const &db_connection, bool append) enable_check_trigger(db_connection, table()); } - prepare(db_connection); + table().prepare(db_connection); } void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable, @@ -368,19 +380,7 @@ void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable, } log_info("Analyzing table '{}'...", table().name()); - analyze(db_connection); -} - -void table_connection_t::prepare(pg_conn_t const &db_connection) -{ - if (table().has_id_column() && table().has_columns_with_expire()) { - db_connection.exec(table().build_sql_prepare_get_wkb()); - } -} - -void table_connection_t::analyze(pg_conn_t const &db_connection) -{ - analyze_table(db_connection, table().schema(), table().name()); + table().analyze(db_connection); } void table_connection_t::create_id_index(pg_conn_t const &db_connection) diff --git a/src/flex-table.hpp b/src/flex-table.hpp index cc15febff..c1278f9f7 100644 --- a/src/flex-table.hpp +++ b/src/flex-table.hpp @@ -199,6 +199,10 @@ class flex_table_t std::size_t num() const noexcept { return m_table_num; } + void prepare(pg_conn_t const &db_connection) const; + + void analyze(pg_conn_t const &db_connection) const; + private: /// The schema this table is in std::string m_schema; @@ -270,10 +274,6 @@ class table_connection_t flex_table_t const &table() const noexcept { return *m_table; } - void prepare(pg_conn_t const &db_connection); - - void analyze(pg_conn_t const &db_connection); - void create_id_index(pg_conn_t const &db_connection); /** diff --git a/src/output-flex.cpp b/src/output-flex.cpp index daccd60fd..510746be0 100644 --- a/src/output-flex.cpp +++ b/src/output-flex.cpp @@ -1266,8 +1266,8 @@ output_flex_t::output_flex_t(output_flex_t const *other, m_select_relation_members(other->m_select_relation_members) { for (auto &table : *m_tables) { - auto &tc = m_table_connections.emplace_back(&table, m_copy_thread); - tc.prepare(m_db_connection); + table.prepare(m_db_connection); + m_table_connections.emplace_back(&table, m_copy_thread); } for (auto &expire_output : *m_expire_outputs) { @@ -1514,7 +1514,7 @@ void output_flex_t::reprocess_marked() for (auto &table : m_table_connections) { if (table.table().matches_type(osmium::item_type::way) && table.table().has_id_column()) { - table.analyze(m_db_connection); + table.table().analyze(m_db_connection); table.create_id_index(m_db_connection); } }