mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
add NOT NULL and UNIQUE constraints where possible
This commit is contained in:
@@ -2,36 +2,48 @@
|
|||||||
--
|
--
|
||||||
-- This file is part of Nominatim. (https://nominatim.org)
|
-- This file is part of Nominatim. (https://nominatim.org)
|
||||||
--
|
--
|
||||||
-- Copyright (C) 2022 by the Nominatim developer community.
|
-- Copyright (C) 2026 by the Nominatim developer community.
|
||||||
-- For a full list of authors see the git log.
|
-- For a full list of authors see the git log.
|
||||||
|
|
||||||
drop table IF EXISTS search_name_blank CASCADE;
|
drop table IF EXISTS search_name_blank CASCADE;
|
||||||
CREATE TABLE search_name_blank (
|
CREATE TABLE search_name_blank (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
address_rank smallint,
|
address_rank smallint NOT NULL,
|
||||||
name_vector integer[],
|
name_vector integer[] NOT NULL,
|
||||||
centroid GEOMETRY(Geometry, 4326)
|
centroid GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
{% for partition in db.partitions %}
|
{% for partition in db.partitions %}
|
||||||
CREATE TABLE location_area_large_{{ partition }} () INHERITS (location_area_large) {{db.tablespace.address_data}};
|
CREATE TABLE location_area_large_{{ partition }} () INHERITS (location_area_large) {{db.tablespace.address_data}};
|
||||||
CREATE INDEX idx_location_area_large_{{ partition }}_place_id ON location_area_large_{{ partition }} USING BTREE (place_id) {{db.tablespace.address_index}};
|
CREATE INDEX idx_location_area_large_{{ partition }}_place_id
|
||||||
CREATE INDEX idx_location_area_large_{{ partition }}_geometry ON location_area_large_{{ partition }} USING GIST (geometry) {{db.tablespace.address_index}};
|
ON location_area_large_{{ partition }}
|
||||||
|
USING BTREE (place_id) {{db.tablespace.address_index}};
|
||||||
|
CREATE INDEX idx_location_area_large_{{ partition }}_geometry
|
||||||
|
ON location_area_large_{{ partition }}
|
||||||
|
USING GIST (geometry) {{db.tablespace.address_index}};
|
||||||
|
|
||||||
CREATE TABLE search_name_{{ partition }} () INHERITS (search_name_blank) {{db.tablespace.address_data}};
|
CREATE TABLE search_name_{{ partition }} () INHERITS (search_name_blank) {{db.tablespace.address_data}};
|
||||||
CREATE INDEX idx_search_name_{{ partition }}_place_id ON search_name_{{ partition }} USING BTREE (place_id) {{db.tablespace.address_index}};
|
CREATE UNIQUE INDEX idx_search_name_{{ partition }}_place_id
|
||||||
CREATE INDEX idx_search_name_{{ partition }}_centroid_street ON search_name_{{ partition }} USING GIST (centroid) {{db.tablespace.address_index}} where address_rank between 26 and 27;
|
ON search_name_{{ partition }}
|
||||||
CREATE INDEX idx_search_name_{{ partition }}_centroid_place ON search_name_{{ partition }} USING GIST (centroid) {{db.tablespace.address_index}} where address_rank between 2 and 25;
|
USING BTREE (place_id) {{db.tablespace.address_index}};
|
||||||
|
CREATE INDEX idx_search_name_{{ partition }}_centroid_street
|
||||||
|
ON search_name_{{ partition }} USING GIST (centroid) {{db.tablespace.address_index}}
|
||||||
|
WHERE address_rank between 26 and 27;
|
||||||
|
CREATE INDEX idx_search_name_{{ partition }}_centroid_place
|
||||||
|
ON search_name_{{ partition }} USING GIST (centroid) {{db.tablespace.address_index}}
|
||||||
|
WHERE address_rank between 2 and 25;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS location_road_{{ partition }};
|
DROP TABLE IF EXISTS location_road_{{ partition }};
|
||||||
CREATE TABLE location_road_{{ partition }} (
|
CREATE TABLE location_road_{{ partition }} (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
partition SMALLINT,
|
partition SMALLINT NOT NULL,
|
||||||
country_code VARCHAR(2),
|
country_code VARCHAR(2),
|
||||||
geometry GEOMETRY(Geometry, 4326)
|
geometry GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
) {{db.tablespace.address_data}};
|
) {{db.tablespace.address_data}};
|
||||||
CREATE INDEX idx_location_road_{{ partition }}_geometry ON location_road_{{ partition }} USING GIST (geometry) {{db.tablespace.address_index}};
|
CREATE INDEX idx_location_road_{{ partition }}_geometry
|
||||||
CREATE INDEX idx_location_road_{{ partition }}_place_id ON location_road_{{ partition }} USING BTREE (place_id) {{db.tablespace.address_index}};
|
ON location_road_{{ partition }}
|
||||||
|
USING GIST (geometry) {{db.tablespace.address_index}};
|
||||||
|
CREATE UNIQUE INDEX idx_location_road_{{ partition }}_place_id
|
||||||
|
ON location_road_{{ partition }}
|
||||||
|
USING BTREE (place_id) {{db.tablespace.address_index}};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -34,53 +34,53 @@ GRANT SELECT ON TABLE nominatim_properties TO "{{config.DATABASE_WEBUSER}}";
|
|||||||
|
|
||||||
drop table IF EXISTS location_area CASCADE;
|
drop table IF EXISTS location_area CASCADE;
|
||||||
CREATE TABLE location_area (
|
CREATE TABLE location_area (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
keywords INTEGER[],
|
keywords INTEGER[] NOT NULL,
|
||||||
partition SMALLINT,
|
partition SMALLINT NOT NULL,
|
||||||
rank_search SMALLINT NOT NULL,
|
rank_search SMALLINT NOT NULL,
|
||||||
rank_address SMALLINT NOT NULL,
|
rank_address SMALLINT NOT NULL,
|
||||||
country_code VARCHAR(2),
|
country_code VARCHAR(2),
|
||||||
isguess BOOL,
|
isguess BOOL NOT NULL,
|
||||||
postcode TEXT,
|
postcode TEXT,
|
||||||
centroid GEOMETRY(Point, 4326),
|
centroid GEOMETRY(Point, 4326) NOT NULL,
|
||||||
geometry GEOMETRY(Geometry, 4326)
|
geometry GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE location_area_large () INHERITS (location_area);
|
CREATE TABLE location_area_large () INHERITS (location_area);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS location_area_country;
|
DROP TABLE IF EXISTS location_area_country;
|
||||||
CREATE TABLE location_area_country (
|
CREATE TABLE location_area_country (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
country_code varchar(2),
|
country_code varchar(2) NOT NULL,
|
||||||
geometry GEOMETRY(Geometry, 4326)
|
geometry GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
) {{db.tablespace.address_data}};
|
) {{db.tablespace.address_data}};
|
||||||
CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry) {{db.tablespace.address_index}};
|
CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry) {{db.tablespace.address_index}};
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE location_property_tiger (
|
CREATE TABLE location_property_tiger (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
parent_place_id BIGINT,
|
parent_place_id BIGINT,
|
||||||
startnumber INTEGER,
|
startnumber INTEGER NOT NULL,
|
||||||
endnumber INTEGER,
|
endnumber INTEGER NOT NULL,
|
||||||
step SMALLINT,
|
step SMALLINT NOT NULL,
|
||||||
partition SMALLINT,
|
partition SMALLINT NOT NULL,
|
||||||
linegeo GEOMETRY,
|
linegeo GEOMETRY NOT NULL,
|
||||||
postcode TEXT);
|
postcode TEXT);
|
||||||
GRANT SELECT ON location_property_tiger TO "{{config.DATABASE_WEBUSER}}";
|
GRANT SELECT ON location_property_tiger TO "{{config.DATABASE_WEBUSER}}";
|
||||||
|
|
||||||
drop table if exists location_property_osmline;
|
drop table if exists location_property_osmline;
|
||||||
CREATE TABLE location_property_osmline (
|
CREATE TABLE location_property_osmline (
|
||||||
place_id BIGINT NOT NULL,
|
place_id BIGINT NOT NULL,
|
||||||
osm_id BIGINT,
|
osm_id BIGINT NOT NULL,
|
||||||
parent_place_id BIGINT,
|
parent_place_id BIGINT,
|
||||||
geometry_sector INTEGER,
|
geometry_sector INTEGER NOT NULL,
|
||||||
indexed_date TIMESTAMP,
|
indexed_date TIMESTAMP,
|
||||||
startnumber INTEGER,
|
startnumber INTEGER,
|
||||||
endnumber INTEGER,
|
endnumber INTEGER,
|
||||||
step SMALLINT,
|
step SMALLINT,
|
||||||
partition SMALLINT,
|
partition SMALLINT NOT NULL,
|
||||||
indexed_status SMALLINT,
|
indexed_status SMALLINT NOT NULL,
|
||||||
linegeo GEOMETRY,
|
linegeo GEOMETRY NOT NULL,
|
||||||
address HSTORE,
|
address HSTORE,
|
||||||
token_info JSONB, -- custom column for tokenizer use only
|
token_info JSONB, -- custom column for tokenizer use only
|
||||||
postcode TEXT,
|
postcode TEXT,
|
||||||
@@ -95,27 +95,28 @@ GRANT SELECT ON location_property_osmline TO "{{config.DATABASE_WEBUSER}}";
|
|||||||
drop table IF EXISTS search_name;
|
drop table IF EXISTS search_name;
|
||||||
{% if not db.reverse_only %}
|
{% if not db.reverse_only %}
|
||||||
CREATE TABLE search_name (
|
CREATE TABLE search_name (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
importance FLOAT,
|
importance FLOAT NOT NULL,
|
||||||
search_rank SMALLINT,
|
search_rank SMALLINT NOT NULL,
|
||||||
address_rank SMALLINT,
|
address_rank SMALLINT NOT NULL,
|
||||||
name_vector integer[],
|
name_vector integer[] NOT NULL,
|
||||||
nameaddress_vector integer[],
|
nameaddress_vector integer[] NOT NULL,
|
||||||
country_code varchar(2),
|
country_code varchar(2),
|
||||||
centroid GEOMETRY(Geometry, 4326)
|
centroid GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
) {{db.tablespace.search_data}};
|
) {{db.tablespace.search_data}};
|
||||||
CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {{db.tablespace.search_index}};
|
CREATE UNIQUE INDEX idx_search_name_place_id
|
||||||
|
ON search_name USING BTREE (place_id) {{db.tablespace.search_index}};
|
||||||
GRANT SELECT ON search_name to "{{config.DATABASE_WEBUSER}}" ;
|
GRANT SELECT ON search_name to "{{config.DATABASE_WEBUSER}}" ;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
drop table IF EXISTS place_addressline;
|
drop table IF EXISTS place_addressline;
|
||||||
CREATE TABLE place_addressline (
|
CREATE TABLE place_addressline (
|
||||||
place_id BIGINT,
|
place_id BIGINT NOT NULL,
|
||||||
address_place_id BIGINT,
|
address_place_id BIGINT NOT NULL,
|
||||||
distance FLOAT,
|
distance FLOAT NOT NULL,
|
||||||
cached_rank_address SMALLINT,
|
cached_rank_address SMALLINT NOT NULL,
|
||||||
fromarea boolean,
|
fromarea boolean NOT NULL,
|
||||||
isaddress boolean
|
isaddress boolean NOT NULL
|
||||||
) {{db.tablespace.search_data}};
|
) {{db.tablespace.search_data}};
|
||||||
CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {{db.tablespace.search_index}};
|
CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {{db.tablespace.search_index}};
|
||||||
|
|
||||||
@@ -128,18 +129,18 @@ CREATE TABLE placex (
|
|||||||
linked_place_id BIGINT,
|
linked_place_id BIGINT,
|
||||||
importance FLOAT,
|
importance FLOAT,
|
||||||
indexed_date TIMESTAMP,
|
indexed_date TIMESTAMP,
|
||||||
geometry_sector INTEGER,
|
geometry_sector INTEGER NOT NULL,
|
||||||
rank_address SMALLINT,
|
rank_address SMALLINT NOT NULL,
|
||||||
rank_search SMALLINT,
|
rank_search SMALLINT NOT NULL,
|
||||||
partition SMALLINT,
|
partition SMALLINT NOT NULL,
|
||||||
indexed_status SMALLINT,
|
indexed_status SMALLINT NOT NULL,
|
||||||
LIKE place INCLUDING CONSTRAINTS,
|
LIKE place INCLUDING CONSTRAINTS,
|
||||||
wikipedia TEXT, -- calculated wikipedia article name (language:title)
|
wikipedia TEXT, -- calculated wikipedia article name (language:title)
|
||||||
token_info JSONB, -- custom column for tokenizer use only
|
token_info JSONB, -- custom column for tokenizer use only
|
||||||
country_code varchar(2),
|
country_code varchar(2),
|
||||||
housenumber TEXT,
|
housenumber TEXT,
|
||||||
postcode TEXT,
|
postcode TEXT,
|
||||||
centroid GEOMETRY(Geometry, 4326)
|
centroid GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
) {{db.tablespace.search_data}};
|
) {{db.tablespace.search_data}};
|
||||||
|
|
||||||
CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {{db.tablespace.search_index}};
|
CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {{db.tablespace.search_index}};
|
||||||
@@ -214,10 +215,10 @@ CREATE TABLE location_postcodes (
|
|||||||
place_id BIGINT NOT NULL,
|
place_id BIGINT NOT NULL,
|
||||||
parent_place_id BIGINT,
|
parent_place_id BIGINT,
|
||||||
osm_id BIGINT,
|
osm_id BIGINT,
|
||||||
rank_search SMALLINT,
|
rank_search SMALLINT NOT NULL,
|
||||||
indexed_status SMALLINT,
|
indexed_status SMALLINT NOT NULL,
|
||||||
indexed_date TIMESTAMP,
|
indexed_date TIMESTAMP,
|
||||||
country_code varchar(2),
|
country_code varchar(2) NOT NULL,
|
||||||
postcode TEXT NOT NULL,
|
postcode TEXT NOT NULL,
|
||||||
centroid GEOMETRY(Geometry, 4326) NOT NULL,
|
centroid GEOMETRY(Geometry, 4326) NOT NULL,
|
||||||
geometry GEOMETRY(Geometry, 4326) NOT NULL
|
geometry GEOMETRY(Geometry, 4326) NOT NULL
|
||||||
|
|||||||
Reference in New Issue
Block a user