4646
4747namespace {
4848
49- bool check_bucket_index (pg_conn_t const *db_connection,
50- std::string const &prefix)
51- {
52- auto const res =
53- db_connection->exec (" SELECT relname FROM pg_class"
54- " WHERE relkind='i'"
55- " AND relname = '{}_ways_nodes_bucket_idx'" ,
56- prefix);
57- return res.num_tuples () > 0 ;
58- }
59-
6049void send_id_list (pg_conn_t const &db_connection,
6150 std::string const &table, idlist_t const &ids)
6251{
@@ -97,7 +86,7 @@ std::string build_sql(options_t const &options, std::string const &templ)
9786 fmt::arg (" using_tablespace" , using_tablespace),
9887 fmt::arg (" data_tablespace" , tablespace_clause (options.tblsslim_data )),
9988 fmt::arg (" index_tablespace" , tablespace_clause (options.tblsslim_index )),
100- fmt::arg (" way_node_index_id_shift" , options. way_node_index_id_shift ),
89+ fmt::arg (" way_node_index_id_shift" , 5 ),
10190 fmt::arg (" attribute_columns_definition" ,
10291 options.extra_attributes ? " created timestamp with time zone,"
10392 " version int4,"
@@ -663,17 +652,13 @@ void middle_pgsql_t::get_node_parents(idlist_t const &changed_nodes,
663652
664653 queries.emplace_back (" ANALYZE osm2pgsql_changed_nodes" );
665654
666- bool const has_bucket_index =
667- check_bucket_index (&m_db_connection, m_options->prefix );
668-
669- if (has_bucket_index) {
670- // The query to get the parent ways of changed nodes is "hidden"
671- // inside a PL/pgSQL function so that the query planner only sees
672- // a single node id that is being queried for. If we ask for all
673- // nodes at the same time the query planner sometimes thinks it is
674- // better to do a full table scan which totally destroys performance.
675- // This is due to the PostgreSQL statistics on ARRAYs being way off.
676- queries.emplace_back (R"(
655+ // The query to get the parent ways of changed nodes is "hidden"
656+ // inside a PL/pgSQL function so that the query planner only sees
657+ // a single node id that is being queried for. If we ask for all
658+ // nodes at the same time the query planner sometimes thinks it is
659+ // better to do a full table scan which totally destroys performance.
660+ // This is due to the PostgreSQL statistics on ARRAYs being way off.
661+ queries.emplace_back (R"(
677662CREATE OR REPLACE FUNCTION osm2pgsql_find_changed_ways() RETURNS void AS $$
678663DECLARE
679664 changed_buckets RECORD;
@@ -692,16 +677,8 @@ BEGIN
692677END;
693678$$ LANGUAGE plpgsql
694679)" );
695- queries.emplace_back (" SELECT osm2pgsql_find_changed_ways()" );
696- queries.emplace_back (" DROP FUNCTION osm2pgsql_find_changed_ways()" );
697- } else {
698- queries.emplace_back (R"(
699- INSERT INTO osm2pgsql_changed_ways
700- SELECT w.id
701- FROM {schema}"{prefix}_ways" w, osm2pgsql_changed_nodes n
702- WHERE w.nodes && ARRAY[n.id]
703- )" );
704- }
680+ queries.emplace_back (" SELECT osm2pgsql_find_changed_ways()" );
681+ queries.emplace_back (" DROP FUNCTION osm2pgsql_find_changed_ways()" );
705682
706683 queries.emplace_back (R"(
707684INSERT INTO osm2pgsql_changed_relations
@@ -1176,7 +1153,7 @@ table_sql sql_for_nodes(middle_pgsql_options const &options)
11761153 return sql;
11771154}
11781155
1179- table_sql sql_for_ways (middle_pgsql_options const &options )
1156+ table_sql sql_for_ways ()
11801157{
11811158 table_sql sql{};
11821159
@@ -1200,23 +1177,17 @@ table_sql sql_for_ways(middle_pgsql_options const &options)
12001177 " {users_table_access}"
12011178 " WHERE o.id = ANY($1::int8[])" };
12021179
1203- if (options.way_node_index_id_shift == 0 ) {
1204- sql.create_fw_dep_indexes = {
1205- " CREATE INDEX ON {schema}\" {prefix}_ways\" USING GIN (nodes)"
1206- " WITH (fastupdate = off) {index_tablespace}" };
1207- } else {
1208- sql.create_fw_dep_indexes = {
1209- " CREATE OR REPLACE FUNCTION"
1210- " {schema}\" {prefix}_index_bucket\" (int8[])"
1211- " RETURNS int8[] AS $$"
1212- " SELECT ARRAY(SELECT DISTINCT"
1213- " unnest($1) >> {way_node_index_id_shift})"
1214- " $$ LANGUAGE SQL IMMUTABLE" ,
1215- " CREATE INDEX \" {prefix}_ways_nodes_bucket_idx\" "
1216- " ON {schema}\" {prefix}_ways\" "
1217- " USING GIN ({schema}\" {prefix}_index_bucket\" (nodes))"
1218- " WITH (fastupdate = off) {index_tablespace}" };
1219- }
1180+ sql.create_fw_dep_indexes = {
1181+ " CREATE OR REPLACE FUNCTION"
1182+ " {schema}\" {prefix}_index_bucket\" (int8[])"
1183+ " RETURNS int8[] AS $$"
1184+ " SELECT ARRAY(SELECT DISTINCT"
1185+ " unnest($1) >> {way_node_index_id_shift})"
1186+ " $$ LANGUAGE SQL IMMUTABLE" ,
1187+ " CREATE INDEX \" {prefix}_ways_nodes_bucket_idx\" "
1188+ " ON {schema}\" {prefix}_ways\" "
1189+ " USING GIN ({schema}\" {prefix}_index_bucket\" (nodes))"
1190+ " WITH (fastupdate = off) {index_tablespace}" };
12201191
12211192 return sql;
12221193}
@@ -1272,7 +1243,6 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
12721243 m_db_copy(m_copy_thread), m_append(options->append)
12731244{
12741245 m_store_options.with_attributes = options->extra_attributes ;
1275- m_store_options.way_node_index_id_shift = options->way_node_index_id_shift ;
12761246
12771247 if (options->middle_with_nodes ) {
12781248 m_store_options.nodes = true ;
@@ -1289,15 +1259,8 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
12891259
12901260 log_debug (" Mid: pgsql, cache={}" , options->cache );
12911261
1292- bool const has_bucket_index =
1293- check_bucket_index (&m_db_connection, options->prefix );
1294-
1295- if (!has_bucket_index && options->append ) {
1296- log_debug (" You don't have a bucket index. See manual for details." );
1297- }
1298-
12991262 m_tables.nodes () = table_desc{*options, sql_for_nodes (m_store_options)};
1300- m_tables.ways () = table_desc{*options, sql_for_ways (m_store_options )};
1263+ m_tables.ways () = table_desc{*options, sql_for_ways ()};
13011264 m_tables.relations () = table_desc{*options, sql_for_relations ()};
13021265
13031266 m_users_table = table_desc{*options, sql_for_users (m_store_options)};
@@ -1310,8 +1273,6 @@ void middle_pgsql_t::set_requirements(
13101273 log_debug (" nodes: {}" , m_store_options.nodes );
13111274 log_debug (" untagged_nodes: {}" , m_store_options.untagged_nodes );
13121275 log_debug (" use_flat_node_file: {}" , m_store_options.use_flat_node_file );
1313- log_debug (" way_node_index_id_shift: {}" ,
1314- m_store_options.way_node_index_id_shift );
13151276 log_debug (" with_attributes: {}" , m_store_options.with_attributes );
13161277}
13171278
0 commit comments