简体   繁体   English

PosgtreSQL使用st_transform,st_makepoint和st_contains优化查询

[英]PosgtreSQL Optimize Query with st_transform, st_makepoint, and st_contains

I have the following query: 我有以下查询:

UPDATE  DestinTable
SET  destin = geomVal 
FROM GeomTable
WHERE st_contains(st_transform(geom, 4326), st_setsrid(
      st_makepoint(d_lon::double precision, d_lat::double precision), 4326));

This query works, but it is very slow. 该查询有效,但是非常慢。 I have to run an update on a very large table, and it is taking a 8+ hours to complete (I run this on 5 different columns). 我必须在一个非常大的表上运行更新,并且需要8个多小时才能完成更新(我在5个不同的列上运行该更新)。 I wanted to know if there was a way to optimize this query to make it run faster . 我想知道是否有一种方法可以优化此查询以使其运行更快 I am unaware of the behind the scenes work associated with an st_contains() method, so there may be some obvious solutions that I am missing. 我不知道与st_contains()方法相关的幕后工作,因此可能缺少一些明显的解决方案。

The easiest way is to create an index on ST_TRANSFORM 最简单的方法是在ST_TRANSFORM上创建索引

CREATE INDEX idx_geom_4326_geomtable
  ON GeomTable
  USING gist
  (ST_Transform(geom, 26986))
  WHERE geom IS NOT NULL;

If you have all the fields in one SRID in the table it will be even easier to create a normal GIST index on that table and transform the point you're supplying to the local SRID 如果您在表中的一个SRID中拥有所有字段,则在该表上创建普通GIST索引并将要提供的点转换为本地SRID会更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM