0

以下のSQLを取得したとします

クエリのパフォーマンスを最適化するにはどうすればよいですか?

select product, address, quantity, 
    price, create_date, sum(no_of_photo) as no_of_photo
from
(
    SELECT customer.PROJECT_ID as project_id ,
        customer.ORDER_TYPE as order_type,  
        customer.product_name as product, 
        customer.address_name as address ,    
        customer.quantity_name as quantity,
        user.first_name || ' ' || user.last_name AS price,
        customer.create_date, customer.no_of_photo 
    FROM customer 
    INNER JOIN user 
        ON customer.creation_userid = user.userid
) master_list 
group by project_id, order_type , 
    product, address, quantity, price, 
    create_date 
having project_id = 123456 
order by product, address, quantity, price, create_date
4

2 に答える 2

4

私が試すいくつかのこと:

  1. HAVING 句を内部クエリの WHERE に入れます
  2. 内部クエリで first_name と last_name を単独で選択する
  3. 外側のクエリで first_name、last_name でグループ化 (なぜ価格と呼ばれるのですか?)
  4. first_name || を連結します。' ' || 外部クエリの last_name

また、次の場所にインデックスがあることを確認してください。

  • customer.project_id
  • customer.creation_userid
  • user.userid
于 2012-09-21T10:26:12.057 に答える
1

通常、最良の増加は、インデックスを作成することによってもたらされます。内部結合について質問します。内部結合なしで高速ですか?次に、おそらく user.userid のインデックスが必要です。

于 2012-09-21T10:32:26.830 に答える