@@ -127,8 +127,6 @@ middle_pgsql_t::table_desc::table_desc(options_t const &options,
127127 m_copy_target->id = " id" ;
128128
129129 if (options.with_forward_dependencies ) {
130- m_prepare_fw_dep_lookups =
131- build_sql (options, ts.prepare_fw_dep_lookups );
132130 m_create_fw_dep_indexes = build_sql (options, ts.create_fw_dep_indexes );
133131 }
134132}
@@ -859,9 +857,57 @@ INSERT INTO osm2pgsql_changed_relations
859857 parent_ways->size (), parent_relations->size ());
860858}
861859
862- idlist_t middle_pgsql_t::get_rels_by_way (osmid_t osm_id)
860+ void middle_pgsql_t::get_way_parents (
861+ osmium::index::IdSetSmall<osmid_t > const &changed_ways,
862+ osmium::index::IdSetSmall<osmid_t > *parent_relations) const
863863{
864- return get_ids_from_db (&m_db_connection, " mark_rels_by_way" , osm_id);
864+ util::timer_t timer;
865+
866+ auto const num_relations_referenced_by_nodes = parent_relations->size ();
867+
868+ m_db_connection.exec (" BEGIN" );
869+ m_db_connection.exec (" CREATE TEMP TABLE osm2pgsql_changed_ways"
870+ " (id int8 NOT NULL) ON COMMIT DROP" );
871+ m_db_connection.exec (" CREATE TEMP TABLE osm2pgsql_changed_relations"
872+ " (id int8 NOT NULL) ON COMMIT DROP" );
873+
874+ send_id_list (m_db_connection, " osm2pgsql_changed_ways" , changed_ways);
875+
876+ m_db_connection.exec (" ANALYZE osm2pgsql_changed_ways" );
877+
878+ if (m_options->middle_database_format == 1 ) {
879+ m_db_connection.exec (build_sql (*m_options, R"(
880+ INSERT INTO osm2pgsql_changed_relations
881+ SELECT DISTINCT r.id
882+ FROM {schema}"{prefix}_rels" r, osm2pgsql_changed_ways w
883+ WHERE r.parts && ARRAY[w.id]
884+ AND r.parts[way_off+1:rel_off] && ARRAY[w.id]
885+ )" ));
886+ } else {
887+ m_db_connection.exec (build_sql (*m_options, R"(
888+ INSERT INTO osm2pgsql_changed_relations
889+ SELECT DISTINCT r.id
890+ FROM {schema}"{prefix}_rels" r, osm2pgsql_changed_ways c
891+ WHERE {schema}"{prefix}_member_ids"(r.members, 'W'::char) && ARRAY[c.id];
892+ )" ));
893+ }
894+
895+ load_id_list (m_db_connection, " osm2pgsql_changed_relations" ,
896+ parent_relations);
897+
898+ m_db_connection.exec (" COMMIT" );
899+
900+ timer.stop ();
901+ log_debug (" Found {} ways that are new/changed in input or parent of"
902+ " changed node." ,
903+ changed_ways.size ());
904+ log_debug (" Found in {} their {} parent relations." ,
905+ std::chrono::duration_cast<std::chrono::seconds>(timer.elapsed ()),
906+ parent_relations->size () - num_relations_referenced_by_nodes);
907+
908+ // (Potentially) contains parent relations from nodes and from ways. Make
909+ // sure they are merged.
910+ parent_relations->sort_unique ();
865911}
866912
867913void middle_pgsql_t::way_set (osmium::Way const &way)
@@ -1223,13 +1269,6 @@ void middle_pgsql_t::start()
12231269 // problems when accessing the intarrays.
12241270 m_db_connection.set_config (" jit_above_cost" , " -1" );
12251271 m_db_connection.set_config (" max_parallel_workers_per_gather" , " 0" );
1226-
1227- // Prepare queries for updating dependent objects
1228- for (auto &table : m_tables) {
1229- if (!table.m_prepare_fw_dep_lookups .empty ()) {
1230- m_db_connection.exec (table.m_prepare_fw_dep_lookups );
1231- }
1232- }
12331272 } else {
12341273 if (m_store_options.db_format == 2 ) {
12351274 table_setup (m_db_connection, m_users_table);
@@ -1488,12 +1527,6 @@ static table_sql sql_for_relations_format1()
14881527 " SELECT members, tags"
14891528 " FROM {schema}\" {prefix}_rels\" WHERE id = $1;\n " ;
14901529
1491- sql.prepare_fw_dep_lookups =
1492- " PREPARE mark_rels_by_way(int8) AS"
1493- " SELECT id FROM {schema}\" {prefix}_rels\" "
1494- " WHERE parts && ARRAY[$1]"
1495- " AND parts[way_off+1:rel_off] && ARRAY[$1];\n " ;
1496-
14971530 sql.create_fw_dep_indexes =
14981531 " CREATE INDEX ON {schema}\" {prefix}_rels\" USING GIN (parts)"
14991532 " WITH (fastupdate = off) {index_tablespace};\n " ;
@@ -1528,12 +1561,6 @@ static table_sql sql_for_relations_format2()
15281561 " {users_table_access}"
15291562 " WHERE o.id = $1;\n " ;
15301563
1531- sql.prepare_fw_dep_lookups =
1532- " PREPARE mark_rels_by_way(int8) AS"
1533- " SELECT DISTINCT id FROM {schema}\" {prefix}_rels\" "
1534- " WHERE {schema}\" {prefix}_member_ids\" (members, 'W'::char)"
1535- " @> ARRAY[$1::bigint];\n " ;
1536-
15371564 sql.create_fw_dep_indexes =
15381565 " CREATE INDEX \" {prefix}_rels_node_members\" "
15391566 " ON {schema}\" {prefix}_rels\" USING GIN"
0 commit comments