0
我有一個表:PostgreSQL的簡單的選擇是緩慢
CREATE TABLE my_table
(
id integer NOT NULL DEFAULT nextval('seq_my_table_id'::regclass),
fk_id1 integer NOT NULL,
fk_id2 smallint NOT NULL,
name character varying(255) NOT NULL,
description text,
currency_name character varying(3) NOT NULL,
created timestamp with time zone NOT NULL DEFAULT now(),
updated timestamp with time zone NOT NULL DEFAULT now(),
CONSTRAINT "PK_my_table_id" PRIMARY KEY (id),
CONSTRAINT "FK_my_table_fk_id1" FOREIGN KEY (fk_id1)
REFERENCES my_table2 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT "FK_my_table_fk_id2" FOREIGN KEY (fk_id2)
REFERENCES my_table3 (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED
)
WITH (
OIDS=FALSE,
autovacuum_enabled=true,
autovacuum_vacuum_threshold=50,
autovacuum_vacuum_scale_factor=0.2,
autovacuum_analyze_threshold=50,
autovacuum_analyze_scale_factor=0.1,
autovacuum_vacuum_cost_delay=20,
autovacuum_vacuum_cost_limit=200,
autovacuum_freeze_min_age=50000000,
autovacuum_freeze_max_age=200000000,
autovacuum_freeze_table_age=150000000
);
ALTER TABLE my_table
OWNER TO postgres;
CREATE INDEX my_table_fk_id1
ON my_table
USING btree
(fk_id1);
CREATE INDEX my_table_fk_id2
ON my_table
USING btree
(fk_id2);
表中的記錄計數
select count(id) from my_table; --24061
select count(id) from my_table2; --24061
select count(id) from my_table3; --123
執行時間
select * from my_table -- ~17sec
vacuum/analyze
- 不影響
description
- 長度〜4000字符在每行
postgres.conf
- 非標準設置
版本:9.1
選擇除描述各個領域減少執行時間到〜1.5秒
如何icrease選擇速度描述?
UPD
--explain analyze select * from my_table
"Seq Scan on my_table (cost=0.00..3425.79 rows=24079 width=1015) (actual time=0.019..17.238 rows=24079 loops=1)"
"Total runtime: 18.649 ms"
你正在使用哪個應用程序來顯示'select *'語句的結果?報告哪個運行時報告瞭解釋select * from my_table' –
'select *'只是例子,但是'select fk_id1,fk_id2,name,currency_name,description' - 使用(相同的17秒),也見問題更新 – cetver
運行時* *在服務器上**僅有18 **毫秒**(18.649ms)。這意味着如果您的前端需要17 *秒*,則通過網絡(或在客戶端應用程序內)發送行的時間會丟失 –