我在Postgres数据库运行一个相对简单的查询:简单查询到很长一段时间
INSERT INTO tt (pid, trip_pid) SELECT stop_time.pid, trip.pid
FROM stop_time, trip
WHERE stop_time.trip_id = trip.trip_id AND
17 = trip.gtfsfeed_id
AND 17 = stop_time.gtfsfeed_id
TT是一个临时表,stop_time的包含约200万行,行程只包含大约50,000。这个查询在我的aws rds实例上运行了一个多小时,我不知道为什么。这个查询有没有可悲的低效率?
编辑:这里是EXPLAIN(我创建了一个新的临时表相同的列运行解释)
QUERY PLAN
--------------------------------------------------------------------------------
Insert on ll (cost=2604.38..75394.65 rows=1649975 width=8)
-> Hash Join (cost=2604.38..75394.65 rows=1649975 width=8)
Hash Cond: ((stop_time.trip_id)::text = (trip.trip_id)::text)
-> Seq Scan on stop_time (cost=0.00..49406.68 rows=1835694 width=34)
Filter: (gtfsfeed_id = 17)
-> Hash (cost=2123.74..2123.74 rows=38451 width=34)
-> Seq Scan on trip (cost=0.00..2123.74 rows=38451 width=34)
Filter: (gtfsfeed_id = 17)
你能向我们展示查询的'EXPLAIN PLAN'吗? –
我已经添加了它 – Derongan
尝试使用forall语句批量插入。 – Avi