]> git.openstreetmap.org Git - nominatim.git/blob - lib-sql/indices.sql
916d011710c64bff070368ccfb5fb912352de614
[nominatim.git] / lib-sql / indices.sql
1 -- SPDX-License-Identifier: GPL-2.0-only
2 --
3 -- This file is part of Nominatim. (https://nominatim.org)
4 --
5 -- Copyright (C) 2022 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
7
8 -- The following indicies are only useful during imoprt when all of placex is processed.
9
10 {% if drop %}
11   DROP INDEX IF EXISTS idx_placex_rank_address_sector;
12   DROP INDEX IF EXISTS idx_placex_rank_boundaries_sector;
13 {% endif %}
14
15 -- Indices used only during search and update.
16 -- These indices are created only after the indexing process is done.
17
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}};
20 ---
21 CREATE INDEX IF NOT EXISTS idx_placex_rank_search
22   ON placex USING BTREE (rank_search) {{db.tablespace.search_index}};
23 ---
24 CREATE INDEX IF NOT EXISTS idx_placex_rank_address
25   ON placex USING BTREE (rank_address) {{db.tablespace.search_index}};
26 ---
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;
30 ---
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;
36 ---
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;
40 ---
41 CREATE INDEX IF NOT EXISTS idx_osmline_parent_osm_id
42   ON location_property_osmline USING BTREE (osm_id) {{db.tablespace.search_index}};
43 ---
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.
47
48 {% if not drop %}
49 ---
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}};
52 ---
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}};
55 {% endif %}
56
57 -- Indices only needed for search.
58 {% if 'search_name' in db.tables %}
59 ---
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 ---
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}};
65 ---
66   CREATE INDEX IF NOT EXISTS idx_search_name_centroid
67     ON search_name USING GIST (centroid) {{db.tablespace.search_index}};
68
69   {% if postgres.has_index_non_key_column %}
70 ---
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;
75 ---
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;
80   {% endif %}
81 {% endif %}