4
需要提出一種有效地執行查詢的方法,WHERE
子句中的數組和整數列由時間戳列排序。使用PostgreSQL 9.2。有效查詢包含PostgreSQL中的數組列的條件的表
我們需要執行的查詢是:
SELECT id
from table
where integer = <int_value>
and <text_value> = any (array_col)
order by timestamp
limit 1;
int_value
是一個整數值,並text_value
是1 - 3字母文本值。
表結構是這樣的:
Column | Type | Modifiers ---------------+-----------------------------+------------------------ id | text | not null timestamp | timestamp without time zone | array_col | text[] | integer | integer |
我應該如何設計指標/修改查詢,以使其儘可能高效?
非常感謝!如果需要更多信息,請告知我,我會盡快更新。
好的,謝謝。那麼順序呢?我如何解決這個問題? – 2013-03-19 17:00:40
哦,我錯過了。在這種情況下,'index(integer,timestamp)'應該比'(integer)'和'(timestamp)'上的兩個單獨索引快,但是我恐怕這比我的水平高一點,所以我不能保證你應該嘗試一下。 – 2013-03-19 17:21:21