添加一些列,在mysql查询中增加很多获取时间

时间:2017-06-19 07:48:46

标签: mysql

SQL1:

SELECT id
, orderNo
, consumerId
, consumerName
, state
, totalAmount
, totalIntegral
, cid
, rid
, totalQuantity
, areaId
FROM oms_order
WHERE rid IN 
    (SELECT rn.id
    FROM oms_doc_region rn
    WHERE rn.cityCode = '320100')
        AND state = '2'
        AND deliveryTime >= CONCAT('2017-03-01',' 00:00:00')
        AND deliveryTime <= CONCAT('2017-06-19',' 23:59:59') 
ORDER BY  areaId asc, orderTime 

持续时间:0.188秒/ 获取时间:0.063秒

SQL2:

SELECT id
, orderNo
, consumerId
, consumerName
, state
, totalAmount
, totalIntegral
, cid
, rid
, totalQuantity
, areaId
, areaName
, staffName
FROM oms_order
WHERE rid IN 
    (SELECT rn.id
    FROM oms_doc_region rn
    WHERE rn.cityCode = '320100')
        AND state = '2'
        AND deliveryTime >= CONCAT('2017-03-01',' 00:00:00')
        AND deliveryTime <= CONCAT('2017-06-19',' 23:59:59') 
ORDER BY  areaId asc, orderTime 

持续时间:0.453秒/ 获取时间:7.721秒

我不知道为什么只添加两列(areaName&amp; staffName),但增加了很多获取时间,为什么会这样?以及如何改善它? (areaName&amp; staffName值为chinese。)

表创建Sql:

create table oms_order
(
   id                   bigint(20) not null ,
   orderNo              varchar(64) ,
   consumerId           bigint(20) ,
   consumerName         varchar(128) ,
   state                int(1) default 0 ,
   orderTime            datetime not null ,
   deliveryTime         datetime ,
   receivingId          bigint(20) ,
   receivingName        varchar(128) ,
   receivingPhone       varchar(20) ,
   receivingAddress     varchar(256) ,
   createTime           datetime ,
   updateTime           datetime ,
   remark               varchar(512) ,
   payModel             tinyint(4) default 0 ,
   totalAmount          decimal(12,4) default 0 ,
   totalIntegral        int default 0 ,
   printTime            datetime ,
   printCount           int ,
   cid                  bigint(20) ,
   dealerName           varchar(128) ,
   mainOrderId          bigint(20) ,
   rid                  bigint(20),
   totalQuantity        bigint(20) ,
   areaId               BIGINT(20)  ,
   areaName             VARCHAR(128)  ,
   staffName            VARCHAR(128)  ,
   staffPhone           VARCHAR(64)  ,
   primary key (id)
)
ENGINE=InnoDB;

0 个答案:

没有答案