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 |
설명 결과에서 이 쿼리에는 특별한 문제는 없지만 다음과 같은 점을 고려할 수 있습니다.
으아악1,
shippingtype
및status
은 열거형 값으로 나타나며tinyint
로 대체할 수 있습니다(숫자 쿼리가 문자열 쿼리보다 빠릅니다).2,
endtime
는 , 원래 null 값을 특수 값(-1 또는 0)으로 바꿉니다.NOT NULL
값은 인덱스NULL
의 효율성에 영향을 미칩니다. 3. 가능하면대신
user_id
을 사용하세요.user
개인 YY 최적화:처음 4가지 조건에 대해서는 별로 할 말이 없습니다. 주요 조건은 마지막 3가지 조건인
,,
consigntime
로 필터링 범위를 작은 것부터 큰 것까지 나열했습니다. (구체적으로는 테이블의 세 가지 조건, 필드 범위에 따라 다릅니다.)created
endtime
일부 제안은 테이블 구조를 수정할 수 있다는 사실을 기반으로 합니다. 권한이 없으면 무시하세요.참고:
강함
이것이 성능에 영향을 미친다는 의미는 아닙니다
설명으로는 문제가 없습니다