0

我这样做是为了根据地址和邮政编码字段中的数字查找与我们的员工具有匹配地址的供应商,但这确实很慢。该查询删除任何文本并将员工表中的数字连接到供应商表。

有什么方法可以提高查询性能?

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
)
;
4

2 回答 2

0

弄清楚了:

  • 我的邮政编码使用了错误的表格(T2 而不是 T1)
  • 我将 Vendor_ID 条件移到子查询之外

它现在在不到 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
)
;
于 2014-07-10T17:05:03.540 回答
0

我会考虑以下方法: - 通过添加两个计算列以及格式化结果来对表进行反规范化 - 在这些列上添加非主索引

然后,您可以连接那些运行速度更快的列。

于 2014-07-10T16:42:28.387 回答