I have a blacklist of people you canβt contact. When I want to see if a person is on this list, I do the following:
SELECT *
FROM bldb.dbo.blacklist l
WHERE l.matchcode
= dbo.fn_matchcode('12345','Sesame Street','1','Eddie','Bert')
The query is very fast, since there is an index in the matchcode column, and it fn_matchcodeis deterministic.
Think of a coincidence as a concise form of address and name, which helps me not to be mistyped in street names, etc. It consists of 22 characters: 13 for the address, 9 for the name. When I want to see if any of the 1 Sesame Street 12345 is blacklisted, I do the following:
SELECT *
FROM bldb.dbo.blacklist l
WHERE LEFT(l.matchcode,13)
= LEFT(dbo.fn_matchcode('12345','Sesame Street','1','Eddie','Bert'),13)
It lasts a very long time ...
On the contrary, it runs much faster:
SELECT *
FROM bldb.dbo.blacklist l
WHERE LEFT(l.matchcode,13)
= (SELECT LEFT(dbo.fn_matchcode('12345','Sesame Street','1','Eddie','Bert'),13))
, where ! ? UDF . LEFT(), ?
EDIT:
, , . , .
:
SELECT *
FROM bldb.dbo.blacklist
WHERE matchcode LIKE LEFT(dbo.fn_matchcode('12345','Sesame Street','1','Eddie','Bert'),13) + '%'
- . , fn_matchcode .
fn_matchcode :
SELECT *
FROM bldb.dbo.blacklist
WHERE matchcode LIKE '12345SSMSTRT1%'
! ?