我有一个 Postgres 物化视图:
Column | Type | Modifiers
---------------------+-------------------+-----------
document_id | character varying |
recorded_date | date |
parcels | jsonb |
Indexes:
"index_my_view_on_document_id" btree (document_id)
"index_my_view_on_recorded_date" btree (recorded_date)
"index_my_view_on_parcels" gin (parcels)
Run Code Online (Sandbox Code Playgroud)
我正在尝试执行一个分页查询,该查询在parcelsjsonb 数组字段上进行过滤,但是每当我添加 LIMIT 时,我的性能就会下降:
无限制:
EXPLAIN ANALYZE SELECT document_id FROM my_view WHERE (parcels @> '[3022890014]') ORDER BY recorded_date DESC;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=24178.50..24194.79 rows=6518 width=21) (actual time=11.272..11.275 rows=22 loops=1)
Sort Key: recorded_date DESC
Sort Method: quicksort Memory: 26kB
-> Bitmap Heap Scan on my_view (cost=78.51..23765.58 …Run Code Online (Sandbox Code Playgroud)