<div dir="ltr">Hi Folks,<br><br>I've got a slow running query. When I break it down to just the spatial constraint on one table, I find that the query takes 8s. I need my broader query to take < 1s so have a long way to go on just the spatial part. Hopefully you guys will have some ideas for me...<br>
<br>Here's what I've got:<br><br>Query:<br>SELECT u.username,u.locbbox, y(u.locpoint) AS latitude, x(u.locpoint) AS longitude<br>FROM users u<br>WHERE u.locbbox && SetSrid( 'BOX(-73.795166015625 9.42738628387451,-69.49951171875 11.813588142395)'::box2d, 4326 ) <br>
<br>Explain Analyze:<br>"Bitmap Heap Scan on users u (cost=741.34..43666.77 rows=15789 width=486) (actual time=29.730..7321.358 rows=10687 loops=1)"<br>" Filter: (locbbox && '0103000020E6100000010000000500000000000000E47252C000000060D2DA224000000000E47252C0000000A08EA0274000000000F85F51C0000000A08EA0274000000000F85F51C000000060D2DA224000000000E47252C000000060D2DA2240'::geometry)"<br>
" -> Bitmap Index Scan on users_locbbox (cost=0.00..737.39 rows=15789 width=0) (actual time=26.981..26.981 rows=10703 loops=1)"<br>" Index Cond: (locbbox && '0103000020E6100000010000000500000000000000E47252C000000060D2DA224000000000E47252C0000000A08EA0274000000000F85F51C0000000A08EA0274000000000F85F51C000000060D2DA224000000000E47252C000000060D2DA2240'::geometry)"<br>
"Total runtime: 7328.359 ms"<br><br><br>Index:<br>CREATE INDEX users_locbbox<br> ON users<br> USING gist<br> (locbbox);<br><br>Some Stats (let me know what else would be helpful):<br>Rows in users table: 1.85mm<br>
Table Size: ~4GB<br>users_locbbox index size: 190MB<br><br>Tuning done:<br>shared_buffers = 100MB<br>work_mem = 100MB<br>max_fsm_pages = 153600<br>random_page_cost = 3.0<br>cpu_tuple_cost = 0.1<br>effective_cache_size = 8GB<br>
default_statistics_target = 100<br><br>Tables in the query are vacuum/analyzed daily.<br><br><br></div>