]> git.openstreetmap.org Git - nominatim.git/blob - sql/tables.sql
clean up query logging
[nominatim.git] / sql / tables.sql
1 drop table if exists import_status;
2 CREATE TABLE import_status (
3   lastimportdate timestamp NOT NULL
4   );
5 GRANT SELECT ON import_status TO "{www-user}" ;
6
7 drop table if exists import_osmosis_log;
8 CREATE TABLE import_osmosis_log (
9   batchend timestamp,
10   batchsize integer,
11   starttime timestamp,
12   endtime timestamp,
13   event text
14   );
15
16 CREATE TABLE new_query_log (
17   type text,
18   starttime timestamp,
19   ipaddress text,
20   useragent text,
21   language text,
22   query text,
23   searchterm text,
24   endtime timestamp,
25   results integer,
26   format text,
27   secret text
28   );
29 CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime);
30 GRANT INSERT ON new_query_log TO "{www-user}" ;
31 GRANT UPDATE ON new_query_log TO "{www-user}" ;
32 GRANT SELECT ON new_query_log TO "{www-user}" ;
33
34 GRANT SELECT ON TABLE country_name TO "{www-user}";
35 GRANT SELECT ON TABLE gb_postcode TO "{www-user}";
36
37 drop table IF EXISTS word;
38 CREATE TABLE word (
39   word_id INTEGER,
40   word_token text,
41   word text,
42   class text,
43   type text,
44   country_code varchar(2),
45   search_name_count INTEGER,
46   operator TEXT
47   ) {ts:search-data};
48 CREATE INDEX idx_word_word_token on word USING BTREE (word_token) {ts:search-index};
49 GRANT SELECT ON word TO "{www-user}" ;
50 DROP SEQUENCE IF EXISTS seq_word;
51 CREATE SEQUENCE seq_word start 1;
52
53 drop table IF EXISTS location_area CASCADE;
54 CREATE TABLE location_area (
55   partition integer,
56   place_id BIGINT,
57   country_code VARCHAR(2),
58   keywords INTEGER[],
59   rank_search INTEGER NOT NULL,
60   rank_address INTEGER NOT NULL,
61   isguess BOOL
62   );
63 SELECT AddGeometryColumn('location_area', 'centroid', 4326, 'POINT', 2);
64 SELECT AddGeometryColumn('location_area', 'geometry', 4326, 'GEOMETRY', 2);
65
66 CREATE TABLE location_area_large () INHERITS (location_area);
67
68 drop table IF EXISTS location_property CASCADE;
69 CREATE TABLE location_property (
70   place_id BIGINT,
71   partition integer,
72   parent_place_id BIGINT,
73   housenumber TEXT,
74   postcode TEXT
75   );
76 SELECT AddGeometryColumn('location_property', 'centroid', 4326, 'POINT', 2);
77
78 CREATE TABLE location_property_aux () INHERITS (location_property);
79 CREATE INDEX idx_location_property_aux_place_id ON location_property_aux USING BTREE (place_id);
80 CREATE INDEX idx_location_property_aux_parent_place_id ON location_property_aux USING BTREE (parent_place_id);
81 CREATE INDEX idx_location_property_aux_housenumber_parent_place_id ON location_property_aux USING BTREE (parent_place_id, housenumber);
82 GRANT SELECT ON location_property_aux TO "{www-user}";
83
84 CREATE TABLE location_property_tiger (linegeo GEOMETRY, place_id BIGINT, partition INTEGER, parent_place_id BIGINT, startnumber INTEGER, endnumber INTEGER, interpolationtype TEXT, postcode TEXT);
85 GRANT SELECT ON location_property_tiger TO "{www-user}";
86
87 drop table IF EXISTS search_name;
88 CREATE TABLE search_name (
89   place_id BIGINT,
90   search_rank integer,
91   address_rank integer,
92   importance FLOAT,
93   country_code varchar(2),
94   name_vector integer[],
95   nameaddress_vector integer[]
96   ) {ts:search-data};
97 SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
98 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
99
100 drop table IF EXISTS place_addressline;
101 CREATE TABLE place_addressline (
102   place_id BIGINT,
103   address_place_id BIGINT,
104   fromarea boolean,
105   isaddress boolean,
106   distance float,
107   cached_rank_address integer
108   ) {ts:search-data};
109 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {ts:search-index};
110
111 drop table if exists placex;
112 CREATE TABLE placex (
113   place_id BIGINT NOT NULL,
114   partition integer,
115   LIKE place INCLUDING CONSTRAINTS,
116   parent_place_id BIGINT,
117   linked_place_id BIGINT,
118   rank_address INTEGER,
119   rank_search INTEGER,
120   importance FLOAT,
121   indexed_status INTEGER,
122   indexed_date TIMESTAMP,
123   wikipedia TEXT, -- calculated wikipedia article name (language:title)
124   geometry_sector INTEGER,
125   calculated_country_code varchar(2)
126   ) {ts:search-data};
127 SELECT AddGeometryColumn('placex', 'centroid', 4326, 'GEOMETRY', 2);
128 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
129 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
130 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index};
131 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search, geometry_sector) {ts:address-index};
132 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry) {ts:search-index};
133 CREATE INDEX idx_placex_adminname on placex USING BTREE (make_standard_name(name->'name'),rank_search) {ts:address-index} WHERE osm_type='N' and rank_search < 26;
134
135 DROP SEQUENCE IF EXISTS seq_place;
136 CREATE SEQUENCE seq_place start 1;
137 GRANT SELECT on placex to "{www-user}" ;
138 GRANT SELECT ON search_name to "{www-user}" ;
139 GRANT SELECT on place_addressline to "{www-user}" ;
140 GRANT SELECT ON seq_word to "{www-user}" ;
141 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
142 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
143 GRANT SELECT on location_area to "{www-user}" ;
144
145 -- insert creates the location tagbles, creates location indexes if indexed == true
146 CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
147     FOR EACH ROW EXECUTE PROCEDURE placex_insert();
148
149 -- update insert creates the location tables
150 CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
151     FOR EACH ROW EXECUTE PROCEDURE placex_update();
152
153 -- diff update triggers
154 CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
155     FOR EACH ROW EXECUTE PROCEDURE placex_delete();
156 CREATE TRIGGER place_before_delete BEFORE DELETE ON place
157     FOR EACH ROW EXECUTE PROCEDURE place_delete();
158 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
159     FOR EACH ROW EXECUTE PROCEDURE place_insert();
160
161 DROP SEQUENCE seq_postcodes;
162 CREATE SEQUENCE seq_postcodes start 1;
163
164 drop table import_polygon_error;
165 CREATE TABLE import_polygon_error (
166   osm_type char(1),
167   osm_id INTEGER,
168   class TEXT NOT NULL,
169   type TEXT NOT NULL,
170   name HSTORE,
171   country_code varchar(2),
172   updated timestamp,
173   errormessage text
174   );
175 SELECT AddGeometryColumn('import_polygon_error', 'prevgeometry', 4326, 'GEOMETRY', 2);
176 SELECT AddGeometryColumn('import_polygon_error', 'newgeometry', 4326, 'GEOMETRY', 2);
177 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
178 GRANT SELECT ON import_polygon_error TO "{www-user}";
179
180 drop table import_polygon_delete;
181 CREATE TABLE import_polygon_delete (
182   osm_type char(1),
183   osm_id INTEGER,
184   class TEXT NOT NULL,
185   type TEXT NOT NULL
186   );
187 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
188 GRANT SELECT ON import_polygon_delete TO "{www-user}";
189
190 drop sequence file;
191 CREATE SEQUENCE file start 1;
192
193 -- null table so it won't error
194 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
195 CREATE TABLE wikipedia_article (
196     language text NOT NULL,
197     title text NOT NULL,
198     langcount integer,
199     othercount integer,
200     totalcount integer,
201     lat double precision,
202     lon double precision,
203     importance double precision,
204     osm_type character(1),
205     osm_id bigint
206 );
207 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
208 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
209
210 CREATE TABLE wikipedia_redirect (
211     language text,
212     from_title text,
213     to_title text
214 );
215 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);
216