UPDATE tbl
SET city=s.city_name
FROM shp AS s
WHERE
ST_CONTAINS(s.city_geom,geom);
위의 코드를 사용하면 GPS 지점에 정확한 도시를 추가 할 수 있습니다. 5 천만 행에서 약 45-50 분 실행됩니다. "city"테이블에는 약 4000 개의 도시가 확인되어야합니다.ST_Contains()로 천천히 업데이트하십시오.
나는 주어진 국가에서 19 개 카운티 (하나의 국가 만)가있는 다른 형태의 파일을 가지고 있습니다. 포인트를 카운티에 추가하는 데 약 1.5 시간이 걸립니다.
나는 52 개 EU 국가의 세 번째 셰이프 파일을 가지고 있습니다. 동일한 SQL 쿼리로 거의 25 시간 동안 실행됩니다.
CREATE INDEX idx_txt_geom ON txt USING GIST(geom);
Q :
모든 표와 같이 기하 구조에 의해 인덱스가 왜 그것이 몇 다각형을 확인해야 할 때 너무 느리다?
Update (cost=0.00..324.85 rows=1 width=286) (actual time=353.932..353.932 rows=0 loops=1)
Buffers: shared hit=73090 read=1
-> Nested Loop (cost=0.00..324.85 rows=1 width=286) (actual time=0.544..341.936 rows=471 loops=1)
Join Filter: _st_contains(s.geom, prob.geom)
Buffers: shared hit=69985
-> Seq Scan on world s (cost=0.00..83.44 rows=244 width=48) (actual time=0.009..0.319 rows=244 loops=1)
Buffers: shared hit=81
-> Index Scan using idx_prob_geom on prob (cost=0.00..0.73 rows=1 width=270) (actual time=0.003..0.024 rows=9 loops=244)
Index Cond: (s.geom && prob.geom)
Buffers: shared hit=533
Total runtime: 354.640 ms
인덱스를 사용하는지 보여 주려면 'EXPLAIN'을 추가하십시오. –
'explain (buffers, analyze)'please [tag : postgresql-performance] –
작은 데이터 샘플에서 Explain Analyze를 만들었습니다. – Boppa