mysql_slow_queriesログに次のようなクエリがあります。
Query_time:4.642323 Lock_time:1.821996 Rows_sent:14 Rows_examined:27099
SET TIMESTAMP=1356068688;
SELECT gw.id website_id, gw.name,gw.url,gw.language,gw.title,gw.nickname, gd.id,
gd.deal_title, gd.cdeal_title, gd.deal_details, gd.cdeal_details,
gd.discount_price, gd.original_price, gd.savings, gd.expiry, gd.shop,
gd.location, gd.clocation, gd.limited_offer, gd.contact, gd.url website,
gd.affiliate_url, gd.tags, gd.pic_url, gd.featured, gd.top_pos,
gd.sub_pos, gd.appeal, gd.redeem_until, gd.noofpurchased
FROM groupon_deals gd
INNER JOIN groupon_websites gw ON gw.id=gd.groupon_websites_id
WHERE gd.tags LIKE '%technology-and-gadgets%' AND gd.pubDate >= SYSDATE() - INTERVAL 24 HOUR AND
gd.hidden = 0 AND gd.pubDate < SYSDATE() AND
gd.id NOT IN (1,30079,30090,30116,30118,30070,30136,30137,30138,30156,30103,30157,30038,30044,30084,30025,30013,30111,30030,30020,30059,30087,30026,30016,30112,30031,30021,30005,30092,30027,30017,30113,30049,30032,30023,30006,30096,30040,30028,30018,30120,30033,30024,30008,30110,30029,30019,30128,30131,30129,30100,30004,29995,30076,30126,30069,30078,30071,30034,30080,30065,30073,30082,29987,30074,30117,30068,29981,30098,30102,30088,30119,30135,30155,30107,29997,30041,30046,30077,30003,29992,30058,30097,30014,29999,30066,30127,30009,30081,29993,30060,30015,30114,30000,29985,30099,30010,30083,29994,30061,30022,30115,30001,30072,29986,30011,30086,30062,30123,30002,30075,29990,30054,30160,30094,30012,29998,30064,30125,30039,30130,30134,29982,30159,30048,30047,30158,30043,30101,30104,30106,30122,30056,30057,30063,30161,30053,29984,30132,30109,30036,30108,30037,30121,30045,30124) AND
(gw.language = 'C' OR gw.language = 'B')
ORDER BY gd.sub_pos,gd.noofpurchased DESC
phpMyAdminにアクセスし、EXPLAINを使用して同じクエリを実行すると、次の出力が得られます: http: //algaryeung.com/temp/explain-output.jpg
2つの質問があります:
1)ログのrows_examinedが27099であるのに対し、EXPLAIN 37、756のrows_examinedは異なるのはなぜですか?実際の行を調べるには、EXPLAINの2つの値を乗算する必要がありますか?
2)これは一種のオープンエンドであることは知っていますが、既存のクエリを改善するにはどうすればよいですか?フィールドgroupon_deals.groupon_websites_idにインデックスを付けましたが、クエリのNOTIN部分を改善する方法があると思います。ここで完全な答えを期待していませんが、どこから掘り出し/学習を開始するかについて何か考えはありますか?