好了,我有以下表(从pgAdmin的信息):在PostgreSQL中比较小的表非常缓慢更新
CREATE TABLE comments_lemms
(
comment_id integer,
freq integer,
lemm_id integer,
bm25 real
)
WITH (
OIDS=FALSE
);
ALTER TABLE comments_lemms OWNER TO postgres;
-- Index: comments_lemms_comment_id_idx
-- DROP INDEX comments_lemms_comment_id_idx;
CREATE INDEX comments_lemms_comment_id_idx
ON comments_lemms
USING btree
(comment_id);
-- Index: comments_lemms_lemm_id_idx
-- DROP INDEX comments_lemms_lemm_id_idx;
CREATE INDEX comments_lemms_lemm_id_idx
ON comments_lemms
USING btree
(lemm_id);
还有一表:
CREATE TABLE comments
(
id serial NOT NULL,
nid integer,
userid integer,
timest timestamp without time zone,
lemm_length integer,
CONSTRAINT comments_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE comments OWNER TO postgres;
-- Index: comments_id_idx
-- DROP INDEX comments_id_idx;
CREATE INDEX comments_id_idx
ON comments
USING btree
(id);
-- Index: comments_nid_idx
-- DROP INDEX comments_nid_idx;
CREATE INDEX comments_nid_idx
ON comments
USING btree
(nid);
在comments_lemms有800万条目,评论 - 270万。 林执行下面的SQL查询:
update comments_lemms set bm25=(select lemm_length from comments where id=comment_id limit 1)
而且它需要超过20分钟的运行,而我停下来,因为pgAdmin的看起来像它即将崩溃。 有没有什么办法可以修改这个查询或索引或我的数据库中的任何东西来加速一些事情?我必须在将来运行一些类似的查询,并且等待超过30分钟是相当痛苦的。
当你说“看起来像它即将崩溃?”是什么意思?你有没有理由不加入? Postgres不允许更新连接? – MJB 2011-05-26 11:07:59
Windows开始尖叫,pgAdmin可能停止工作。因为我不知道更新连接,所以在sql中我是一个新手,你会看到:)我使用更新连接重写了我的查询,再次启动它,现在正在等待结果显示。 – Anton 2011-05-26 11:40:18
与问题无关,但我相信'comments_id_idx'没有必要。 Postgres在没有被告知的情况下为PK提供了一个独特的索引。 – 2011-05-29 00:24:20