last day (14 days later) » 

10:51 AM
0
A: PostgreSQL index in temporarly table

Vao Tsunto check if you right, you can leave sn as is and apply ST_Buffer on join: SELECT luc.* FROM spatial_derived.lucas12 luc, (SELECT geom FROM spatial_derived.germany_bld WHERE state = 'SN') sn WHERE ST_Contains(ST_Buffer(sn.geom, 30000), luc.geom) Query plan: Nested Loop (cost=0.00..13...

 
your solution takes 22min while the same query without ST_Buffer() takes 593msec. Still a way to huge difference.
 
@andrasz and please a plan for my query?..
 
When runing SELECT ST_Buffer(geom, 30000) FROM spatial_derived.germany_bld WHERE state = 'SN' it also only takes 76msec. So is it really 'causing the speed drop down? I will run EXPLAIN ANALYZE.
 
oh, yes please check with analyze for sure. if you have smth strange - dont ommit analyze
@andrasz please check plan for: with sn as ( SELECT geom FROM spatial_derived.germany_bld WHERE state = 'SN' ) SELECT luc.* FROM spatial_derived.lucas12 luc JOIN sn on sn.geom = luc.geom WHERE ST_Contains(ST_Buffer(sn.geom, 30000), luc.geom)
 
this is really fast, however has no results
 
10:51 AM
yeah, cos it joins on small set and after that no point in ST_Buffer :)
just out of curioucity: run set enable_seqscan to off before query
 
Here's the plan for your query:
Nested Loop (cost=2.20..13293.46 rows=8 width=236) (actual time=225.214..225.214 rows=0 loops=1)
Join Filter: ((sn.geom = luc.geom) AND st_contains(st_buffer(sn.geom, 30000::double precision), luc.geom))
Rows Removed by Join Filter: 24935
CTE sn
-> Seq Scan on germany_bld (cost=0.00..2.20 rows=1 width=18399) (actual time=0.017..0.025 rows=1 loops=1)
Filter: ((state)::text = 'SN'::text)
Rows Removed by Filter: 15
-> CTE Scan on sn (cost=0.00..0.02 rows=1 width=32) (actual time=0.021..0.030 rows=1 loops=1)
That's when seqscan is off:

Nested Loop (cost=20000000002.20..20000013293.46 rows=8 width=236) (actual time=225.227..225.227 rows=0 loops=1)
Join Filter: ((sn.geom = luc.geom) AND st_contains(st_buffer(sn.geom, 30000::double precision), luc.geom))
Rows Removed by Join Filter: 24935
CTE sn
-> Seq Scan on germany_bld (cost=10000000000.00..10000000002.20 rows=1 width=18399) (actual time=0.018..0.040 rows=1 loops=1)
Filter: ((state)::text = 'SN'::text)
Rows Removed by Filter: 15
-> CTE Scan on sn (cost=0.00..0.02 rows=1 width=32) (actual time=0.023..0.050 rows=1 loops=1)
 
hm
I have no experience in geospatial
probably missing smth :)
 
ok, mine is also low. ST_Buffer() seems to cause it. My initial guess was that the geometry columns created by ST_Buffer() lack an index. Maybe I can force ST_Buffer somehow to also create an index? Just a guess..
 
and the plan for ```with sn as (
SELECT ST_Buffer(sn.geom, 30000) geom
FROM spatial_derived.germany_bld
WHERE state = 'SN'
)
SELECT luc.*
FROM spatial_derived.lucas12 luc
JOIN sn on sn.geom = luc.geom
WHERE ST_Contains(sn.geom, luc.geom)```
please
again
 
"Nested Loop (cost=10000000004.90..10000000053.60 rows=1 width=236) (actual time=61.802..61.802 rows=0 loops=1)"
" CTE sn"
" -> Seq Scan on germany_bld (cost=10000000000.00..10000000002.45 rows=1 width=18399) (actual time=57.347..57.899 rows=1 loops=1)"
" Filter: ((state)::text = 'SN'::text)"
" Rows Removed by Filter: 15"
" -> CTE Scan on sn (cost=0.00..0.02 rows=1 width=32) (actual time=57.357..57.910 rows=1 loops=1)"
" -> Bitmap Heap Scan on lucas12 luc (cost=2.45..51.12 rows=1 width=236) (actual time=3.854..3.854 rows=0 loops=1)"
how can I create a code block in the chat?
 
11:08 AM
tripple `
not sure it works in chat though
(actual time=61.802..61.802 - means it runs minute, not 5?
rows 0 though. hm
really unexpected
sorry :)
no idea what's there
 
11:21 AM
ok, I have it now!!
The help ( ) of ST_Buffer(http://www.postgis.org/docs/ST_Buffer.html) states:
"People often make the mistake of using this function to try to do radius searches. Creating a buffer to to a radius search is slow and pointless. Use ST_DWithin instead."

the help (http://www.postgis.org/docs/ST_DWithin.html) of ST_DWithin() again says that:

"This function call will automatically include a bounding box comparison that will make use of any indexes that are available on the geometries."
it works now
thanks for your efforts! next time I start with the function's help page directly ;)
 
:)
please put it as correct answers
to help lazy people not to step on same rake
good luck
 
k, will do!
Buffer is so common in other GIS softwares that I didn't even consider looking up another function let alone the help page.
 

last day (14 days later) »