我根据地址和邮政编码字段中的数字找到了具有匹配地址的供应商作为我们的员工,但它确实很慢。查询将删除任何文本,并将employee表中的数字连接到供应商表。
有什么方法可以改善查询效果吗?
SELECT
T1.EMPLID, T1.NAME, T1.ADDRESS1, T1.ADDRESS2, T1.ADDRESS3, T1.ADDRESS4, T1.CITY,
T2.VENDOR_ID, T3.NAME1, T2.ADDRESS1, T2.ADDRESS2, T2.ADDRESS3, T2.ADDRESS4, T2.CITY
FROM PS_PERSONAL_DATA T1
JOIN PS_VENDOR_ADDR T2
ON
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5) =
TRANSLATE(T2.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T2.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5)
JOIN PS_VENDOR T3
ON T2.VENDOR_ID = T3.VENDOR_ID
WHERE T1.EMPLID <> T2.VENDOR_ID
AND
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5) NOT LIKE ' '
AND T2.VENDOR_ID IN
(
SELECT VENDOR_ID
FROM PS_VOUCHER
WHERE PROCESS_INSTANCE <> 0
AND POST_STATUS_AP LIKE 'P'
AND VENDOR_ID NOT IN
(
'0000003730',
'0000003318',
'0000003555',
'0000002422',
'0000003458',
'0000001089',
'0000001450',
'0000003809',
'0000003255',
'0000001903'
)
HAVING SUM(GROSS_AMT) > 5000 AND COUNT(VENDOR_ID) > 2
GROUP BY VENDOR_ID
)
;
答案 0 :(得分:0)
我会考虑以下方法: 通过添加两个计算列来对表进行规范化,并使用格式化结果 - 在这些列上添加非主要索引
然后,您可以加入那些运行速度更快的列。
答案 1 :(得分:0)
想出来:
现在可以在不到8秒的时间内执行。
SELECT
T1.EMPLID, T1.NAME, T1.ADDRESS1 AS EE_ADDR, T2.ADDRESS1 AS VEN_ADDR, T1.ADDRESS2, T1.ADDRESS3, T1.CITY, T1.POSTAL,
T2.VENDOR_ID, T2.ADDRESS1, T2.ADDRESS2, T2.ADDRESS3, T2.CITY, T2.POSTAL
FROM PS_PERSONAL_DATA T1
JOIN PS_VENDOR_ADDR T2
ON
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS3, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS4, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T1.POSTAL,0,5) =
TRANSLATE(T2.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T2.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T2.ADDRESS3, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T2.ADDRESS4, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T2.POSTAL,0,5)
WHERE
TRANSLATE(T1.ADDRESS1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS2, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS3, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
TRANSLATE(T1.ADDRESS4, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-#./ ,',' ') ||
SUBSTR(T1.POSTAL,0,5) NOT LIKE ' '
AND VENDOR_ID NOT IN
(
'0000003730',
'0000003318',
'0000003555',
'0000002422',
'0000003458',
'0000001089',
'0000001450',
'0000003809',
'0000003255',
'0000001903'
)
AND VENDOR_ID NOT LIKE 'SF%'
AND VENDOR_ID NOT LIKE 'P%'
AND VENDOR_ID NOT LIKE '_______'
AND T2.VENDOR_ID IN
(
SELECT VENDOR_ID
FROM PS_VOUCHER
WHERE PROCESS_INSTANCE 0
AND POST_STATUS_AP LIKE 'P'
HAVING SUM(GROSS_AMT) > 5000 AND COUNT(VENDOR_ID) > 2
GROUP BY VENDOR_ID
)
;