#4405 closed defect (wontfix)
Index over ST_Transform(constant, SRID) breaks pg_upgrade
Reported by: | Algunenano | Owned by: | Algunenano |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS Fund Me |
Component: | build | Version: | master |
Keywords: | Cc: |
Description
As <subject> says, having an index which uses a ST_Transform(constant, XXXX) will break pg_upgrade.
Test case.
## Create the table
# create database test95; # \c test95 # create extension postgis; # create table t95 ( the_geom geometry ); # insert into t95 values ('SRID=4326; POINT(-133 40.2)'::geometry); # CREATE INDEX "idx_transf" ON "public"."t95" USING "btree" ("st_intersects"("the_geom", "st_transform"('0101000020E61000000000000000A060C0FAEDEBC0395B4440'::"geometry", 3857)));
## Run pg_upgrade
I've tested this doing:
- PG9.5, postgis 2.2 → PG10, postgis 2.4
- PG10, postgis 2.4 → PG11, postgis 2.5
pg_restore: creating CONSTRAINT "public.spatial_ref_sys spatial_ref_sys_pkey" pg_restore: creating INDEX "public.idx_transf" pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore: [archiver (db)] Error from TOC entry 3342; 1259 17766 INDEX idx_transf postgres pg_restore: [archiver (db)] could not execute query: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys Command was: -- For binary upgrade, must preserve pg_class oids SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('17766'::pg_catalog.oid);
Any function that calls ST_Intersects is also affected, e.g. ST_Buffer(geography).
AFAIK, it affects all stable postgis releases, although I'd expect that if the destination installation has PROJ 6 it'll do fine as it likely won't need the lookup of spatial_ref_sys
.
Change History (13)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
After looking into the code it appears that will also be present with PROJ 6 path as it also requires the projection to be available in spatial_ref_sys
.
comment:3 by , 5 years ago
Milestone: | PostGIS 2.3.10 → PostGIS 2.5.4 |
---|
comment:4 by , 5 years ago
Milestone: | PostGIS 2.5.4 → PostGIS 2.5.5 |
---|
comment:5 by , 4 years ago
I think this may be fixed already. I'll test in a bit and close out if I can't replicate issue.
comment:6 by , 4 years ago
Milestone: | PostGIS 2.5.5 → PostGIS 3.0.3 |
---|
okay it's still an issue.
I tried upgrading from PostGIS 2.5.5 dev PG 12 to PG 13 PostGIS 2.5.5dev and got same error
pg_restore: from TOC entry 3507; 1259 54514 INDEX idx_transf postgres pg_restore: error: could not execute query: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys Command was: -- For binary upgrade, must preserve pg_class oids SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('54514'::pg_catalog.oid); CREATE INDEX "idx_transf" ON "public"."t95" USING "btree" ("public"."st_intersects"("the_geom", "public"."st_transform"('0101000020E61000000000000000A060C0FAEDEBC0395B4440'::"public"."geometry", 3857)));
you think this is fixable. I haven't tried Proj 6 (this was testing with Proj 5.2). Seems like such a rare case and we have a workaround (just drop the index before you pg_upgrade)
comment:7 by , 4 years ago
Milestone: | PostGIS 3.0.3 → PostGIS Fund Me |
---|---|
Version: | 2.3.x → master |
I don't think this is fixable with our current spatial_ref_sys desisgn. To fix it in my migrations I've hardcoded the necessary SRID transformation strings inside Postgis, but that isn't a proper solution.
I think that ideally we would have a set of static SRIDs inside Postgis/PROJ (independent of spatial_ref_sys) that can't be modified by the end user and then allow having other SRIDS (as long as they don't collide with the static ones). This would mean a major change which I'm not sure we want to tackle.
comment:8 by , 4 years ago
with [c1b8d14d8900dc835fd5782f364364ffa963919e/git] we have a an util/check_cluster_upgrade.sh script that can be useful to put this case under automated testing. I've tried it and it indeed fails with:
pg_restore: error: could not execute query: ERROR: Cannot find SRID (4326) in spatial_ref_sys
When upgrading a cluster from 12 to 13
comment:9 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Not fixable as long as we keep spatial_ref_sys as the source of truth
follow-up: 12 comment:10 by , 3 years ago
Is this due to spatial_ref_sys contents NOT being visible at the time the table using the index is created ?
comment:11 by , 3 years ago
A reorganization of spatial_ref_sys might be an occasion to look at this, see #4987
comment:12 by , 3 years ago
Replying to strk:
Is this due to spatial_ref_sys contents NOT being visible at the time the table using the index is created ?
Yes - NOT having data is the issue for pg_upgrade.
The issue is when pg_upgrade runs I think it restores all the structures first and the data later but for some reason it restores the indexes before the data. I think I complained about this on pg-hackers (thought I forget). The assumption is since all functions used in indexes are immutable, they should not rely on data in any tables. AS such it shouldn't matter the order you load the tables. In this case other tables get loaded first and fail the index check because the spatial_ref_sys table is empty. Actually I don't even think a table has to have data for it to fail the index check cause the index goes to check on the function it relies on to index empty data (I could be mistaken here).
Why they can't create indexes after loading data I don't understand. Perhaps because it might slow the build of materialized views. Have no clue.
I would think if they just changed the order of how they do things it would be fine.
comment:13 by , 3 years ago
A reorganization of spatial_ref_sys might be an occasion to look at this, see #4987
In this case, that reorganization would not fix the issue. As robe said, the problem is that the table is created, then the indexes, then the data is added.
Speculation over IRC: