<html><head></head><body class=""><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 class=""><br class=""></div><div class=""></div><div class=""><font color="#24292e" face="Courier New" class=""><span style="font-size: 14px;" class="">CREATE OR REPLACE FUNCTION ST_DWithin(geom1 geometry, geom2 geometry, float8 RETURNS boolean</span></font><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="orphans: 2; widows: 2; box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; background-color: rgb(255, 255, 255);"></table><font color="#24292e" face="Courier New" class=""><span style="font-size: 14px;" class="">AS 'SELECT $1 OPERATOR(@extschema@.&&) @extschema@.ST_Expand($2,$3) AND <b class="">$2 OPERATOR(@extschema@.&&) @extschema@.ST_Expand($1,$3)</b> AND @extschema@._ST_DWithin($1, $2, $3)'</span></font><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="orphans: 2; widows: 2; box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; background-color: rgb(255, 255, 255);"></table><font color="#24292e" face="Courier New" class=""><span style="font-size: 14px;" class="">LANGUAGE 'sql' IMMUTABLE _PARALLEL;</span></font><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="orphans: 2; widows: 2; box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; background-color: rgb(255, 255, 255);"></table><div class=""><br class=""></div></div><div class="">What’s the purpose of the second bounding box check? </div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">Zhihong</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><pre>_______________________________________________
postgis-devel mailing list
<a href="mailto:postgis-devel@lists.osgeo.org">postgis-devel@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></pre></blockquote></body></html>