我正在尝试对表answer_date
的列P
运行更新查询。我想在answer_date
P
create_date
的每一行填充H
P.ID1
列中H.ID1
与P.acceptance_date
匹配answer_date
的唯一日期UPDATE P
SET answer_date = subquery.date
FROM (SELECT DISTINCT H.create_date as date
FROM H, P
where H.postid=P.acceptance_id
) AS subquery
WHERE P.acceptance_id is not null;
不是空的。
查询需要很长时间才能运行,因此我检查 Table "public.P"
Column | Type | Modifiers | Storage | Stats target | Description
-----------------------+-----------------------------+-----------+----------+--------------+-------------
id | integer | not null | plain | |
acceptance_id | integer | | plain | |
answer_date | timestamp without time zone | | plain | |
Indexes:
"posts_pkey" PRIMARY KEY, btree (id)
"posts_accepted_answer_id_idx" btree (acceptance_id) WITH (fillfactor='100')
中的临时更改,但整个列都是空的,就像它已创建一样。
所有提到的列都存在Btree索引。
查询有问题吗?
Table "public.H"
Column | Type | Modifiers | Storage | Stats target | Description
-------------------+-----------------------------+-----------+----------+--------------+-------------
id | integer | not null | plain | |
postid | integer | | plain | |
create_date | timestamp without time zone | not null | plain | |
Indexes:
"H_pkey" PRIMARY KEY, btree (id)
"ph_creation_date_idx" btree (create_date) WITH (fillfactor='100')
表模式如下:
P
和
H
表mlockall
为7000万行,ulimit
有2.2亿行。
Postgres版本是9.6 硬件是具有8Gb RAM的Windows笔记本电脑。