Skip to content

Commit 37e12e0

Browse files
authored
Merge pull request #2148 from joto/cleanup-flex-table
Move analyze() and prepare() from table_connection_t to flex_table_t
2 parents 664681d + 7486cdb commit 37e12e0

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/flex-table.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ bool flex_table_t::has_columns_with_expire() const noexcept
242242
[](auto const &column) { return column.has_expire(); });
243243
}
244244

245+
void flex_table_t::prepare(pg_conn_t const &db_connection) const
246+
{
247+
if (has_id_column() && has_columns_with_expire()) {
248+
db_connection.exec(build_sql_prepare_get_wkb());
249+
}
250+
}
251+
252+
void flex_table_t::analyze(pg_conn_t const &db_connection) const
253+
{
254+
analyze_table(db_connection, schema(), name());
255+
}
256+
245257
static void enable_check_trigger(pg_conn_t const &db_connection,
246258
flex_table_t const &table)
247259
{
@@ -285,7 +297,7 @@ void table_connection_t::start(pg_conn_t const &db_connection, bool append)
285297
enable_check_trigger(db_connection, table());
286298
}
287299

288-
prepare(db_connection);
300+
table().prepare(db_connection);
289301
}
290302

291303
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,
368380
}
369381

370382
log_info("Analyzing table '{}'...", table().name());
371-
analyze(db_connection);
372-
}
373-
374-
void table_connection_t::prepare(pg_conn_t const &db_connection)
375-
{
376-
if (table().has_id_column() && table().has_columns_with_expire()) {
377-
db_connection.exec(table().build_sql_prepare_get_wkb());
378-
}
379-
}
380-
381-
void table_connection_t::analyze(pg_conn_t const &db_connection)
382-
{
383-
analyze_table(db_connection, table().schema(), table().name());
383+
table().analyze(db_connection);
384384
}
385385

386386
void table_connection_t::create_id_index(pg_conn_t const &db_connection)

src/flex-table.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ class flex_table_t
199199

200200
std::size_t num() const noexcept { return m_table_num; }
201201

202+
void prepare(pg_conn_t const &db_connection) const;
203+
204+
void analyze(pg_conn_t const &db_connection) const;
205+
202206
private:
203207
/// The schema this table is in
204208
std::string m_schema;
@@ -270,10 +274,6 @@ class table_connection_t
270274

271275
flex_table_t const &table() const noexcept { return *m_table; }
272276

273-
void prepare(pg_conn_t const &db_connection);
274-
275-
void analyze(pg_conn_t const &db_connection);
276-
277277
void create_id_index(pg_conn_t const &db_connection);
278278

279279
/**

src/output-flex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,8 @@ output_flex_t::output_flex_t(output_flex_t const *other,
12661266
m_select_relation_members(other->m_select_relation_members)
12671267
{
12681268
for (auto &table : *m_tables) {
1269-
auto &tc = m_table_connections.emplace_back(&table, m_copy_thread);
1270-
tc.prepare(m_db_connection);
1269+
table.prepare(m_db_connection);
1270+
m_table_connections.emplace_back(&table, m_copy_thread);
12711271
}
12721272

12731273
for (auto &expire_output : *m_expire_outputs) {
@@ -1514,7 +1514,7 @@ void output_flex_t::reprocess_marked()
15141514
for (auto &table : m_table_connections) {
15151515
if (table.table().matches_type(osmium::item_type::way) &&
15161516
table.table().has_id_column()) {
1517-
table.analyze(m_db_connection);
1517+
table.table().analyze(m_db_connection);
15181518
table.create_id_index(m_db_connection);
15191519
}
15201520
}

0 commit comments

Comments
 (0)