我有一个 PostgreSQL 数据库表,text[]
上面定义了(数组)列。我正在使用这些列以这种方式搜索数据库中的特定记录:
select obj from business
where ((('street' = ANY (address_line_1)
and 'a_city' = ANY (city)
and 'a_state' = ANY (state))
or ('street' = ANY (address_line_1)
and '1234' = ANY (zip_code)))
and ('a_business_name' = ANY (business_name)
or 'a_website' = ANY (website_url)
or array['123'] && phone_numbers))
我遇到的问题是大约有 100 万条记录,查询变得非常慢。我的问题很简单,数组列有不同类型的索引吗?有人知道在这种情况下要创建的最佳索引类型吗?(假设有不同的类型)。
以防万一,这是explain analyze
响应:
"Seq Scan on business (cost=0.00..207254.51 rows=1 width=32) (actual time=18850.462..18850.462 rows=0 loops=1)"
" Filter: (('a'::text = ANY (address_line_1)) AND (('a'::text = ANY (business_name)) OR ('a'::text = ANY (website_url)) OR ('{123}'::text[] && phone_numbers)) AND ((('a'::text = ANY (city)) AND ('a'::text = ANY (state))) OR ('1234'::text = ANY (zip_code))))"
" Rows Removed by Filter: 900506"
"Total runtime: 18850.523 ms"
提前致谢!