<div dir="ltr">  Hi, everyone,<br>I have 2 issues and need to improve their speed.<br>There are 3 tables in total, they use the ST_ContainsProperly function and ST_Intersects.<br><br>1 table name gisdata containing 3 billion rows of data, fields gid and geom and others.<br>There is also 1 test_line table, gid and geom, with 1 row of data.<br>There is also 1 test_polygon table, gid and geom, with 1 row of data.<br>Created SPGIST (geom).<br><br>--ST_ContainsProperly Execution Time: 143759.746 ms<br>select count(*) from  gisdata_30 g join test_polygon po on ST_ContainsProperly(po.geom,g.geom)='t';<br> Aggregate  (cost=85375554.05..85375554.06 rows=1 width=8) (actual time=143758.524..143758.526 rows=1 loops=1)<br>   ->  Nested Loop  (cost=84983.55..85368054.05 rows=3000000 width=0) (actual time=940.048..143633.927 rows=1148761 loops=1)<br>         ->  Seq Scan on bs c  (cost=0.00..1.01 rows=1 width=32) (actual time=0.002..0.004 rows=1 loops=1)<br>         ->  Bitmap Heap Scan on gisdata_30 sl  (cost=84983.55..85365053.04 rows=300000 width=157) (actual time=940.042..143458.484 rows=<br>1148761 loops=1)<br>               Filter: st_containsproperly(c.geom, geom)<br>               Rows Removed by Filter: 564339<br>               Heap Blocks: exact=1107489<br>               ->  Bitmap Index Scan on gisdata_30_geom  (cost=0.00..84908.55 rows=3000000 width=0) (actual time=551.154..551.154 rows=17<br>13100 loops=1)<br>                     Index Cond: (geom @ c.geom)<br> Planning Time: 32.232 ms<br> Execution Time: 143759.746 ms<br> <br>--ST_Intersects  1445741.458 ms<br>select count(*) from  gisdata_30 g join test_line li on ST_Intersects(li.geom,g.geom)='t';<br> Aggregate  (cost=8720103.56..8720103.57 rows=1 width=8) (actual time=1445741.385..1445741.386 rows=1 loops=1)<br>   ->  Nested Loop  (cost=0.56..8712603.56 rows=3000000 width=0) (actual time=526.359..1445730.137 rows=76332 loops=1)<br>         ->  Seq Scan on bs_line li  (cost=0.00..1.01 rows=1 width=32) (actual time=0.354..0.357 rows=1 loops=1)<br>         ->  Index Scan using gisdata_30_geom on gisdata_30 sl  (cost=0.56..8709602.55 rows=300000 width=157) (actual time=526.000..14457<br>15.941 rows=76332 loops=1)<br>               Index Cond: (geom && li.geom)<br>               Filter: st_intersects(li.geom, geom)<br>               Rows Removed by Filter: 7907303<br> Planning Time: 0.783 ms<br> Execution Time: 1445741.458 ms<br> <br>Is there any way to make them faster?<br><br>Wangdapeng.<div class="gmail-yj6qo"></div><div class="gmail-adL"><br></div></div>