<div dir="ltr"><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Hello,</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Lets say I have two tables</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">CREATE EXTENSION postgis;</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">DROP TABLE A;</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">DROP TABLE B;</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">CREATE TABLE A(shape Geometry, id INT);</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">CREATE TABLE B(shape Geometry, id INT, kind INT);</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">CREATE INDEX ON A USING GIST (shape);</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">I would like to select for each object A, the an object of B of a particular kind, such</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">that the relative overlap between A and B is at least 0.5:</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">SELECT A.id, B.id FROM A, B</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">WHERE B.id = (SELECT B.id FROM B WHERE</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><span style="white-space:pre-wrap">           </span> ST_Intersects(A.shape, B.shape)</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><span style="white-space:pre-wrap">          </span> AND ST_Length(ST_Intersection(A.shape, B.shape)) / ST_Length(A.shape) >= 0.5</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><span style="white-space:pre-wrap">          </span> AND B.kind != 1 LIMIT 1)</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">The number of rows in table A orders of magnitude larger than that of table B.</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">What are the indexes that should give optimal performance and what should be the order of arguments</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">in the ST_Intersection? From the following page it seems that the order or arguments can have dramatic effects:</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><a href="http://support.esri.com/EN/knowledgebase/techarticles/detail/35498" target="_blank">http://support.esri.com/EN/knowledgebase/techarticles/detail/35498</a></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Thanks,</div><div style="font-size:13.1999998092651px;line-height:19.7999992370605px">Igor</div></div>