@@ -64,7 +64,7 @@ static std::string build_sql(options_t const &options, char const *templ)
6464
6565middle_pgsql_t ::table_desc::table_desc(options_t const &options,
6666 table_sql const &ts)
67- : m_create (build_sql(options, ts.create_table)),
67+ : m_create_table (build_sql(options, ts.create_table)),
6868 m_prepare_query (build_sql(options, ts.prepare_query)),
6969 m_copy_target(std::make_shared<db_target_descr_t >())
7070{
@@ -73,8 +73,9 @@ middle_pgsql_t::table_desc::table_desc(options_t const &options,
7373 m_copy_target->id = " id" ; // XXX hardcoded column name
7474
7575 if (options.with_forward_dependencies ) {
76- m_prepare_intarray = build_sql (options, ts.prepare_mark );
77- m_array_indexes = build_sql (options, ts.create_index );
76+ m_prepare_fw_dep_lookups =
77+ build_sql (options, ts.prepare_fw_dep_lookups );
78+ m_create_fw_dep_indexes = build_sql (options, ts.create_fw_dep_indexes );
7879 }
7980}
8081
@@ -97,9 +98,9 @@ void middle_pgsql_t::table_desc::stop(std::string const &conninfo,
9798 auto const qual_name = qualified_name (
9899 m_copy_target->schema , m_copy_target->name );
99100 sql_conn.exec (" DROP TABLE IF EXISTS {}" _format (qual_name));
100- } else if (build_indexes && !m_array_indexes .empty ()) {
101+ } else if (build_indexes && !m_create_fw_dep_indexes .empty ()) {
101102 fmt::print (stderr, " Building index on table: {}\n " , name ());
102- sql_conn.exec (m_array_indexes );
103+ sql_conn.exec (m_create_fw_dep_indexes );
103104 }
104105
105106 fmt::print (stderr, " Stopped table: {} in {}s\n " , name (), timer.stop ());
@@ -564,8 +565,8 @@ void middle_pgsql_t::start()
564565
565566 // Prepare queries for updating dependent objects
566567 for (auto &table : m_tables) {
567- if (!table.m_prepare_intarray .empty ()) {
568- m_db_connection.exec (table.m_prepare_intarray );
568+ if (!table.m_prepare_fw_dep_lookups .empty ()) {
569+ m_db_connection.exec (table.m_prepare_fw_dep_lookups );
569570 }
570571 }
571572 } else {
@@ -577,7 +578,7 @@ void middle_pgsql_t::start()
577578 table.m_copy_target ->schema , table.m_copy_target ->name );
578579 m_db_connection.exec (
579580 " DROP TABLE IF EXISTS {} CASCADE" _format (qual_name));
580- m_db_connection.exec (table.m_create );
581+ m_db_connection.exec (table.m_create_table );
581582 }
582583
583584 // The extra query connection is only needed in append mode, so close.
@@ -660,33 +661,34 @@ static table_sql sql_for_ways(bool has_bucket_index,
660661 " WHERE id = ANY($1::int8[]);\n " ;
661662
662663 if (has_bucket_index) {
663- sql.prepare_mark =
664+ sql.prepare_fw_dep_lookups =
664665 " PREPARE mark_ways_by_node(int8) AS"
665666 " SELECT id FROM {schema}{prefix}_ways w"
666667 " WHERE $1 = ANY(nodes)"
667668 " AND {schema}{prefix}_index_bucket(w.nodes)"
668669 " && {schema}{prefix}_index_bucket(ARRAY[$1]);\n " ;
669670 } else {
670- sql.prepare_mark = " PREPARE mark_ways_by_node(int8) AS"
671- " SELECT id FROM {schema}{prefix}_ways"
672- " WHERE nodes && ARRAY[$1];\n " ;
671+ sql.prepare_fw_dep_lookups = " PREPARE mark_ways_by_node(int8) AS"
672+ " SELECT id FROM {schema}{prefix}_ways"
673+ " WHERE nodes && ARRAY[$1];\n " ;
673674 }
674675
675676 if (way_node_index_id_shift == 0 ) {
676- sql.create_index =
677+ sql.create_fw_dep_indexes =
677678 " CREATE INDEX ON {schema}{prefix}_ways USING GIN (nodes)"
678679 " WITH (fastupdate = off) {index_tablespace};\n " ;
679680 } else {
680- sql.create_index = " CREATE OR REPLACE FUNCTION"
681- " {schema}{prefix}_index_bucket(int8[])"
682- " RETURNS int8[] AS $$\n "
683- " SELECT ARRAY(SELECT DISTINCT"
684- " unnest($1) >> {way_node_index_id_shift})\n "
685- " $$ LANGUAGE SQL IMMUTABLE;\n "
686- " CREATE INDEX {schema}{prefix}_ways_nodes_bucket_idx"
687- " ON {schema}{prefix}_ways"
688- " USING GIN ({schema}{prefix}_index_bucket(nodes))"
689- " WITH (fastupdate = off) {index_tablespace};\n " ;
681+ sql.create_fw_dep_indexes =
682+ " CREATE OR REPLACE FUNCTION"
683+ " {schema}{prefix}_index_bucket(int8[])"
684+ " RETURNS int8[] AS $$\n "
685+ " SELECT ARRAY(SELECT DISTINCT"
686+ " unnest($1) >> {way_node_index_id_shift})\n "
687+ " $$ LANGUAGE SQL IMMUTABLE;\n "
688+ " CREATE INDEX {schema}{prefix}_ways_nodes_bucket_idx"
689+ " ON {schema}{prefix}_ways"
690+ " USING GIN ({schema}{prefix}_index_bucket(nodes))"
691+ " WITH (fastupdate = off) {index_tablespace};\n " ;
690692 }
691693
692694 return sql;
@@ -711,17 +713,19 @@ static table_sql sql_for_relations() noexcept
711713 " SELECT members, tags"
712714 " FROM {schema}{prefix}_rels WHERE id = $1;\n " ;
713715
714- sql.prepare_mark = " PREPARE mark_rels_by_node(int8) AS"
715- " SELECT id FROM {schema}{prefix}_rels"
716- " WHERE parts && ARRAY[$1]"
717- " AND parts[1:way_off] && ARRAY[$1];\n "
718- " PREPARE mark_rels_by_way(int8) AS"
719- " SELECT id FROM {schema}{prefix}_rels"
720- " WHERE parts && ARRAY[$1]"
721- " AND parts[way_off+1:rel_off] && ARRAY[$1];\n " ;
722-
723- sql.create_index = " CREATE INDEX ON {schema}{prefix}_rels USING GIN (parts)"
724- " WITH (fastupdate = off) {index_tablespace};\n " ;
716+ sql.prepare_fw_dep_lookups =
717+ " PREPARE mark_rels_by_node(int8) AS"
718+ " SELECT id FROM {schema}{prefix}_rels"
719+ " WHERE parts && ARRAY[$1]"
720+ " AND parts[1:way_off] && ARRAY[$1];\n "
721+ " PREPARE mark_rels_by_way(int8) AS"
722+ " SELECT id FROM {schema}{prefix}_rels"
723+ " WHERE parts && ARRAY[$1]"
724+ " AND parts[way_off+1:rel_off] && ARRAY[$1];\n " ;
725+
726+ sql.create_fw_dep_indexes =
727+ " CREATE INDEX ON {schema}{prefix}_rels USING GIN (parts)"
728+ " WITH (fastupdate = off) {index_tablespace};\n " ;
725729
726730 return sql;
727731}
0 commit comments