0
我有兩張表PRODUCT和ACCOUNT。由於加入導致的性能影響
產品表列
product_id (PK)
subscription_id
ACCOUNT表列
account_nbr
subscription_id
(account_nbr and subscription_id are primary key columns in account table)
... Other columns
我必須找到一個product_id
account_nbr
和subscription_id
。
我得到product_id
作爲輸入。使用它我可以得到subscription_id from PRODUCT table
和 使用subscription_id
我可以從ACCOUNT表中獲得account_nbr
值。
而不是在兩個查詢中獲取信息,可以在一個查詢中完成?
喜歡的東西下面:
select distinct a.acct_nbr,p.subscription_id
from ACCOUNT a,PRODUCT p
where v.product_id = ' val 1' and
v.subscription_id = p.subscription_id
將比兩個單獨的查詢上述查詢的性能是低?
請提供有關您的DBMS的信息 - 否則只會對性能方面提出常見建議,因爲每個DBMS在優化查詢時都有自己的問題。 –
數據庫是oracle 11g。 – user1758616
你可以展示'EXPLAIN PLAN'嗎? – beny23