select count(*) from trade where shippingtype <> "free" and status
in ("TRADE_FINISHED","WAIT_SELLER_SEND_GOODS") and tosellerreachgoods = 0 and consigntime <1470110400000 and ( endtime >=1469980800000 or endtime is null ) and created >=1469980800000 and created <=1470067200000 and user = "xxxxxxxxxxxxxxxx" ;
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | trade | range | trade__user,trade_user_created,trade_user_buyernick,trade__status_created,trade_user_status | trade_user_created | 108 | NULL | 588 | Using index condition; Using where |
Explain 結果からはこのクエリに特別なことはありませんが、次の点が考えられます。
リーリー1、
shippingtype
、およびstatus
は列挙値であるように見え、tinyint
に置き換えることができます (数値クエリは文字列クエリよりも高速です)。2、
endtime
は 、元の null 値を特殊な値 (-1 または 0) に置き換えます。NOT NULL
値はインデックスの効率に影響します。NULL
3. 可能であれば、の代わりに
user_id
を使用します。 🎜>user
個人 YY の最適化:最初の 4 つの条件については特に言うことはありません。主なものは、
、、
consigntime
のフィルタリング範囲に従って配置されています。 (具体的には、テーブルの 3 つの条件、フィールドの範囲によって異なります)。created
endtime
いくつかの提案は、テーブル構造を変更できるという事実に基づいています。権限がない場合は無視してください。参考: http://tech.meituan.com/mysql...
強い
パフォーマンスに影響を与えるという意味ではありません
説明から見て問題ありません