1 -- SPDX-License-Identifier: GPL-2.0-only
3 -- This file is part of Nominatim. (https://nominatim.org)
5 -- Copyright (C) 2026 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
8 -- Helper functions for updates.
10 -- Invalidate all placex affected by inserting a new place into the placex table.
11 CREATE OR REPLACE FUNCTION update_invalidate_for_new_place(address_rank SMALLINT,
12 is_area BOOLEAN, area_size FLOAT,
13 otype TEXT, newgeom GEOMETRY)
19 diameter := update_place_diameter(address_rank);
20 is_area := COALESCE(is_area, ST_GeometryType(newgeom) in ('ST_Polygon','ST_MultiPolygon'));
21 -- Update dependencies for address parts.
22 -- Leaving countries out here because a newly inserted country is
23 -- more likely incorrect mapping.
24 IF address_rank BETWEEN 4 AND 25 THEN
26 IF COALESCE(area_size, ST_Area(newgeom)) <= 2.0 THEN
27 UPDATE placex SET indexed_status = 2
28 WHERE ST_Intersects(newgeom, placex.geometry)
29 AND indexed_status = 0
30 AND ((rank_address = 0 and rank_search > address_rank)
31 or rank_address > address_rank
32 or (osm_type = 'N' and rank_address between 4 and 25))
33 AND (rank_search < 28 or name is not null);
35 ELSEIF otype = 'N' THEN
37 UPDATE placex SET indexed_status = 2
38 WHERE ST_DWithin(newgeom, placex.geometry, diameter)
39 AND indexed_status = 0
40 AND ((rank_address = 0 and rank_search > address_rank)
41 or rank_address > address_rank
42 or (osm_type = 'N' and rank_address between 4 and 25))
43 AND (rank_search < 28 or name is not null);
46 -- Addressable places may cause reparenting of addr:place-based addresses.
47 IF address_rank BETWEEN 16 AND 25 THEN
48 UPDATE placex SET indexed_status = 2
49 WHERE indexed_status = 0
52 AND ST_DWithin(newgeom, placex.geometry, diameter);
55 -- Roads may cause reparenting for POI places
56 IF address_rank BETWEEN 26 AND 27 THEN
57 UPDATE placex SET indexed_status = 2
58 WHERE indexed_status = 0
60 AND ST_DWithin(newgeom, placex.geometry, diameter);
61 UPDATE location_property_osmline SET indexed_status = 2
62 WHERE indexed_status = 0
63 AND startnumber is not null
64 AND ST_DWithin(newgeom, linegeo, diameter);