<div dir="ltr">Hello,<div><br></div><div>Would you please post the query plan please?<br>It feels like "all geometry columns are indexed" may switch plan to Bitmap And, and that indeed may be slower. <br>Is statistics up-to-date?</div></div><br><div class="gmail_quote"><div dir="ltr">сб, 6 янв. 2018 г. в 19:10, Zhihong Zhang <<a href="mailto:zhihong@gmail.com">zhihong@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Thanks for the explanation. I understand the reason for the 2nd check now.<div><br></div><div>All our geometry columns are indexed so the 2nd check is redundant, which causes the performance degradation.</div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><br></div><div>Zhihong</div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><br><blockquote type="cite"><div>On Jan 6, 2018, at 11:00 AM, Nicklas Avén <<a href="mailto:nicklas.aven@jordogskog.no" target="_blank">nicklas.aven@jordogskog.no</a>> wrote:</div><br class="m_-2702818378071579770Apple-interchange-newline"><div><div><div>Hello</div><div><br></div><div>If you get a difference as large as 20% I guess you are not using spatial indexes.</div><div><br></div><div>The reaason for that implementation is that it gives the query planner the possibility to choose if it shall iterate table1 and use the index of table 2 to find overlaps, or if it shall iterate table 2 instead and use the index of table 1 to find overlap.</div><div><br></div><div>The index cannot be used on an expanded geometry (snce the bbox in the index is for the original geometry) so without this double check the planner wouldn't have the choice.</div><div><br></div><div>That would be very bad if only 1 of the tables have an index. It is also a bad thing if the table that gets the sequential scan is the one with millions of rows and the index is used on the table with just a few rows.</div><div><br></div><div>/Nicklas</div><div><br></div><div><br></div><div>On Sat, 2018-01-06 at 10:14 -0500, Zhihong Zhang wrote:</div><blockquote type="cite">ST_DWithin is implemented like this,<div><br></div><div></div><div><font color="#24292e" face="Courier New"><span style="font-size:14px">CREATE OR REPLACE FUNCTION ST_DWithin(geom1 geometry, geom2 geometry, float8 RETURNS boolean</span></font><table class="m_-2702818378071579770highlight m_-2702818378071579770js-file-line-container m_-2702818378071579770tab-size" style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;background-color:rgb(255,255,255)"></table><font color="#24292e" face="Courier New"><span style="font-size:14px">AS 'SELECT $1 OPERATOR(@extschema@.&&) @extschema@.ST_Expand($2,$3) AND <b>$2 OPERATOR(@extschema@.&&) @extschema@.ST_Expand($1,$3)</b> AND @extschema@._ST_DWithin($1, $2, $3)'</span></font><table class="m_-2702818378071579770highlight m_-2702818378071579770js-file-line-container m_-2702818378071579770tab-size" style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;background-color:rgb(255,255,255)"></table><font color="#24292e" face="Courier New"><span style="font-size:14px">LANGUAGE 'sql' IMMUTABLE _PARALLEL;</span></font><table class="m_-2702818378071579770highlight m_-2702818378071579770js-file-line-container m_-2702818378071579770tab-size" style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;background-color:rgb(255,255,255)"></table><div><br></div></div><div>What’s the purpose of the second bounding box check? </div><div><br></div><div>I did many tests. It’s always faster (about 20%) with one check. So we ended up using our own version of ST_DWithin.</div><div><br></div><div>Thanks!</div><div><br></div><div>Zhihong</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><pre>_______________________________________________
postgis-devel mailing list
<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></pre></blockquote></div>_______________________________________________<br>postgis-devel mailing list<br><a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br><a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></div></blockquote></div><br></div></div>_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></blockquote></div>