インデックスを持つにもかかわらずデータを返すためにクエリを15秒掛けて実行し、id
をプライマリキーとします。タイムスタンプ列のクエリによる処理が非常に遅い
"Limit (cost=1766417.72..1766417.72 rows=1 width=12) (actual time=32479.440..32479.441 rows=1 loops=1)"
" -> Sort (cost=1766417.72..1797117.34 rows=12279848 width=12) (actual time=32479.437..32479.437 rows=1 loops=1)"
" Sort Key: insert_date"
" Sort Method: top-N heapsort Memory: 25kB"
" -> Seq Scan on my_table (cost=0.00..1705018.48 rows=12279848 width=12) (actual time=0.006..21338.401 rows=12108916 loops=1)"
"Total runtime: 32479.476 ms"
私のテーブルには、他のいくつかの列があり、次のようにザ・分析が説明
select id from my_table order by insert_date offset 0 limit 1
です。
shared_buffers = more than 1GB ## just for an example
temp_buffers = more than 1GB
work_mem = more than 1GB
maintenance_work_mem = more than 1GB
dynamic_shared_memory_type = posix
default_statistics_target = 10000
autovacuum = on
random_page_cost = 2.0
cpu_index_tuple_cost = 0.0005
私はPostgresの9.3を使用しています。しかし、insert_date
用タイプは
insert_date timestamp without time zone NOT NULL DEFAULT now(),
は私がpostgresql.conf
ファイルから
CREATE INDEX my_table_insert_date_indx
ON my_table
USING btree
(insert_date)
TABLESPACE somexyz_idx_ts;
いくつかの値をある特定の日付の列に索引を持っていますたった今。
select insert_date, count(*) from my_table group by insert_date
をし、その結果から、上位のいくつかは次のとおりです:
UPDATE ::
私はしばらく前に、以下のクエリを実行した
"2015-04-02 00:00:00";3718104
"2015-04-03 00:00:00";6410253
"2015-04-04 00:00:00";538247
"2015-04-05 00:00:00";1228877
"2015-04-06 00:00:00";131248
私は約12持っていますそのテーブルの100万レコード。上記の数は、その合計にほぼ近いです。
わかりませんが、重複した値が重複している列にインデックスが作成されているという問題がありますか?それが真実ならば、私たちは周りに何か方法がありますか?
たぶん依頼するより良い場所:[dba.stackexchange.com](http://dba.stackexchange.com) –
あり同様の質問がSOに最近だった、と私は結論がいることだったかもしれないと思います並べ替えを避けるために、インデックス付きの列で並べ替える方が優れていました。その質問を探すのが好きかもしれません。 –
'set enable_seqscan = off;'で同じクエリをテストし、explain analyzeの出力を表示してください。あなたのインデックスとテーブルはどれくらいの大きさですか? psqlの '\ di + my_table_insert_date_indx'、' \ dt + my_table'コマンドは、サイズが – alexius