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 -- The following indicies are only useful during imoprt when all of placex is processed.
11 DROP INDEX IF EXISTS idx_placex_rank_address_sector;
12 DROP INDEX IF EXISTS idx_placex_rank_boundaries_sector;
15 -- Indices used only during search and update.
16 -- These indices are created only after the indexing process is done.
18 CREATE INDEX IF NOT EXISTS idx_place_addressline_address_place_id
19 ON place_addressline USING BTREE (address_place_id) {{db.tablespace.search_index}};
21 CREATE INDEX IF NOT EXISTS idx_placex_rank_search
22 ON placex USING BTREE (rank_search) {{db.tablespace.search_index}};
24 CREATE INDEX IF NOT EXISTS idx_placex_rank_address
25 ON placex USING BTREE (rank_address) {{db.tablespace.search_index}};
27 CREATE INDEX IF NOT EXISTS idx_placex_parent_place_id
28 ON placex USING BTREE (parent_place_id) {{db.tablespace.search_index}}
29 WHERE parent_place_id IS NOT NULL;
31 CREATE INDEX IF NOT EXISTS idx_placex_geometry_reverse_lookupPolygon
32 ON placex USING gist (geometry) {{db.tablespace.search_index}}
33 WHERE St_GeometryType(geometry) in ('ST_Polygon', 'ST_MultiPolygon')
34 AND rank_address between 4 and 25 AND type != 'postcode'
35 AND name is not null AND indexed_status = 0 AND linked_place_id is null;
37 CREATE INDEX IF NOT EXISTS idx_osmline_parent_place_id
38 ON location_property_osmline USING BTREE (parent_place_id) {{db.tablespace.search_index}}
39 WHERE parent_place_id is not null;
41 CREATE INDEX IF NOT EXISTS idx_osmline_parent_osm_id
42 ON location_property_osmline USING BTREE (osm_id) {{db.tablespace.search_index}};
44 CREATE INDEX IF NOT EXISTS idx_postcode_postcode
45 ON location_postcode USING BTREE (postcode) {{db.tablespace.search_index}};
46 -- Indices only needed for updating.
50 CREATE INDEX IF NOT EXISTS idx_location_area_country_place_id
51 ON location_area_country USING BTREE (place_id) {{db.tablespace.address_index}};
53 CREATE UNIQUE INDEX IF NOT EXISTS idx_place_osm_unique
54 ON place USING btree(osm_id, osm_type, class, type) {{db.tablespace.address_index}};
57 -- Indices only needed for search.
58 {% 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}};
63 CREATE INDEX IF NOT EXISTS idx_search_name_name_vector
64 ON search_name USING GIN (name_vector) WITH (fastupdate = off) {{db.tablespace.search_index}};
66 CREATE INDEX IF NOT EXISTS idx_search_name_centroid
67 ON search_name USING GIST (centroid) {{db.tablespace.search_index}};
69 {% if postgres.has_index_non_key_column %}
71 CREATE INDEX IF NOT EXISTS idx_placex_housenumber
72 ON placex USING btree (parent_place_id)
73 INCLUDE (housenumber) {{db.tablespace.search_index}}
74 WHERE housenumber is not null;
76 CREATE INDEX IF NOT EXISTS idx_osmline_parent_osm_id_with_hnr
77 ON location_property_osmline USING btree(parent_place_id)
78 INCLUDE (startnumber, endnumber) {{db.tablespace.search_index}}
79 WHERE startnumber is not null;