]> git.openstreetmap.org Git - nominatim.git/blob - lib-sql/tables/placex.sql
Merge pull request #4163 from Itz-Agasta/category-support
[nominatim.git] / lib-sql / tables / placex.sql
1 -- SPDX-License-Identifier: GPL-2.0-only
2 --
3 -- This file is part of Nominatim. (https://nominatim.org)
4 --
5 -- Copyright (C) 2026 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
7
8 -- placex - main table for searchable places
9
10 DROP TABLE IF EXISTS placex;
11 CREATE TABLE placex (
12   place_id BIGINT NOT NULL,
13   parent_place_id BIGINT,
14   linked_place_id BIGINT,
15   importance FLOAT NOT NULL,
16   indexed_date TIMESTAMP,
17   geometry_sector INTEGER NOT NULL,
18   rank_address SMALLINT NOT NULL,
19   rank_search SMALLINT NOT NULL,
20   partition SMALLINT NOT NULL,
21   indexed_status SMALLINT NOT NULL,
22   LIKE place INCLUDING CONSTRAINTS,
23   wikipedia TEXT, -- calculated wikipedia article name (language:title)
24   token_info JSONB, -- custom column for tokenizer use only
25   country_code varchar(2),
26   housenumber TEXT,
27   postcode TEXT,
28   centroid GEOMETRY(Geometry, 4326) NOT NULL
29   ) {{db.tablespace.search_data}};
30
31 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {{db.tablespace.search_index}};
32 {% for osm_type in ('N', 'W', 'R') %}
33 CREATE INDEX idx_placex_osmid_{{osm_type | lower}} ON placex
34   USING BTREE (osm_id) {{db.tablespace.search_index}}
35   WHERE osm_type = '{{osm_type}}';
36 {% endfor %}
37
38 -- Usage: - removing linkage status on update
39 --        - lookup linked places for /details
40 CREATE INDEX idx_placex_linked_place_id ON placex
41   USING BTREE (linked_place_id) {{db.tablespace.address_index}}
42   WHERE linked_place_id IS NOT NULL;
43
44 -- Usage: - check that admin boundaries do not overtake each other rank-wise
45 --        - check that place node in a admin boundary with the same address level
46 --        - boundary is not completely contained in a place area
47 --        - parenting of large-area or unparentable features
48 CREATE INDEX idx_placex_geometry_address_area_candidates ON placex
49   USING gist (geometry) {{db.tablespace.address_index}}
50   WHERE rank_address between 1 and 25
51         and ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon');
52
53 -- Usage: - POI is within building with housenumber
54 CREATE INDEX idx_placex_geometry_buildings ON placex
55   USING SPGIST (geometry) {{db.tablespace.address_index}}
56   WHERE address is not null and rank_search = 30
57         and ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon');
58
59 -- Usage: - linking of similar named places to boundaries
60 --        - linking of place nodes with same type to boundaries
61 CREATE INDEX idx_placex_geometry_placenode ON placex
62   USING SPGIST (geometry) {{db.tablespace.address_index}}
63   WHERE osm_type = 'N' and rank_search < 26
64         and categories <@ 'osm.place';
65
66 -- Usage: - is node part of a way?
67 --        - find parent of interpolation spatially
68 CREATE INDEX idx_placex_geometry_lower_rank_ways ON placex
69   USING SPGIST (geometry) {{db.tablespace.address_index}}
70   WHERE osm_type = 'W' and rank_search >= 26;
71
72 -- Usage: - linking place nodes by wikidata tag to boundaries
73 CREATE INDEX idx_placex_wikidata on placex
74   USING BTREE ((extratags -> 'wikidata')) {{db.tablespace.address_index}}
75   WHERE extratags ? 'wikidata'
76         and categories <@ 'osm.place'
77         and osm_type = 'N' and rank_search < 26;
78
79 -- The following two indexes function as a todo list for indexing.
80
81 CREATE INDEX idx_placex_rank_address_sector ON placex
82   USING BTREE (rank_address, geometry_sector) {{db.tablespace.address_index}}
83   WHERE indexed_status > 0;
84
85 CREATE INDEX idx_placex_rank_boundaries_sector ON placex
86   USING BTREE (rank_search, geometry_sector) {{db.tablespace.address_index}}
87   WHERE categories <@ 'osm.boundary.administrative'
88         and indexed_status > 0;
89