46
46
47
47
namespace {
48
48
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
-
60
49
void send_id_list (pg_conn_t const &db_connection,
61
50
std::string const &table, idlist_t const &ids)
62
51
{
@@ -97,7 +86,7 @@ std::string build_sql(options_t const &options, std::string const &templ)
97
86
fmt::arg (" using_tablespace" , using_tablespace),
98
87
fmt::arg (" data_tablespace" , tablespace_clause (options.tblsslim_data )),
99
88
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 ),
101
90
fmt::arg (" attribute_columns_definition" ,
102
91
options.extra_attributes ? " created timestamp with time zone,"
103
92
" version int4,"
@@ -663,17 +652,13 @@ void middle_pgsql_t::get_node_parents(idlist_t const &changed_nodes,
663
652
664
653
queries.emplace_back (" ANALYZE osm2pgsql_changed_nodes" );
665
654
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"(
677
662
CREATE OR REPLACE FUNCTION osm2pgsql_find_changed_ways() RETURNS void AS $$
678
663
DECLARE
679
664
changed_buckets RECORD;
@@ -692,16 +677,8 @@ BEGIN
692
677
END;
693
678
$$ LANGUAGE plpgsql
694
679
)" );
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()" );
705
682
706
683
queries.emplace_back (R"(
707
684
INSERT INTO osm2pgsql_changed_relations
@@ -1176,7 +1153,7 @@ table_sql sql_for_nodes(middle_pgsql_options const &options)
1176
1153
return sql;
1177
1154
}
1178
1155
1179
- table_sql sql_for_ways (middle_pgsql_options const &options )
1156
+ table_sql sql_for_ways ()
1180
1157
{
1181
1158
table_sql sql{};
1182
1159
@@ -1200,23 +1177,17 @@ table_sql sql_for_ways(middle_pgsql_options const &options)
1200
1177
" {users_table_access}"
1201
1178
" WHERE o.id = ANY($1::int8[])" };
1202
1179
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}" };
1220
1191
1221
1192
return sql;
1222
1193
}
@@ -1272,7 +1243,6 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
1272
1243
m_db_copy(m_copy_thread), m_append(options->append)
1273
1244
{
1274
1245
m_store_options.with_attributes = options->extra_attributes ;
1275
- m_store_options.way_node_index_id_shift = options->way_node_index_id_shift ;
1276
1246
1277
1247
if (options->middle_with_nodes ) {
1278
1248
m_store_options.nodes = true ;
@@ -1289,15 +1259,8 @@ middle_pgsql_t::middle_pgsql_t(std::shared_ptr<thread_pool_t> thread_pool,
1289
1259
1290
1260
log_debug (" Mid: pgsql, cache={}" , options->cache );
1291
1261
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
-
1299
1262
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 ()};
1301
1264
m_tables.relations () = table_desc{*options, sql_for_relations ()};
1302
1265
1303
1266
m_users_table = table_desc{*options, sql_for_users (m_store_options)};
@@ -1310,8 +1273,6 @@ void middle_pgsql_t::set_requirements(
1310
1273
log_debug (" nodes: {}" , m_store_options.nodes );
1311
1274
log_debug (" untagged_nodes: {}" , m_store_options.untagged_nodes );
1312
1275
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 );
1315
1276
log_debug (" with_attributes: {}" , m_store_options.with_attributes );
1316
1277
}
1317
1278
0 commit comments