-
-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SP-GiST indexes when available #1357
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I've reindexed my planet database right after an initial import. The size benefit is clear, almost 1/3 of GIST index (except for planet_osm_point). All tests done with PG 13 and postgis 3.1. All my conditionnal indices are now spgist too, with the same benefit. |
What about speed of actually using SP-GIST versus GIST indexed data, e.g. during rendering in some toolchain, or display in e.g. QGIS? Do you have any experiences to share? E.g. I know from experience that using BRIN significantly slows down spatially accessing Polygon and Line type data in a GIS. |
Here is a comparison, done on an idle server with a fresh planet import: I kept the best EXPLAIN ANALYZE time of 10 runs. GIST
SP-GIST
There is a small 10% impact on a single query but of course all the data is in the cache and possible benefit of have more index/data in the cache thanks to small spgist index is lost in this single test. |
Thanks, that appears not to bad. It would also be interesting to see a comparison for other geometry types, especially Polygon. |
It is now possible to use an SP-GiST index (as well as any other index type) with the flex output. See https://osm2pgsql.org/doc/manual.html#defining-indexes for details. |
Since PostGIS 2.5 and PostgreSQL 11, spgist indexes are available for 2d and 3d geometries. PostGIS performance testing indicates they are beneficial with many overlapping objects. This is the situation with most osm2pgsql tables.
I collected some real-world data on the differences between the indexes. To better emulate tile server queries I turned parallelism and jit off.
The difference in polygon performance is likely to be more significant on servers with less RAM or when more queries are running, increasing the size of the working set. Mine has enough RAM to keep the entire GiST index cached in memory.
Most polygon and linestring tables will have objects that bbox overlap, so we should use spgist indexes for those tables. I could go either way on points.
Queries
Point in polygon (PIP)
polygon bbox
point tile
Footnotes
1: Index sizes are based on a single index build, but at least GiST index size is variable
The text was updated successfully, but these errors were encountered: