Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL多个发送数据状态_Php_Mysql_Profiling_Entity Attribute Value_Explain - Fatal编程技术网

Php MySQL多个发送数据状态

Php MySQL多个发送数据状态,php,mysql,profiling,entity-attribute-value,explain,Php,Mysql,Profiling,Entity Attribute Value,Explain,我的查询太长了。当我对其进行分析时,我会看到类似的情况: Sending data 0.039324 executing 0.000011 Sending data 0.039662 executing 0.000012 Sending data 0.040380 executing 0.000015 Sending data 0.035879 executing 0.000012 S

我的查询太长了。当我对其进行分析时,我会看到类似的情况:

    Sending data    0.039324
    executing   0.000011
    Sending data    0.039662
    executing   0.000012
    Sending data    0.040380
    executing   0.000015
    Sending data    0.035879
    executing   0.000012
    Sending data    0.035426
    executing   0.000012
    Sending data    0.038107
    executing   0.000011
    Sending data    0.035247
    executing   0.000011
    Sending data    0.050108
    executing   0.000014
    Sending data    0.045458
    executing   0.000012
    Sending data    0.034700
    executing   0.000012
    Sending data    0.036205
    executing   0.000012
    Sending data    0.034602
    executing   0.000015
    Sending data    0.034580
    executing   0.000012
    Sending data    0.034477
    executing   0.000010
    Sending data    0.034382
    executing   0.000010
    Sending data    0.034416
    executing   0.000011
    Sending data    0.034335
    executing   0.000010
    Sending data    0.034474
    executing   0.000010
    Sending data    0.034405
    executing   0.000010
    Sending data    0.034433
    executing   0.000011
    Sending data    0.034544
    executing   0.000010
    Sending data    0.034525
    executing   0.000011
    Sending data    0.034459
    executing   0.000010
    Sending data    0.034766
    executing   0.000011
    Sending data    0.034633
    executing   0.000010
    Sending data    0.034574
    executing   0.000011
    Sending data    0.034607
    executing   0.000010
    Sending data    0.034613
    executing   0.000011
    Sending data    0.034394
    executing   0.000010
    Sending data    0.034606
    executing   0.000011
    Sending data    0.034790
    executing   0.000011
    Sending data    0.034614
    executing   0.000011
    Sending data    0.034497
    executing   0.000010
    Sending data    0.034756
    executing   0.000010
    Sending data    0.034440
    executing   0.000010
    Sending data    0.034414
    executing   0.000011
    Sending data    0.034484
    executing   0.000011
    Sending data    0.034490
    executing   0.000011
    Sending data    0.034672
    executing   0.000011
    Sending data    0.034455
    executing   0.000011
    Sending data    0.034430
    executing   0.000011
    Sending data    0.034509
    executing   0.000012
    Sending data    0.034432
    executing   0.000012
    Sending data    0.034348
    executing   0.000011
    Sending data    0.034378
    executing   0.000011
    Sending data    0.034356
    executing   0.000011
    Sending data    0.034631
    end 0.000014
    query end   0.000007
    closing tables  0.000010
    freeing items   0.000025
    logging slow query  0.000003
    logging slow query  0.000004
    cleaning up 0.000004
里面发送的数据太多了

我运行的查询:

SELECT COUNT(*) as count from OrdersArchive where ID>0 and PId IN ('2564') and 
   (
   ID like '17000106864' 
   OR `OrderID` like '17000106864' 
   OR `ID` IN
   (
       SELECT `transferID`
       FROM `custom_fields`
       WHERE `fieldName` = 'invoiceNumber'
       AND `value` like '%17000106864%'
   )
   OR `tpb` LIKE '17000106864' 

   )
解释节目

id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY OrdersArchive range PRIMARY,ID_UNIQUE PRIMARY 4 NULL 41609 Using where 2 DEPENDENT SUBQUERY custom_fields ALL NULL NULL NULL NULL 93141 Using where id选择\u类型表类型可能的\u键\u长度参考行额外 1主订单蜂窝范围主,ID_唯一主4 NULL 41609使用where 2个相依子查询自定义_字段所有NULL 93141使用where MySQL表结构:

CREATE TABLE IF NOT EXISTS `OrdersArchive` ( `ID` int(11) NOT NULL, `ids` int(11) NOT NULL DEFAULT '0', `OrderID` varchar(11) NOT NULL DEFAULT '0', `PricePosition` int(11) NOT NULL DEFAULT '0', `Reverse` tinyint(1) DEFAULT NULL, `DataOrder` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `DataFlightTrain` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `Customer` varchar(255) DEFAULT NULL, `PhoneCustomer` varchar(255) DEFAULT NULL, `EmailCustomer` varchar(255) DEFAULT NULL, `Provider` int(11) DEFAULT NULL, `DeliveryTime` timestamp NULL DEFAULT NULL, `Address1` varchar(255) DEFAULT NULL, `Address2` varchar(255) NOT NULL, `Passangers` varchar(1024) DEFAULT NULL, `PassangersPhones` varchar(255) NOT NULL, `PassangersEmailes` varchar(255) NOT NULL, `FlightTrain` varchar(255) DEFAULT NULL, `QuantityPassangers` int(11) DEFAULT '1', `NamePlate` varchar(255) DEFAULT NULL, `PhoneDriver` varchar(255) DEFAULT NULL, `PhoneDriverNeed` tinyint(1) DEFAULT '0', `Status` int(11) DEFAULT NULL, `Operator` int(11) DEFAULT NULL, `userId` int(11) NOT NULL, `usn` varchar(256) NOT NULL, `ArendaNeed` varchar(255) DEFAULT '', `ArendaHour` int(11) DEFAULT NULL, `ArendaMinutes` varchar(255) DEFAULT '', `Cost` double DEFAULT NULL, `Notes` text NOT NULL, `notes2` varchar(256) NOT NULL DEFAULT '', `PId` int(11) NOT NULL DEFAULT '0', `Voucher` varchar(256) NOT NULL, `Invoice` varchar(256) NOT NULL, `Meet` varchar(255) NOT NULL, `Toward` varchar(255) NOT NULL, `techStatus` int(2) NOT NULL DEFAULT '0', `City` varchar(55) NOT NULL, `City2` varchar(55) NOT NULL, `Auto` varchar(30) NOT NULL, `department` varchar(255) NOT NULL DEFAULT '', `nsktime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `tpb` varchar(255) NOT NULL DEFAULT '', `ban_add_races` int(1) NOT NULL DEFAULT '0', `paid` int(10) NOT NULL DEFAULT '0', `taxi` varchar(255) NOT NULL DEFAULT '', `price_client` int(11) DEFAULT NULL, `comission_from_client` int(11) DEFAULT NULL, `primechanie` varchar(1000) DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`), KEY `fk_Orders_Users1_idx` (`Operator`), KEY `fk_Orders_Providers1_idx` (`Provider`), KEY `fk_Orders_OrderStatus1_idx` (`Status`), KEY `ids` (`ids`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ## and other table CREATE TABLE IF NOT EXISTS `custom_fields` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `pid` int(11) NOT NULL, `transferID` int(11) NOT NULL, `fieldName` varchar(255) NOT NULL, `value` varchar(1024) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=325452 ; 如果不存在“OrdersArchive”,则创建表( `ID`int(11)不为空, `ids`int(11)不为空默认值'0', `OrderID`varchar(11)不为NULL默认值为'0', `PricePosition`int(11)非空默认值'0', `反向'tinyint(1)默认为空, `DataOrder `时间戳空默认当前时间戳更新当前时间戳, `DataFlightTrain`时间戳非空默认值'0000-00-00:00:00', `Customer`varchar(255)默认为空, `PhoneCustomer`varchar(255)默认为空, `EmailCustomer`varchar(255)默认为空, `提供程序`int(11)默认为空, `DeliveryTime`时间戳为空默认为空, `Address1`varchar(255)默认为空, `Address2`varchar(255)不为空, `Passenger'varchar(1024)默认为空, `PassengerSphones的varchar(255)不为空, `PASSANGESMAILES`varchar(255)不为空, `FlightTrain`varchar(255)默认为空, `QuantityPassangers`int(11)默认值'1', `铭牌'varchar(255)默认为空, `PhoneDriver`varchar(255)默认为空, `PhoneDriverNeed`tinyint(1)默认值为'0', `状态`int(11)默认为空, `运算符`int(11)默认为空, `userId`int(11)不为空, `usn`varchar(256)不为空, `ArendaNeed`varchar(255)默认值“”, `ArendaHour`int(11)默认为空, `ArendaMinutes`varchar(255)默认值“”, `成本`双默认为空, `注释`文本不为空, `注2`varchar(256)非空默认值“”, `PId`int(11)不为空默认值'0', `凭证'varchar(256)不为空, `发票'varchar(256)不为空, `满足`varchar(255)不为空, `指向`varchar(255)非空, `techStatus`int(2)非空默认值'0', `City`varchar(55)不为空, `City2`varchar(55)不为空, `Auto`varchar(30)不为空, `部门“varchar(255)非空默认值”, `nsktime`时间戳非空默认值'0000-00-00:00:00', `tpb`varchar(255)非空默认值“”, `ban_add_races`int(1)非空默认值“0”, `paid`int(10)非空默认值'0', `taxi`varchar(255)非空默认值“”, `price_client`int(11)默认为空, `来自客户端的佣金`int(11)默认为空, `primechanie`varchar(1000)默认为空, 主键(`ID`), 唯一键'ID\u UNIQUE'('ID'), 键'fk\u Orders\u Users1\u idx'('Operator'), 键'fk_Orders_Providers1_idx'('Provider'), 键“fk\U Orders\U OrderStatus1\U idx”(“状态”), 键'ids'('ids`) )ENGINE=InnoDB默认字符集=utf8; ##和其他桌子 如果不存在“自定义字段”,则创建表( `ID`int(11)非空自动增量, `pid`int(11)不为空, `transferID`int(11)不为空, `fieldName`varchar(255)不为空, `值`varchar(1024)不为空, 主键(`ID`) )引擎=InnoDB默认字符集=utf8自动增量=325452;
虽然当前的SELECT查询可能会在某种程度上得到改进,但我认为如果您能够以更高效的方式存储数据,尤其是如果您能够消除对

类似“%17000106864%”

如果为invoiceNumber创建一个单独的字段,并在插入数据时填充该字段,则可以将其编入索引,并按如下方式选择/合并:

其中invoiceNumber=17000106864


如果您只查找一条记录,那么为查询添加一个限制也会有所帮助。

虽然当前的SELECT查询可能会得到某种程度的改进,但我认为如果您能够以更高效的方式存储数据,尤其是如果您能够消除对查询的需要,那么它会有更大的帮助

类似“%17000106864%”

如果为invoiceNumber创建一个单独的字段,并在插入数据时填充该字段,则可以将其编入索引,并按如下方式选择/合并:

其中invoiceNumber=17000106864


如果您只查找一条记录,那么向查询添加限制也会有所帮助。

好吧,我通过内部连接完成了这一点。运行0.34秒

最后一个问题是:

SELECT COUNT(`OrdersArchive`.ID) as count, `OrdersArchive`.ID FROM `OrdersArchive` INNER JOIN `custom_fields` on `OrdersArchive`.ID = `custom_fields`.`transferID` WHERE `OrdersArchive`.ID>0 AND `custom_fields`.`fieldName` = 'invoiceNumber' AND `OrdersArchive`.PId IN ('2564') AND ( `OrdersArchive`.ID LIKE '17000106864' OR `OrdersArchive`.`OrderID` LIKE '17000106864' OR `OrdersArchive`.`tpb` LIKE '17000106864' OR ( `custom_fields`.`value` like '%17000106864%' ) ) 选择COUNT(`OrdersArchive`.ID)作为COUNT,`OrdersArchive`.ID 从Sarchive` 在“OrdersArchive”上的内部联接“custom\u fields”。ID=`custom\u fields`.`transferID` 其中`OrdersArchive`.ID>0 和“自定义字段”。“字段名”=“发票编号” 及 `OrdersArchive`.PId位于('2564')和 ( `OrdersArchive`.我想要“17000106864” 或“OrdersArchive”。“OrderID”类似于“17000106864” 或“OrdersArchive”。“tpb”类似于“17000106864” 或( `自定义_字段`.`value`类似于“%17000106864%” ) )
嗯,我是通过内部连接完成的。运行0.34秒

最后一个问题是:

SELECT COUNT(`OrdersArchive`.ID) as count, `OrdersArchive`.ID FROM `OrdersArchive` INNER JOIN `custom_fields` on `OrdersArchive`.ID = `custom_fields`.`transferID` WHERE `OrdersArchive`.ID>0 AND `custom_fields`.`fieldName` = 'invoiceNumber' AND `OrdersArchive`.PId IN ('2564') AND ( `OrdersArchive`.ID LIKE '17000106864' OR `OrdersArchive`.`OrderID` LIKE '17000106864' OR `OrdersArchive`.`tpb` LIKE '17000106864' OR ( `custom_fields`.`value` like '%17000106864%' ) ) 选择COUNT(`OrdersArchive`.ID)作为COUNT,`OrdersArchive`.ID 从Sarchive` 在“OrdersArchive”上的内部联接“custom\u fields”。ID=`custom\u fields`.`transferID` 其中`OrdersArchive`.ID>0 和“自定义字段”。“字段名”=“发票编号” 及 `OrdersArchive`.PId位于('2564')和 ( `OrdersArchive`.我想要“17000106864” 或“OrdersArchive”。“OrderID”类似于“17000106864” 或“OrdersArchive”。“tpb”类似于“17000106864” 或( `自定义_字段`.`value`类似于“%17000106864%” ) )
回到标题中隐含的问题(“多个发送数据状态”)

(选择…)中的
通常效率很低。在您的例子中,它被重复执行,从而为每次调用“执行”和“发送数据”

其他答案通过将该构造转换为
连接
,解决了另一个隐含问题(“查询运行太长”)

其他问题

PRIMARY KEY (`ID`),   -- This is UNIQUE and an INDEX
UNIQUE KEY `ID_UNIQUE` (`ID`),  -- totally redundant; DROP it
由于模式是“EAV”(实体属性值),并且需要基于某个键值(“invoiceNumber”)进行筛选,因此可能会遇到性能问题。骗局