-1

以下のクエリのパフォーマンスを向上させる方法

select 
     distinct o1.id as c1, 
              a1.id as c2,
              o1.t1_id as c3, 
              o1.t2_id as c4,
              o1.t_p_id as c5 
from 
     ord o1 
     left outer join 
     acc a1 
       on o1.end_user_id=a1.id 
     left outer join 
     acc a2 
       on 1.t1_id=a2.id 
     left outer join 
     acc a3 
       on o1.t2_id=a3.id 
     left outer join 
     acc a4 on 
       o1.t_p_id=account4_.id 
where 
     a1.account_id=1 or a2.account_id=1 or a3.account_id=1 or a4.account_id=1;
4

2 に答える 2

1

同じaccテーブルで非常に多くの左外部結合がパフォーマンスの問題を引き起こす理由である可能性があります。

あなたの意図を理解してから、同じテーブルで非常に多くの左結合を排除することをお勧めします。

一般的な分析については、@ScottMarloweが正しいと思います。インデックス、説明結果など、より多くの情報を提供する必要があります...

于 2013-02-22T07:01:25.143 に答える
0

私は専門家ではありませんが、「左結合」を使用する代わりに「exists」コマンドを使用できます。

以下のように「exists」コマンドを使用してクエリを作成しようとしました。

select 
     distinct o1.id as c1, 
              a1.id as c2,
              o1.t1_id as c3, 
              o1.t2_id as c4,
              o1.t_p_id as c5 
from ord o1 
        where exists (select 1 
                        from acc a1 where o1.end_user_id=a1.id and a1.account_id=1)
        or exists (select 1 
                        from acc a2 where o1.end_user_id=a2.id and a2.account_id=1)  
        or exists (select 1 
                        from acc a3 where o1.end_user_id=a3.id and a3.account_id=1)  
        or exists (select 1 
                        from acc a4 where o1.end_user_id=a4.id and a4.account_id=1);

お役に立てば幸いです。

于 2013-05-23T13:26:17.157 に答える