Skip to content
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

Cake slice #558

Closed
wants to merge 5 commits into from
Closed

Cake slice #558

wants to merge 5 commits into from

Conversation

Algunenano
Copy link
Member

@Algunenano Algunenano commented May 1, 2020

Trac: https://trac.osgeo.org/postgis/ticket/4676

Some performance improvements, mostly based around the PG12+ ability of retrieve only a slice of a toasted object.

Improvements for big geometries:

  • ST_SRID
-- explain analyze Select ST_SRID(the_geom) from benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020;
-- Before latency average = 16.983 ms
-- After latency average = 0.145 ms
-- Perf: 117 x
  • ST_NDims:
EXPLAIN ANALYZE SELECT ST_NDims(the_geom) from benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020;
-- Before latency average = 16.635 ms
-- After latency average = 0.143 ms 
-- Perf: 116.32x
  • Equivalent improvements for ST_zmflag, postgis_hasbbox, SE_Is3D, SE_IsMeasured

Improvements for point (cast from postgis point to postgresql point):

-- EXPLAIN ANALYZE Select point(the_geom) from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293;
-- Before latency average = 215.468 ms
-- After latency average = 164.299 ms
-- Perf: 1.31x

Improvements for big geometry comparison

This affects any function using gserialized_datum_get_box2df_p, which are all the gist ones.

huge_polygon && huge_polygon

-- explain analyze Select a.the_geom && a.the_geom from benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020 a, benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020 b;
-- Before latency average = 423.047 ms
-- After latency average = 0.886 ms
-- Perf: 477.47x

point && point maintains performance

-- explain analyze with points as (Select the_geom from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293 limit 1000) Select a.the_geom && b.the_geom from points a, points b;
-- Before latency average = 321.904 ms
-- After commit to avoid re-reads = 323.928 ms
-- Perf: 0.993x

Example with a query to read a tile

Table with index created but not selected:

Indexes:
    "lpr_000b16a_e_1_pkey" PRIMARY KEY, btree (cartodb_id)
    "lpr_000b16a_e_1_the_geom_idx" gist (the_geom)
    "lpr_000b16a_e_1_the_geom_webmercator_idx" gist (the_geom_webmercator)

Query:

explain analyze Select count(*) from benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020 where the_geom_webmercator && ST_TileEnvelope(3,1,1);
  • Pgbench:
explain analyze Select count(*) from benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020 where the_geom_webmercator && ST_TileEnvelope(3,1,1);
-- Before latency average = 16.845 ms
-- After latency average = 0.209 ms
-- Perf: 80.59x
  • Plan before:
 Aggregate  (cost=4.39..4.40 rows=1 width=8) (actual time=34.918..34.918 rows=1 loops=1)
   ->  Seq Scan on benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020  (cost=0.00..4.38 rows=3 width=0) (actual 
time=20.303..34.907 rows=3 loops=1)
         Filter: (the_geom_webmercator && '0103000020110F00000100000005000000DC183A68F4A96CC193107C45F81B6341DC183A68F4A96CC1
DC183A68F4A96C4193107C45F81B63C1DC183A68F4A96C4193107C45F81B63C193107C45F81B6341DC183A68F4A96CC193107C45F81B6341'::geometry)
         Rows Removed by Filter: 10
 Planning Time: 0.170 ms
 Execution Time: 34.958 ms
  • Plan afte is the same, just faster:
 Aggregate  (cost=4.39..4.40 rows=1 width=8) (actual time=0.159..0.159 rows=1 loops=1)
   ->  Seq Scan on benchmark_4c7214d90a79aa6760367a084a4d4a2f61fbe1c6cc4f7f9e76020  (cost=0.00..4.38 rows=3 width=0) (actual 
time=0.134..0.153 rows=3 loops=1)
         Filter: (the_geom_webmercator && '0103000020110F00000100000005000000DC183A68F4A96CC193107C45F81B6341DC183A68F4A96CC1
DC183A68F4A96C4193107C45F81B63C1DC183A68F4A96C4193107C45F81B63C193107C45F81B6341DC183A68F4A96CC193107C45F81B6341'::geometry)
         Rows Removed by Filter: 10
 Planning Time: 0.150 ms
 Execution Time: 0.195 ms

@pramsey
Copy link
Member

pramsey commented May 1, 2020

👍

@strk strk closed this in 83c62db May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants