如何优化DB2 Query Where Where子句?

时间:2018-03-22 19:18:46

标签: sql database performance db2

我在这里有一个查询,查找授权给项目的用户,并且它以人类可读的方式编写,但我希望优化DB2查询。是否可以利用一些嵌套选择或一些聪明的表连接来使这个查询表现更好?

SELECT * 
FROM PROJECT p, USER_EMAIL_ACCESS uea, USER_EMAIL e
WHERE (
    uea.PROJECT_ID = p.ID and
    uea.USER_EMAIL_ID = l.ID and
    uea.STATE_ID = 1 and 
    e.USER_ID = 100 and 
    e.STATE_ID = 1 and
    p.STATE_ID = 1
)

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT * 
FROM 
PROJECT p 
inner join USER_EMAIL_ACCESS uea on (uea.PROJECT_ID, uea.STATE_ID)  = (p.ID, p.STATE_ID) 
inner join USER_EMAIL e on e.STATE_ID = uea.STATE_ID and e.USER_ID = 100
WHERE p.STATE_ID = 1