1 -- SPDX-License-Identifier: GPL-2.0-only
3 -- This file is part of Nominatim. (https://nominatim.org)
5 -- Copyright (C) 2022 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
8 -- Indices used only during search and update.
9 -- These indices are created only after the indexing process is done.
11 CREATE INDEX IF NOT EXISTS idx_place_addressline_address_place_id
12 ON place_addressline USING BTREE (address_place_id) {{db.tablespace.search_index}};
14 CREATE INDEX IF NOT EXISTS idx_placex_rank_search
15 ON placex USING BTREE (rank_search) {{db.tablespace.search_index}};
17 CREATE INDEX IF NOT EXISTS idx_placex_rank_address
18 ON placex USING BTREE (rank_address) {{db.tablespace.search_index}};
20 CREATE INDEX IF NOT EXISTS idx_placex_parent_place_id
21 ON placex USING BTREE (parent_place_id) {{db.tablespace.search_index}}
22 WHERE parent_place_id IS NOT NULL;
24 CREATE INDEX IF NOT EXISTS idx_placex_geometry_reverse_lookupPolygon
25 ON placex USING gist (geometry) {{db.tablespace.search_index}}
26 WHERE St_GeometryType(geometry) in ('ST_Polygon', 'ST_MultiPolygon')
27 AND rank_address between 4 and 25 AND type != 'postcode'
28 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
30 CREATE INDEX IF NOT EXISTS idx_osmline_parent_place_id
31 ON location_property_osmline USING BTREE (parent_place_id) {{db.tablespace.search_index}};
33 CREATE INDEX IF NOT EXISTS idx_osmline_parent_osm_id
34 ON location_property_osmline USING BTREE (osm_id) {{db.tablespace.search_index}};
36 CREATE INDEX IF NOT EXISTS idx_postcode_postcode
37 ON location_postcode USING BTREE (postcode) {{db.tablespace.search_index}};
39 -- Indices only needed for updating.
42 CREATE INDEX IF NOT EXISTS idx_placex_pendingsector
43 ON placex USING BTREE (rank_address,geometry_sector) {{db.tablespace.address_index}}
44 WHERE indexed_status > 0;
46 CREATE INDEX IF NOT EXISTS idx_location_area_country_place_id
47 ON location_area_country USING BTREE (place_id) {{db.tablespace.address_index}};
49 CREATE UNIQUE INDEX IF NOT EXISTS idx_place_osm_unique
50 ON place USING btree(osm_id, osm_type, class, type) {{db.tablespace.address_index}};
52 CREATE INDEX IF NOT EXISTS idx_place_interpolations
53 ON place USING gist(geometry) {{db.tablespace.address_index}}
54 WHERE osm_type = 'W' and address ? 'interpolation';
57 -- Indices only needed for search.
59 {% if 'search_name' in db.tables %}
60 CREATE INDEX IF NOT EXISTS idx_search_name_nameaddress_vector
61 ON search_name USING GIN (nameaddress_vector) WITH (fastupdate = off) {{db.tablespace.search_index}};
62 CREATE INDEX IF NOT EXISTS idx_search_name_name_vector
63 ON search_name USING GIN (name_vector) WITH (fastupdate = off) {{db.tablespace.search_index}};
64 CREATE INDEX IF NOT EXISTS idx_search_name_centroid
65 ON search_name USING GIST (centroid) {{db.tablespace.search_index}};
67 {% if postgres.has_index_non_key_column %}
68 CREATE INDEX IF NOT EXISTS idx_placex_housenumber
69 ON placex USING btree (parent_place_id) INCLUDE (housenumber) WHERE housenumber is not null;
70 CREATE INDEX IF NOT EXISTS idx_osmline_parent_osm_id_with_hnr
71 ON location_property_osmline USING btree(parent_place_id) INCLUDE (startnumber, endnumber);