@@ -16,13 +16,12 @@ typedef boost::format fmt;
1616
1717#define BUFFER_SEND_SIZE 1024
1818
19-
20- table_t ::table_t (const string& conninfo, const string& name, const string& type, const columns_t & columns, const hstores_t & hstore_columns,
21- const int srid, const bool append, const bool slim, const bool drop_temp, const int hstore_mode,
22- const bool enable_hstore_index, const boost::optional<string>& table_space, const boost::optional<string>& table_space_index) :
23- conninfo (conninfo), name(name), type(type), sql_conn(nullptr ), copyMode(false ), srid((fmt(" %1%" ) % srid).str()),
24- append(append), slim(slim), drop_temp(drop_temp), hstore_mode(hstore_mode), enable_hstore_index(enable_hstore_index),
25- columns(columns), hstore_columns(hstore_columns), table_space(table_space), table_space_index(table_space_index)
19+ table_t ::table_t (string const &name, string const &type,
20+ columns_t const &columns, hstores_t const &hstore_columns,
21+ int const srid, bool const append, int const hstore_mode)
22+ : name(name), type(type), sql_conn(nullptr ), copyMode(false ),
23+ srid ((fmt(" %1%" ) % srid).str()), append(append), hstore_mode(hstore_mode),
24+ columns(columns), hstore_columns(hstore_columns)
2625{
2726 // if we dont have any columns
2827 if (columns.size () == 0 && hstore_mode != HSTORE_ALL)
@@ -36,11 +35,13 @@ table_t::table_t(const string& conninfo, const string& name, const string& type,
3635 del_fmt = fmt (" DELETE FROM %1% WHERE osm_id = %2%" );
3736}
3837
39- table_t ::table_t (const table_t & other):
40- conninfo (other.conninfo), name(other.name), type(other.type), sql_conn(nullptr ), copyMode(false ), buffer(), srid(other.srid),
41- append(other.append), slim(other.slim), drop_temp(other.drop_temp), hstore_mode(other.hstore_mode), enable_hstore_index(other.enable_hstore_index),
42- columns(other.columns), hstore_columns(other.hstore_columns), copystr(other.copystr), table_space(other.table_space),
43- table_space_index(other.table_space_index), single_fmt(other.single_fmt), del_fmt(other.del_fmt)
38+ table_t ::table_t (table_t const &other)
39+ : m_conninfo(other.m_conninfo), name(other.name), type(other.type),
40+ sql_conn (nullptr ), copyMode(false ), srid(other.srid), append(other.append),
41+ hstore_mode(other.hstore_mode), columns(other.columns),
42+ hstore_columns(other.hstore_columns), copystr(other.copystr),
43+ m_table_space(other.m_table_space), single_fmt(other.single_fmt),
44+ del_fmt(other.del_fmt)
4445{
4546 // if the other table has already started, then we want to execute
4647 // the same stuff to get into the same state. but if it hasn't, then
@@ -89,19 +90,23 @@ void table_t::commit()
8990void table_t::connect ()
9091{
9192 // connect
92- PGconn* _conn = PQconnectdb (conninfo .c_str ());
93+ PGconn * _conn = PQconnectdb (m_conninfo .c_str ());
9394 if (PQstatus (_conn) != CONNECTION_OK)
9495 throw std::runtime_error ((fmt (" Connection to database failed: %1%\n " ) % PQerrorMessage (_conn)).str ());
9596 sql_conn = _conn;
9697 // let commits happen faster by delaying when they actually occur
9798 pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, " SET synchronous_commit TO off;" );
9899}
99100
100- void table_t::start ()
101+ void table_t::start (std::string const &conninfo,
102+ boost::optional<std::string> const &table_space)
101103{
102104 if (sql_conn)
103105 throw std::runtime_error (name + " cannot start, its already started" );
104106
107+ m_conninfo = conninfo;
108+ m_table_space = table_space ? " TABLESPACE " + table_space.get () : " " ;
109+
105110 connect ();
106111 fprintf (stderr, " Setting up table: %s\n " , name.c_str ());
107112 pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, " SET client_min_messages = WARNING" );
@@ -144,20 +149,10 @@ void table_t::start()
144149 // doesn't need to be RESET on these tables
145150 sql += " WITH ( autovacuum_enabled = FALSE )" ;
146151 // add the main table space
147- if (table_space)
148- sql += " TABLESPACE " + table_space.get ();
152+ sql += m_table_space;
149153
150154 // create the table
151155 pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, sql);
152-
153- // slim mode needs this to be able to delete from tables in pending
154- if (slim && !drop_temp) {
155- sql = (fmt (" CREATE INDEX ON %1% USING BTREE (osm_id)" ) % name).str ();
156- if (table_space_index)
157- sql += " TABLESPACE " + table_space_index.get ();
158- pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, sql);
159- }
160-
161156 }// appending
162157 else {
163158 // check the columns against those in the existing table
@@ -208,7 +203,8 @@ void table_t::start()
208203 copyMode = true ;
209204}
210205
211- void table_t::stop ()
206+ void table_t::stop (bool updateable, bool enable_hstore_index,
207+ boost::optional<std::string> const &table_space_index)
212208{
213209 stop_copy ();
214210 if (!append)
@@ -221,14 +217,13 @@ void table_t::stop()
221217 if (srid == " 4326" ) {
222218 /* libosmium assures validity of geometries in 4326, so the WHERE can be skipped.
223219 Because we know the geom is already in 4326, no reprojection is needed for GeoHashing */
224- pgsql_exec_simple (
225- sql_conn, PGRES_COMMAND_OK,
226- (fmt (" CREATE TABLE %1%_tmp %2% AS\n "
227- " SELECT * FROM %1%\n "
228- " ORDER BY ST_GeoHash(way,10)\n "
229- " COLLATE \" C\" " ) %
230- name % (table_space ? " TABLESPACE " + table_space.get () : " " ))
231- .str ());
220+ pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK,
221+ (fmt (" CREATE TABLE %1%_tmp %2% AS\n "
222+ " SELECT * FROM %1%\n "
223+ " ORDER BY ST_GeoHash(way,10)\n "
224+ " COLLATE \" C\" " ) %
225+ name % m_table_space)
226+ .str ());
232227 } else {
233228 /* osm2pgsql's transformation from 4326 to another projection could make a geometry invalid,
234229 and these need to be filtered. Also, a transformation is needed for geohashing.
@@ -244,7 +239,7 @@ void table_t::stop()
244239 " ORDER BY ST_GeoHash(ST_Transform(ST_Envelope(way),4326),10)\n "
245240 // clang-format on
246241 " COLLATE \" C\" " ) %
247- name % (table_space ? " TABLESPACE " + table_space. get () : " " ) )
242+ name % m_table_space )
248243 .str ());
249244 pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, " RESET client_min_messages" );
250245 }
@@ -253,17 +248,23 @@ void table_t::stop()
253248 fprintf (stderr, " Copying %s to cluster by geometry finished\n " , name.c_str ());
254249 fprintf (stderr, " Creating geometry index on %s\n " , name.c_str ());
255250
251+ std::string tblspc_sql =
252+ table_space_index ? " TABLESPACE " + table_space_index.get () : " " ;
256253 // Use fillfactor 100 for un-updatable imports
257- pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, (fmt (" CREATE INDEX ON %1% USING GIST (way) %2% %3%" ) % name %
258- (slim && !drop_temp ? " " : " WITH (FILLFACTOR=100)" ) %
259- (table_space_index ? " TABLESPACE " + table_space_index.get () : " " )).str ());
254+ pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK,
255+ (fmt (" CREATE INDEX ON %1% USING GIST (way) %2% %3%" ) %
256+ name % (updateable ? " " : " WITH (FILLFACTOR=100)" ) %
257+ tblspc_sql)
258+ .str ());
260259
261260 /* slim mode needs this to be able to apply diffs */
262- if (slim && !drop_temp)
263- {
261+ if (updateable) {
264262 fprintf (stderr, " Creating osm_id index on %s\n " , name.c_str ());
265- pgsql_exec_simple (sql_conn, PGRES_COMMAND_OK, (fmt (" CREATE INDEX ON %1% USING BTREE (osm_id) %2%" ) % name %
266- (table_space_index ? " TABLESPACE " + table_space_index.get () : " " )).str ());
263+ pgsql_exec_simple (
264+ sql_conn, PGRES_COMMAND_OK,
265+ (fmt (" CREATE INDEX ON %1% USING BTREE (osm_id) %2%" ) % name %
266+ tblspc_sql)
267+ .str ());
267268 if (srid != " 4326" ) {
268269 pgsql_exec_simple (
269270 sql_conn, PGRES_COMMAND_OK,
0 commit comments