- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在有一个包含 200k+ 条记录的表,我正在尝试对其进行 COUNT(*) 搜索。搜索似乎很快,直到进入发送数据阶段。
表格
CREATE TABLE `evento_inscricao_participante_ingresso` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_participante` int(11) DEFAULT NULL,
`id_carrinho` int(11) DEFAULT NULL,
`id_cortesia` int(11) DEFAULT NULL,
`codigo` varchar(255) DEFAULT NULL,
`checkin` datetime DEFAULT NULL,
`criado_em` datetime DEFAULT NULL,
`modificado_em` datetime DEFAULT NULL,
`criado_por` int(11) DEFAULT NULL,
`modificado_por` int(11) DEFAULT NULL,
`deletado` int(1) DEFAULT '0',
`deletado_por` int(11) DEFAULT NULL,
`deletado_em` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `codigo_UNIQUE` (`codigo`),
KEY `fk_evento_inscricao_participante_ingresso_evento_inscricao__idx` (`id_participante`),
KEY `fk_evento_inscricao_participante_ingresso_evento_inscricao__idx1` (`id_carrinho`),
KEY `fk_evento_inscricao_participante_ingresso_evento_cortesia1_idx` (`id_cortesia`),
CONSTRAINT `fk_evento_inscricao_participante_ingresso_evento_inscricao_ca1` FOREIGN KEY (`id_carrinho`) REFERENCES `evento_inscricao_carrinho` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `fk_evento_inscricao_participante_ingresso_evento_inscricao_pa1` FOREIGN KEY (`id_participante`) REFERENCES `evento_inscricao_participante` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB AUTO_INCREMENT=175477 DEFAULT CHARSET=utf8;
查询
SELECT COUNT(*)
FROM evento_inscricao_participante_ingresso t
LEFT JOIN evento_inscricao_carrinho c ON (c.id = t.id_carrinho)
LEFT JOIN evento_inscricao_participante p ON (p.id = t.id_participante)
LEFT JOIN evento_ingresso i ON (i.id = c.id_ingresso)
LEFT JOIN evento_inscricao ins ON (ins.id = c.id_inscricao)
LEFT JOIN evento_cortesia cortesia ON (t.id_cortesia = cortesia.id)
WHERE (i.id_evento = 894
AND i.id = 3255 AND ins.id_status = 1)
OR (cortesia.id_evento = 894
AND cortesia.id_ingresso = 3255 AND t.id_cortesia IS NOT NULL)
个人资料
starting 0.000104
checking permissions 0.000004
checking permissions 0.000002
checking permissions 0.000002
checking permissions 0.000001
checking permissions 0.000002
checking permissions 0.000004
Opening tables 0.000048
System lock 0.000010
init 0.000029
optimizing 0.000016
statistics 0.000035
preparing 0.000020
executing 0.000004
Sending data 18.216500
end 0.000010
query end 0.000004
closing tables 0.000013
freeing items 0.000106
logging slow query 0.000004
cleaning up 0.000004
解释
1 SIMPLE t ALL fk_evento_inscricao_participante_ingresso_evento_cortesia1_idx NULL NULL NULL 205120 NULL
1 SIMPLE c eq_ref PRIMARY PRIMARY 4 ingresso_main.t.id_carrinho 1 NULL
1 SIMPLE p eq_ref PRIMARY PRIMARY 4 ingresso_main.t.id_participante 1 Using index
1 SIMPLE i eq_ref PRIMARY PRIMARY 4 ingresso_main.c.id_ingresso 1 Using where
1 SIMPLE ins eq_ref PRIMARY PRIMARY 4 ingresso_main.c.id_inscricao 1 Using where
1 SIMPLE cortesia eq_ref PRIMARY PRIMARY 4 ingresso_main.t.id_cortesia 1 Using where
所以我不明白为什么如果我已经创建了索引还要花费很多时间。当我删除旧记录时,时间缩短了 50%。我在生产环境(Amazon RDS/m3.medium/5.6.35)和本地主机(MySQL 5.6.35)中进行了测试
连接中使用的所有表的索引:
evento_inscricao_carrinho 0 PRIMARY 1 id A 76098 NULL NULL BTREE
evento_inscricao_carrinho 1 FK_incricao_carrinho_x_evento_ingresso 1 id_ingresso A 76098 NULL NULL YES BTREE
evento_inscricao_carrinho 1 FK_incricao_carrinho_x_usuario 1 id_usuario A 76098 NULL NULL YES BTREE
evento_inscricao_carrinho 1 FK_evento_inscricao_carrinho_x_evento_inscricao 1 id_inscricao A 76098 NULL NULL YES BTREE
evento_inscricao_carrinho 1 fk_evento_inscricao_carrinho_evento_codigo_desconto1_idx 1 id_codigo_desconto A 76098 NULL NULL YES BTREE
evento_inscricao_carrinho 1 fk_evento_inscricao_carrinho_evento_convite_envio1_idx 1 id_convite_restrito A 76098 NULL NULL YES BTREE
evento_inscricao_participante 0 PRIMARY 1 id A 69614 NULL NULL BTREE
evento_inscricao_participante 1 fk_evento_inscricao_participante_evento_inscricao1_idx 1 id_inscricao A 69614 NULL NULL YES BTREE
evento_inscricao_participante 1 fk_evento_inscricao_participante_evento_inscricao_carrinho1_idx 1 id_carrinho A 69614 NULL NULL YES BTREE
evento_ingresso 0 PRIMARY 1 id A 4021 NULL NULL BTREE
evento_ingresso 1 FK_evento_ingresso_x_inquilino 1 id_inquilino A 670 NULL NULL YES BTREE
evento_ingresso 1 FK_evento_ingresso_x_evento 1 id_evento A 4021 NULL NULL YES BTREE
evento_ingresso 1 fk_evento_ingresso_evento_ingresso1_idx 1 id_ingresso_lote A 6 NULL NULL YES BTREE
evento_inscricao 0 PRIMARY 1 id A 90011 NULL NULL BTREE
evento_inscricao 1 FK_evento_incricao_x_tipo_pagamento 1 id_pagamento_tipo A 90011 NULL NULL YES BTREE
evento_inscricao 1 FK_evento_inscricao_x_evento 1 id_evento A 90011 NULL NULL YES BTREE
evento_inscricao 1 FK_evento_inscricao_x_usuario 1 id_usuario A 90011 NULL NULL YES BTREE
evento_inscricao 1 fk_evento_inscricao_evento_inscricao_status1_idx 1 id_status A 90011 NULL NULL YES BTREE
evento_inscricao 1 fk_evento_inscricao_evento_recorrencia1_idx 1 id_recorrencia A 90011 NULL NULL YES BTREE
evento_inscricao 1 fk_evento_inscricao_terminal1_idx 1 id_terminal A 90011 NULL NULL YES BTREE
evento_cortesia 0 PRIMARY 1 id A 778 NULL NULL BTREE
evento_cortesia 1 FK_evento_apoio_x_evento 1 id_evento A 129 NULL NULL YES BTREE
evento_cortesia 1 fk_evento_cortesia_evento_recorrencia1_idx 1 id_recorrencia A 1 NULL NULL YES BTREE
evento_cortesia 1 fk_evento_cortesia_evento_ingresso1_idx 1 id_ingresso A 259 NULL NULL YES BTREE
evento_cortesia 1 fk_evento_cortesia_terminal1_idx 1 id_terminal A 21 NULL NULL YES BTREE
最佳答案
您创建的索引有助于 JOIN,但评估了大部分 WHERE
条件仍然要求 MySQL 迭代表中 200k 行中的大部分来计算 COUNT()
。这需要时间。
在不对数据库结构进行重大更改的情况下,该查询不可能优化得更快。
关于MySQL “Sending data” 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45927526/
我很难理解为什么这段代码无法编译: use std::cell::{Ref, RefCell}; struct St { data: RefCell } impl St { pub f
我从Richard Blum的一本书《 C#网络编程》中读到有关套接字的信息。以下摘录指出,不保证Send()方法可以发送所有传递给它的数据。 byte[] data = new byte[1024]
我有以下程序,它必须一次读取 1MB 的文件,将其发送到服务器(每次总是 1MB)并返回哈希码: #include #include #include #include #include #
代码在底部。 第 207 行的 send() 命令本身可以正常工作。但是,当我在第 218 行添加 send() 命令时,第一个命令失败 - 给出错误“地址错误”。我已经确认第二个 send() 命令
标记包含 !Send 的类型背后的原因是什么?字段(如 Rc 或 NonNull )与 Send特征?例如,标准库的 LinkedList 以这种方式工作:它包含 Option>字段并实现 Send特
我是新手,我正在尝试学习 goroutines 中信号函数的一些基本用法。我在 go 中有一个无限循环。通过这个 for 循环,我通过 channel 将值传递给 goroutine。 我也有一个阈值
如果数据是从另一台计算机(首先)“发送”的,我如何设置我的套接字例程以“发送”(首先)或(切换)“接收”? 谢谢 通用代码: -(void) TcpClient{ char buffer[12
这个问题已经有答案了: Java multiple file transfer over socket (3 个回答) 已关闭 4 年前。 我正在使用 Java Socket 将文件发送到服务器,然后
根据以下示例中的类型,Go编译器似乎将执行两个完全不同的语义操作: chanA <-chanB 如果chanA是类型(chan chan <-字符串),则此操作会将本身类型chanB的类型(chan
我正在尝试在 VBA 中使用 WinSock2 从本地主机 TCP 流发送(以及稍后接收)数据。 目前,我主要尝试从此处复制客户端示例,https://msdn.microsoft.com/en-us
我在我的 Mac OS X Yosemite 控制台中看到了这个: AppleEvents: Send port for process has no send right, port=( port:
我知道Clojure的“代理”是ref,带有“操作”的添加工作队列。 Action 是使用ref的值在第一个位置调用的函数,可以将其传递给其他参数。操作将返回ref的新值。因此,“代理”是一种计算re
我无法将任何对象或数组传递给 IPCRenderer。 通过 ipcs 传递对象或数组时出现错误,我什至尝试通过使用 JSON.stringify 转换为字符串来发送,但它会将其转换为空对象字符串。
我正在使用unix scoket进行数据传输(SOCK_STREAM模式) 我需要发送超过100k个字符的字符串。首先,我发送一个字符串的长度-它是sizeof(int)个字节。 length = s
Clojure API 将这两个函数描述为: (send a f & args) - Dispatch an action to an agent. Returns the agent immedia
def send_Button(): try: myMsg = "ME: " + text.get() msg = text.get() con
Ruby 对象都有一个“发送”方法,但是,我正在尝试使用一个 Java 库 ( netty-tools ),它的一个接口(interface)上有一个“发送”方法。 用法应该是 java_obj.se
Feb 8, 2011 11:56:49 AM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPC onnection post SEVE
来自 man 2 send: MSG_MORE (since Linux 2.4.4) (…) Since Linux 2.6, this flag is also supported for UDP
我的网页中可以有一个按钮,用于将预填充的消息发送到特定号码吗? 我正在尝试 intent://send/+391234567890#Intent;scheme=smsto;package=com.wh
我是一名优秀的程序员,十分优秀!