<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">ST_DWithin is implemented like this,<div class=""><br class=""></div><div class=""></div><div class=""><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);"><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><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);"><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><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);"><font color="#24292e" face="Courier New" class=""><span style="font-size: 14px;" class="">LANGUAGE 'sql' IMMUTABLE _PARALLEL;</span></font></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></body></html>