0

概要:

各製品に存在する場合と存在しない場合がある、製品とユーザーのコメントのページがあります。1 つのテーブルは製品の詳細 (products_master) を保持し、1 つのテーブルは表示される製品を決定します (shoppingfeed)。クエリ #1 から各製品をループして出力すると、クエリ #2 が実行され、現在表示されている製品に関連するコメントがクエリ #1 から取得されます。

問題: これはすべて動作しますが、遅いです! これを 1 回実行できる 1 つの最適化されたクエリに結合し、それをループする方法があるかどうかを考えています... またはこれを高速化する他のアイデア.

クエリ #1

 SELECT shoppingfeed.action_date,
       products_master.name,
       products_master.image_url,
       products_master.pop_sku,
       products_master.group_id,
       products_master.lowest_price,
       products_master.highest_price,
       products_master.merchant,
       products_master.width,
       products_master.height
FROM   products_master,
       shoppingfeed
WHERE  ( shoppingfeed.sf_product_id = products_master.pop_sku )
ORDER  BY action_date DESC
LIMIT  #offset#, #maxrow#  

クエリ #2

 SELECT DISTINCT comment,
                comment_id,
                comments.user_id,
                comment_date_time,
                comment_visibility,
                comments.friend_user_id,
                thread_id,
                alias,
                first_name,
                last_name,
                action_id,
                group_id,
                users.fb_resource_id,
                gender,
                acct_type,
                ascore
FROM   comments,
       users,
       products_master,
       user_relationship
WHERE  comments.sf_product_id = #feed_item.pop_sku#
       AND comments.user_id = users.user_id
       AND products_master.pop_sku = #feed_item.pop_sku#
       AND ( ( comments.user_id = user_relationship.sf_id
               AND user_relationship.user_id = #SESSION.user_id#
               AND user_relationship.relationship_status = 3 )
              OR ( comments.user_id = #session.user_id#
                   AND user_relationship.user_id = #SESSION.user_id#
                   AND user_relationship.relationship_status = 99 ) )
ORDER  BY comment_date_time ASC  

これが私がまとめたビューです

を選択しますproducts_masterpop_skuとして pop_skuproducts_mastergroup_idとして group_idproducts_masternameとして nameproducts_masterimage_urlとして image_urlproducts_masterlast_updatedとして last_updatedproducts_masterhave_it_usersとして have_it_usersproducts_masterwant_it_usersとして want_it_usersproducts_masteradults_onlyとして adults_onlyproducts_masterreviewed_byとして reviewed_byproducts_masterdonate_needed_qtyとして donate_needed_qtyproducts_masterinspired_usersとして inspired_usersproducts_masterdeal_users_upとして deal_users_upproducts_masterdeal_users_downとして deal_users_downproducts_mastermerchantとして merchantproducts_mastermerchant_logoとして merchant_logoproducts_masterwidthとして widthproducts_masterheightとして heightproducts_masteradded_byなので added_byproducts_masterproduct_category_idとして product_category_idcommentscommentとして commentcommentscomment_date_timeとして comment_date_timecommentscomment_visibilityとして comment_visibilitycommentsfriend_user_idとして friend_user_idcommentsuser_idとして user_idcommentsaction_idとして action_idcommentscomment_idとして comment_idshoppingfeedaction_codeとして action_codeshoppingfeedaction_dateとして action_dateshoppingfeednew_friend_idとして new_friend_idshoppingfeedquestion_idとして question_idusersfirst_nameとしてfirst_nameuserslast_name としてlast_nameusersshopping_cloutとして shopping_cloutusersgenderとしてgenderusersfb_resource_id としてfb_resource_idcommentsthread_idとして thread_idusers. wish_qtyとしてwish_qtymerchantslogoとして logomerchantscompanynameとして companynameproduct_relationshipdesirabilityAS desirability from ((((( products_masterjoin shoppingfeed on(( products_master. pop_sku= shoppingfeed. sf_product_id))) join commentson(( products_master. pop_sku= comments. sf_product_id))) join userson((( comments. user_id= users. user_id) and ( comments. user_id= shoppingfeed. user_id)))) join product_relationship on(( product_relationship. user_id= users. user_id))) join merchantson((( products_master. merchant= merchants. merchantid) and ( product_relationship. sf_product_id = products_master. pop_sku)))) order by comments.comment_date_time

4

2 に答える 2

0

いくつかのインデックスを追加し、ビューを作成しました。これで準備が整いました。さらに高速化するために、さらにいくつかのインデックスを試してみるつもりですが、今のところ満足しています。

于 2013-09-07T18:04:18.203 に答える