Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql PosgtreSQL使用st_变换、st_生成点和st_包含优化查询_Postgresql_Postgis - Fatal编程技术网

Postgresql PosgtreSQL使用st_变换、st_生成点和st_包含优化查询

Postgresql PosgtreSQL使用st_变换、st_生成点和st_包含优化查询,postgresql,postgis,Postgresql,Postgis,我有以下疑问: 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)); 此查询可以工作,但速度非常慢。我必须在一个非常大的表上运行更新,需要8个多小时才能完成(我在5个不

我有以下疑问:

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));

此查询可以工作,但速度非常慢。我必须在一个非常大的表上运行更新,需要8个多小时才能完成(我在5个不同的列上运行)我想知道是否有办法优化此查询以使其运行更快。我不知道与st_contains()方法相关的幕后工作,因此可能有一些我遗漏的明显解决方案

最简单的方法是在ST_变换上创建索引

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

如果表中的一个SRID中有所有字段,则更容易在该表上创建一个普通的
GIST
索引,并将提供的点转换为本地SRID

DestinTable.geom的原始SRID是什么?为什么要转换它?请在查询中使用完全限定的列名。(添加表别名)从您的问题中不清楚列来自两个表中的哪一个。