我试图从这个查询中获得最佳性能,表有2700万条记录,但是当我使用下面的where子句时,结果将只包含160条记录。这是一个观点。原来的表是由emp_dept分区的,并行读取不适用于我的用例,因为这个视图的数据每天都会被刷新,以获得过去24个月的数据。
SELECT
a.fname,
a.lname,
a.mname,
a.emp_id,
a.emp_dob,
a.emp_dept
FROM emp.emp_profile a
WHERE a.emp_join_dt BETWEEN '2018-01-01 00:00:00' AND '2019-07-01 00:00:00'
AND a.emp_salary BETWEEN 0 AND 1000000
AND ((a.emp_id = '0000000024Z67089' AND a.emp_dept= 'INV' AND a.emp_div = '293')
OR (a.emp_id = '000000008UK23197' AND a.emp_dept = 'INV' AND a.emp_div = '293')
OR (a.emp_id = '000000006JF10942' AND a.emp_dept = 'INV' AND a.emp_div = '293')
OR (a.emp_id = '5B103B51' AND a.emp_dept = 'IPS' AND a.emp_div = '640')
OR (a.emp_id = '0000000016H79794' AND a.emp_dept = 'INV' AND a.emp_div = '293'));
我试过用“in”:
SELECT
a.fname,a.lname,a.mname,a.emp_id,a.emp_dob,a.emp_dept
FROM emp.emp_profile a
WHERE (a.emp_join_dt BETWEEN '2018-01-01 00:00:00' AND '2019-07-01 00:00:00')
AND (a.emp_salary BETWEEN 0 AND 1000000) AND a.emp_id in ('0000000024Z67089', '000000008UK23197', '000000006JF10942', '0000000016H79794', '5B103B51')
AND a.emp_dept in ('INV','IPS')
AND a.emp_div in ('293', '640');
* This gives me the same count and better query time, but it is still over 1.5 minute.*
我想,所有的结合都需要更多的时间,一个我已经厌倦了的没有给我正确的结果。
如果可能的话,尽量把查询时间控制在1分钟以内。
暂无答案!
目前还没有任何答案,快来回答吧!