是否有任何其他解决方案可供使用而不是 Like 以匹配开头?
这是我要匹配的查询以使用like开头。
explain analyze select * from completedcalls where call_id like 'GWYA4NvSLzoIcvA7RAtmn_a9IelwOQeH@209.44.103.3%';
QUERY PLAN
------------------------------------------------------------------------------------------------------------------
Seq Scan on completedcalls (cost=0.00..52659.96 rows=112 width=228) (actual time=1.541..249.857 rows=2 loops=1)
Filter: ((call_id)::text ~~ 'GWYA4NvSLzoIcvA7RAtmn_a9IelwOQeH@209.44.103.3%'::text)
Total runtime: 249.893 ms
(3 rows)
这是非常广泛的,因为它进行序列扫描而不是索引扫描。由于喜欢它的性质,它不能在提供的列上使用索引。列的索引很简单:
"i_call_id" btree (call_id)
是否有任何特殊类别的索引可以帮助提高速度,或者在不使用类似的情况下实现相同的任何其他方式?
使用的表脚本是:
Table "public.completedcalls"
Column | Type | Modifiers
---------------+--------------------------+--------------
call_id | character varying(128) |
sip_code | integer |
duration | integer |
setup_time | timestamp with time zone | not null
authname | character varying(30) |
src_sig_ip | character varying(20) |
dst_sig_ip | character varying(20) |
cld | character varying(22) |
cli | character varying(22) |
Indexes:
"i_call_id" btree (call_id)
"i_dst_sig_ip" btree (dst_sig_ip)