Hello again...
This expression is working, but is very slow. I suspect it's because the SQL is peforming the DamerauLevenshtein function twice for each record, and the function is pretty intense to begin with.
I'm wondering if incorporating the MIN() from the SQL right into the DamerauLevenshtein function might speed things up, possibly using VBA syntax instead of SQL. As in, identify the best match right in the function rather than retrieving a list of possible matches and then running the same function again to determine the MIN and pick the right one using a JOIN. It would mean passing the maximum threshhold for error (in this case, "<3") to the function instead of declaring it in the SQL, then using that as a basis to create an array of results and pick the best one, then send it back to the SQL.
I hope that makes sense :/
Anyway here's the SQL: - SELECT t1.*
-
FROM (
-
-
SELECT TCSDBOWNER_EMP.ID AS EMP_ID, TCSDBOWNER_EMP.LAST_NAME AS EMP_LNAME, TCSDBOWNER_EMP.FIRST_NAME AS EMP_FNAME, q_insCrosstab.[SK Insurance], TCSDBOWNER_EMP.EMAIL_ADR AS EMP_EMAIL, TCSDBOWNER_EMP.ACTIVE_FLAG AS ACTIVE, SK_Ins.[Full_Name], DamerauLevenshtein(q_insCrosstab.[NAME],SK_Ins.[Full_Name]) AS DamLev FROM SK_Ins, TCSDBOWNER_EMP,q_insCrosstab WHERE DamerauLevenshtein(q_insCrosstab.[NAME],SK_Ins.[Full_Name]) <3 AND TCSDBOWNER_EMP.ACTIVE_FLAG="T" ORDER BY TCSDBOWNER_EMP.LAST_NAME, TCSDBOWNER_EMP.FIRST_NAME
-
-
) AS t1
-
-
RIGHT JOIN (
-
-
SELECT EMP_ID, MIN(DamLev) AS MinDamLev FROM (
-
-
SELECT TCSDBOWNER_EMP.ID AS EMP_ID, TCSDBOWNER_EMP.LAST_NAME AS EMP_LNAME, TCSDBOWNER_EMP.FIRST_NAME AS EMP_FNAME, q_insCrosstab.[SK Insurance], TCSDBOWNER_EMP.EMAIL_ADR AS EMP_EMAIL, TCSDBOWNER_EMP.ACTIVE_FLAG AS ACTIVE, SK_Ins.[Full_Name], DamerauLevenshtein(q_insCrosstab.[NAME],SK_Ins.[Full_Name]) AS DamLev FROM SK_Ins, TCSDBOWNER_EMP,q_insCrosstab WHERE DamerauLevenshtein(q_insCrosstab.[NAME],SK_Ins.[Full_Name]) <3 AND TCSDBOWNER_EMP.ACTIVE_FLAG="T" ORDER BY TCSDBOWNER_EMP.LAST_NAME, TCSDBOWNER_EMP.FIRST_NAME
-
-
) AS x
-
-
GROUP BY EMP_ID
-
-
) AS t2 ON (t1.EMP_ID = t2.EMP_ID) AND (t1.DamLev = t2.MinDamLev);
and the VBA: - Function DamerauLevenshtein(str1 As String, str2 As String, Optional intSize As Integer = 256)
-
-
Dim intTotalLen As Integer, arrDistance, intLen1 As Integer, intLen2 As Integer, i As Integer, j As Integer, arrStr1, arrStr2, arrDA, intMini As Integer
-
Dim intDB As Integer, intI1 As Integer, intJ1 As Integer, intD As Integer
-
-
'adding basAlphNum() to strip spaces and non-alpha chars
-
str1 = basAlphNum(str1)
-
str2 = basAlphNum(str2)
-
'original code for DamerauLevenshtein() follows
-
-
str1 = UCase(str1)
-
str2 = UCase(str2)
-
intLen1 = Len(str1)
-
intLen2 = Len(str2)
-
intTotalLen = intLen1 + intLen2
-
ReDim arrStr1(intLen1)
-
ReDim arrStr2(intLen2)
-
ReDim arrDA(intSize)
-
ReDim arrDistance(intLen1 + 2, intLen2 + 2)
-
arrDistance(0, 0) = intTotalLen
-
-
For i = 0 To intSize - 1
-
arrDA(i) = 0
-
Next
-
-
For i = 0 To intLen1
-
arrDistance(i + 1, 1) = i
-
arrDistance(i + 1, 0) = intTotalLen
-
Next
-
-
For i = 1 To intLen1
-
arrStr1(i - 1) = Asc(Mid(str1, i, 1))
-
Next
-
-
For j = 0 To intLen2
-
arrDistance(1, j + 1) = j
-
arrDistance(0, j + 1) = intTotalLen
-
Next
-
-
For j = 1 To intLen2
-
arrStr2(j - 1) = Asc(Mid(str2, j, 1))
-
Next
-
-
For i = 1 To intLen1
-
intDB = 0
-
-
For j = 1 To intLen2
-
intI1 = arrDA(arrStr2(j - 1))
-
intJ1 = intDB
-
-
If arrStr1(i - 1) = arrStr2(j - 1) Then
-
intD = 0
-
Else
-
intD = 1
-
End If
-
-
If intD = 0 Then intDB = j
-
-
intMini = arrDistance(i, j) + intD
-
If intMini > arrDistance(i + 1, j) + 1 Then intMini = arrDistance(i + 1, j) + 1
-
If intMini > arrDistance(i, j + 1) + 1 Then intMini = arrDistance(i, j + 1) + 1
-
If intMini > arrDistance(intI1, intJ1) + i - intI1 + j - intJ1 - 1 Then intMini = arrDistance(intI1, intJ1) + i - intI1 + j - intJ1 - 1
-
-
arrDistance(i + 1, j + 1) = intMini
-
Next
-
-
arrDA(arrStr1(i - 1)) = i
-
Next
-
-
DamerauLevenshtein = arrDistance(intLen1 + 1, intLen2 + 1)
-
End Function
Edit: as always, I appreciate any feedback you have on how to improve my question or communicate more effectively. And thank you for any suggestions you might have on how to speed this up :)
It may be quicker if you write out the results of the query to a temp table and then do the min query on that.
2 1061
It may be quicker if you write out the results of the query to a temp table and then do the min query on that.
That's a great idea, thank you!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bennett Haselton |
last post by:
I have a MySQL query running inside a CGI script on my site that, at random
intervals, seems to take 10-20 seconds to complete instead of less than 1
second. I spent so much time trying to track...
|
by: David |
last post by:
Consider this SQL Query:
-----------------------------------------------------------------
SELECT c.CASE_NBR, DATEDIFF(d, c.CREATE_DT, GETDATE()) AS Age,
c.AFFD_RCVD, c.PRV_CRD_ISS, x.RegE,...
|
by: John D |
last post by:
We have a dynamic SP that dependant on a user name will run a selected
tailored to them.
One of the criteria is the number of rows retrieved, which we include using
'top @varNoOfRows' in the...
|
by: mfyahya |
last post by:
Hi,
I'm new to databases :) I need help speeding up select queries on my
data which are currently taking 4-5 seconds. I set up a single large
table of coordinates data with an index on the fields...
|
by: Robert Wille |
last post by:
I have a number of very common queries that the optimizer plans a very inefficient plan for. I am using postgres 7.2.3. I vacuum hourly. I'm wonderingwhat I can do to make the queries faster.
Here...
|
by: Wayne |
last post by:
I am running a complex query using about 25 criteria that are entered
on a query form. If any individual criteria isn't required its field is
left as "*" on the form. When I run the query the...
|
by: strict9 |
last post by:
Hello all,
I'm writing several queries which need to do various string formating,
including changing a phone number from (123) 456-7890. After some
problem with data mismatches, I finally got it...
|
by: Jean |
last post by:
Hello,
I have the following query that I set up as a test, and it runs fine:
SELECT STATUSHISTORIE.*
FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON STATUSHISTORIE.PROBLEM_ID =...
|
by: Dan Sugalski |
last post by:
Is there any good way to speed up SQL that uses like and has placeholders?
Here's the scoop. I've got a system that uses a lot of pre-generated
SQL with placeholders in it. At runtime these SQL...
|
by: Bob Darlington |
last post by:
The following query opens slowly the first time it is opened (6-7 seconds),
but then is less than one second for the next random number of openings
before slowing (6-7 seconds) again.
SELECT...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |