Is there any other solution available to use instead of Like to match starts with?
here is my query to match starts with using 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)
which is very expansive because it does sequence scan instead of index scan. due to nature of like it can not use index on provided column. index of column is simple as:
"i_call_id" btree (call_id)
Is there any special class of index which can help like to improve speed, or any other way to achieve same without using like?
Used Table script is:
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)