我在查询。
SELECT ttf.default_text
FROM test_template_field ttf, TEST t
WHERE ttf.schema_field_id = 2044
--HERE
AND ttf.test_template_id = t.test_template_id
AND t.workflow_node_id IN (
SELECT wn.workflow_node_id
FROM lims_sys.workflow_node wn, lims_sys.workflow_user wu
WHERE wn.workflow_id = wu.workflow_id
AND wn.workflow_node_type_id = 42
AND wu.u_external_category IN ('M'))
group by ttf.DEFAULT_TEXT
这很好用,在8秒内我得到了我的结果。 但是如果我添加另一个AND功能,那么在我得到结果之前需要28分钟。 关于这个,他的位置是“--HERE”
AND ttf.default_text NOT IN ('Preparation Microbiology', 'Other', 'Preparation')
我不知道为什么它很慢..有人可以帮忙吗?
答案 0 :(得分:0)
检查你是否有索引
test_template_field.schema_field_id, test_template_field.test_template_id, test.test_template_id, lims_sys.workflow_node.workflow_id, wu.u_external_category, wn.workflow_node_type_id
也可以尝试此查询
SELECT ttf.default_text
FROM test_template_field ttf
JOIN TEST t
on ttf.test_template_id = t.test_template_id
JOIN (SELECT wn.workflow_node_id
FROM lims_sys.workflow_node wn
JOIN lims_sys.workflow_user wu
ON wn.workflow_id = wu.workflow_id
AND wu.u_external_category = 'M'
WHERE wn.workflow_node_type_id = 42) wni
on t.workflow_node_id = wni.workflow_node_id
WHERE ttf.schema_field_id = 2044
AND ttf.default_text NOT IN ('Preparation Microbiology', 'Other', 'Preparation')
group by ttf.DEFAULT_TEXT
看起来NOT IN耗时太长了(ttf.schema_field_id = 2044行太多了)
尝试此查询
SELECT *
FROM (SELECT ttf.default_text
FROM test_template_field ttf
JOIN TEST t
on ttf.test_template_id = t.test_template_id
JOIN (SELECT wn.workflow_node_id
FROM lims_sys.workflow_node wn
JOIN lims_sys.workflow_user wu
ON wn.workflow_id = wu.workflow_id
AND wu.u_external_category = 'M'
WHERE wn.workflow_node_type_id = 42) wni
on t.workflow_node_id = wni.workflow_node_id
WHERE ttf.schema_field_id = 2044) ss
WHERE ss.default_text NOT IN
('Preparation Microbiology', 'Other', 'Preparation')
group by ss.DEFAULT_TEXT
答案 1 :(得分:0)
答案 2 :(得分:0)
您也可以尝试EXISTS:
SELECT ttf.default_text
FROM test_template_field ttf, TEST t
WHERE ttf.schema_field_id = 2044
AND ttf.test_template_id = t.test_template_id
AND EXISTS
(
SELECT 1
FROM lims_sys.workflow_node wn, lims_sys.workflow_user wu
WHERE wn.workflow_id = wu.workflow_id
AND wn.workflow_node_type_id = 42
AND wu.u_external_category = 'M'
AND t.workflow_node_id = wn.workflow_node_id)
GROUP BY ttf.default_text
;