We are trying to upload data from Excel to Database. Before uploading, we would like to preview the data with the count of Match status(Eg: No match, Similar match, Exact match) while comparing with our database.
The below query is taking 3 minutes of time to fetch the information from the database for 100 rows. We will have a case where the user can upload more than 5K rows of data. Please let us know your suggestions to improve the performance of the below query.
select IF(
count(distinct ID) <= 0, (
select case when count(ID) > 0 then 'Similar Match' else 'No Match' end as MatchType from masterTable where (
soundex(BarCode) like soundex('12069B0') or soundex(ProductName) like soundex('FreezerZX')
) and (
levenshtein(BarCode,'12069B0') < 3 or (levenshtein(ProductName,'FreezerZX') < 3)
)
),
'Exact Match'
) as MatchType from masterTable where BarCode= '12069B0' and ProductName= 'FreezerZX';