- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
本人MySQL不强,有菜鸟错误请见谅。简短版本:
SELECT locId,count,avg FROM destAgg_geo 比 SELECT * from destAgg_geo 显着慢
prtt.destAgg 是一个以 dst_ip (PRIMARY) 为键的表
mysql> describe prtt.destAgg;
+---------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+-------+
| dst_ip | int(10) unsigned | NO | PRI | 0 | |
| total | float unsigned | YES | | NULL | |
| avg | float unsigned | YES | | NULL | |
| sqtotal | float unsigned | YES | | NULL | |
| sqavg | float unsigned | YES | | NULL | |
| count | int(10) unsigned | YES | | NULL | |
+---------+------------------+------+-----+---------+-------+
geoip.blocks 是一个以 startIpNum 和 endIpNum (PRIMARY) 为键的表
mysql> describe geoip.blocks;
+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| startIpNum | int(10) unsigned | NO | MUL | NULL | |
| endIpNum | int(10) unsigned | NO | | NULL | |
| locId | int(10) unsigned | NO | | NULL | |
+------------+------------------+------+-----+---------+-------+
destAgg_geo 是一个 View :
CREATE VIEW destAgg_geo AS SELECT * FROM destAgg JOIN geoip.blocks
ON destAgg.dst_ip BETWEEN geoip.blocks.startIpNum AND geoip.blocks.endIpNum;
这里是select *的优化方案:
mysql> explain select * from destAgg_geo;
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| 1 | SIMPLE | blocks | ALL | start_end | NULL | NULL | NULL | 3486646 | |
| 1 | SIMPLE | destAgg | ALL | PRIMARY | NULL | NULL | NULL | 101893 | Range checked for each record (index map: 0x1) |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
针对特定列的select优化方案如下:
mysql> explain select locId,count,avg from destAgg_geo;
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| 1 | SIMPLE | destAgg | ALL | PRIMARY | NULL | NULL | NULL | 101893 | |
| 1 | SIMPLE | blocks | ALL | start_end | NULL | NULL | NULL | 3486646 | Range checked for each record (index map: 0x1) |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
下面是 destAgg 中每一列的优化计划以及 geoip.blocks 中的 locId 列:
mysql> explain select dst_ip,total,avg,sqtotal,sqavg,count,locId from destAgg_geo;
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| 1 | SIMPLE | blocks | ALL | start_end | NULL | NULL | NULL | 3486646 | |
| 1 | SIMPLE | destAgg | ALL | PRIMARY | NULL | NULL | NULL | 101893 | Range checked for each record (index map: 0x1) |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
删除除 dst_ip 之外的任何列,范围检查 翻转到 block :
mysql> explain select dst_ip,avg,sqtotal,sqavg,count,locId from destAgg_geo;
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| 1 | SIMPLE | destAgg | ALL | PRIMARY | NULL | NULL | NULL | 101893 | |
| 1 | SIMPLE | blocks | ALL | start_end | NULL | NULL | NULL | 3486646 | Range checked for each record (index map: 0x1) |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
这样会慢很多。这是怎么回事?
(是的,我可以只使用 * 查询结果并从那里处理,但我想知道发生了什么以及为什么)
编辑——对 VIEW 查询进行解释:
mysql> explain SELECT * FROM destAgg JOIN geoip.blocks ON destAgg.dst_ip BETWEEN geoip.blocks.startIpNum AND geoip.blocks.endIpNum;
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
| 1 | SIMPLE | blocks | ALL | start_end | NULL | NULL | NULL | 3486646 | |
| 1 | SIMPLE | destAgg | ALL | PRIMARY | NULL | NULL | NULL | 101893 | Range checked for each record (index map: 0x1) |
+----+-------------+---------+------+---------------+------+---------+------+---------+------------------------------------------------+
最佳答案
如果您对两个查询都运行 EXPLAIN PLAN,MySQL 会告诉您。
第一个包含列的查询不包含任何键列,所以我猜它必须执行 TABLE SCAN。
带有“SELECT *”的第二个查询包括主键,因此它可以使用索引。
关于MySQL select specific cols 比 select * 慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2976278/
我正在 sitepoint 上阅读一篇文章 - http://www.sitepoint.com/how-to-create-mysql-events/关于mysql事件的主题,当你可以安排时我遇到了
我想为用户预订一个特定的时间(开始时间和结束时间),其他人不能在同一时间预订。例如:John预约了一个月5号7点到8点的时间,我想没有其他人可以在同一时间和日期预订。我想查一下时段,因为如果像John
I want to book a specific time for the user (start hour and end hour ) and no one else can book a
我已经克隆了 linux 内核 git 仓库: git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 我
我正在尝试获取下面突出显示的文本“frei ab 01.05.2017”。然而问题是,“section_content iw_right”类在该网站上出现了 19 次。我会执行 find_all 并仅
我尝试找到这个问题,但所有其他问题都与我的问题无关。 我的问题:我有类似 0xFreeFoodU 的东西,我必须获得特定的位置,然后翻转它们或将它们设为 1 或 0。 例如,位置 2、6、10、14、
我正在尝试创建一个登录功能,该功能允许我指定要从中选择数据的表以及要选择的字段。我已设法将表值传递给函数,并从所需的表中选择数据,但我的表有不同的字段。如何在查询中指定它是一个表选择: user_id
我是 Rails 的新手,在获取布局(用作唯一的静态登录页面)来加载我想与之关联的特定样式表时遇到了问题。例如:www.landing.com 加载landing.scss.erb . 作为背景,所有
我不明白为什么这两个示例的行为不同。 HTML 和 CSS 的目的只是简单地水平对齐 div,并让最后一个 div(向右)占据剩余空间(容器的剩余宽度)。 为正确的元素使用特定的 id: #left
我是 postfix 的新手。如何使用限制类或其他方法将特定用户的特定域列入黑名单。 假设我的机器有两个用户 - user1 和 user2。 我想将abc.com 到user1@mydomain 的
当记事本是 .txt 文件的默认程序时,我如何告诉 Windows 在写字板中打开 C:\test\test.txt? 最佳答案 接受的答案对我不起作用。我不确定这是因为我试图运行的程序,还是因为路径
对于下面的代码示例,我需要检查一个 tr ,type="a"并且有一个带有文本“3”作为 child 的 td ,是否存在: 1 1
var s = '-10px -10px'; var n = '33px'; 我需要一个产生这个结果的正则表达式:'-10px 33px' 类似于:s.replace(???, n) 最佳答案 如果您
一个项目 table: items 有许多分类法 table: taxonomies 使用连接表 item_taxonomies (item_id, taxonomy_id)。 使用分类组搜索项目。
h:panelGrid 表有 2 列。 这是必需的,第一列为整个表格宽度的 30%,第二列为整个表格宽度的 70%。 这种情况有一些配置吗?看起来 columnClasses 属性应用于所有列, 并且
特定阶段仅在特定计算机上卡在队列中 显示队列中的位置:1,但无法连接到代理,即使没有其他作业正在运行且队列为空 所有其他阶段都工作正常 故障阶段在不同的机器上工作正常 代理已在线并已启用 我们所有的代
我正在使用 CakePHP 3.3.10。我需要将 JavaScript 文件添加到特定 View 。 // default.ctp // I need to remove this script
首先,我发现提出问题很困难,欢迎反馈。 我必须制作一个机器学习代理来玩点和盒子。 我还处于早期阶段,但提出了一个问题:如果我让我的机器学习代理(具有特定的实现)与它自身的副本进行对抗来学习和改进它的游
我是开发 iOS 应用程序的新手,英语不是我的母语,所以请原谅我的任何错误和丑陋的代码。 我尝试创建的应用程序应该只在特定的一天显示一张特定的图像(如果日期更改,则更改图像)。因此我实现了一个检查日期
我写了一些函数,并编译成一个dll模块。在我的头文件中如下: #ifndef GET_DATAFEED_FORKDB_H #define GET_DATAFEED_FORKDB_H #include
我是一名优秀的程序员,十分优秀!