0
我有PostgreSQL的9.1表:正確的索引是簡單的表
_id | integer | not null default nextval('"01f9073e-e6b8-46bf-882f-9a4cd0a69a66__id_seq"'::regclass)
_full_text | tsvector |
tlRecordID | text |
tlPDM | text |
tlPayDateTime | text |
tlExpDateTime | text |
Indexes:
"01f9073e-e6b8-46bf-882f-9a4cd0a69a66_pkey" PRIMARY KEY, btree (_id)
"01f9073e-e6b8-46bf-882f-9a4cd0a69a66_tlRecordID_idx" UNIQUE, btree ("tlRecordID")
"01f9073e-e6b8-46bf-882f-9a4cd0a_tlPayDateTime_tlExpDateTime_idx" btree ("tlPayDateTime", "tlExpDateTime")
有〜35 MIO。行。
調用簡單:
SELECT MAX("tlRecordID"::integer) AS max_id FROM "01f9073e-e6b8-46bf-882f-9a4cd0a69a66";
確實需要很長的時間。此外,更高級的查詢,如:
FROM "01f9073e-e6b8-46bf-882f-9a4cd0a69a66"
WHERE "tlPayDateTime" != 'None' AND "tlExpDateTime" != 'None' AND
NOW() BETWEEN "tlPayDateTime"::timestamp AND "tlExpDateTime"::timestamp GROUP BY "tlPDM"
超時很多時候等
誰能幫助優化數據庫?是35 mio。排成一個問題還是?
這也許會幫助你:http://stackoverflow.com/questions/11940515/postgres-performance-issues – funk
...你拍攝自己的腳,使用基於字符的類型來存儲日期/時間值(即「無」應該可能爲空)。此外,請閱讀[本博客文章](http://sqlblog.com/blogs/aaron_bertrand/archive/2011/10/19/what-do-between-and-the-devil-have-in-common.aspx)有關使用帶有時間戳的BETWEEN的問題(這篇文章是專門針對SQL Server的,但邏輯適用於所有測量/非整數類型) –
是的,這是數據轉換問題。使用正確的數據類型是系統性能的先決條件。 –