Dear all,
We are seeking for a most effective way to perform longest match in Teradata. Following is our situation:
The source data is called "call_records" (2.8 million records).
The pattern table is called "dialed_digits" (15,000 records).
We are using the following SQL to perform longest match. We are not sure if we are using the most efficient method to handle this in Teradata.
Any way better than this?
Thanks!
--------------------------------------------------------------------------------------------------------------------------------
insert into ADM1.longest_match_dialed_digits
(
dialed_digits
,mapped_dialed_digits
,destination
,country_code
,brand_model_id
,cdr_set
)
select
dt.dialed_digits_a
,dt.dialed_digits_b
,dt.destination
,dt.country_code
,dt.brand_model_id
,dt.cdr_set
from
(
select
a.dialed_digits as dialed_digits_a
,b.dialed_digits as dialed_digits_b
,b.destination
,b.country_code
,b.brand_model_id
,RANK() OVER (PARTITION BY a.dialed_digits, a.cdr_set
ORDER BY b.dialed_digits DESC, b.brand_model_id asc ) rnk
,a.cdr_set
from
adm1.call_records a
,adm1.dialed_digits b
where a.dialed_digits like b.dialed_digits || '%'
) dt
where rnk = 1;
We are seeking for a most effective way to perform longest match in Teradata. Following is our situation:
The source data is called "call_records" (2.8 million records).
The pattern table is called "dialed_digits" (15,000 records).
We are using the following SQL to perform longest match. We are not sure if we are using the most efficient method to handle this in Teradata.
Any way better than this?
Thanks!
--------------------------------------------------------------------------------------------------------------------------------
insert into ADM1.longest_match_dialed_digits
(
dialed_digits
,mapped_dialed_digits
,destination
,country_code
,brand_model_id
,cdr_set
)
select
dt.dialed_digits_a
,dt.dialed_digits_b
,dt.destination
,dt.country_code
,dt.brand_model_id
,dt.cdr_set
from
(
select
a.dialed_digits as dialed_digits_a
,b.dialed_digits as dialed_digits_b
,b.destination
,b.country_code
,b.brand_model_id
,RANK() OVER (PARTITION BY a.dialed_digits, a.cdr_set
ORDER BY b.dialed_digits DESC, b.brand_model_id asc ) rnk
,a.cdr_set
from
adm1.call_records a
,adm1.dialed_digits b
where a.dialed_digits like b.dialed_digits || '%'
) dt
where rnk = 1;