- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我们的一个网站上有一个非常慢的搜索引擎。我打开了慢速查询日志并记录了所有超过 10 秒的查询。仅记录来自该搜索引擎的查询。这是日志的一个示例:
# Time: 120801 9:21:42
# User@Host: ********** @ localhost []
# Query_time: 22.156250 Lock_time: 0.000000 Rows_sent: 33 Rows_examined: 3385401
SET timestamp=1343805702;
SELECT *, IF(InSection OR InBranche, 1, 0) AS SorteerKolom FROM(SELECT DISTINCT Plant, Email, Nicename, Displayname, JobTitle, Department, Initials, Lastname, LastnameForSort,
search_people.ForeignId, IsVennoot,
(Zoekwoorden LIKE '%statutair%') AS SearchTerm,
(Displayname LIKE '%statutair%') AS ByName,
0 AS InSection, 0 AS InBranche, 1 AS ShowAll,
(SELECT COUNT(*) FROM search_hasarticles WHERE UserId = search_people.ForeignId) > 0 AS HasWritten
FROM search_people
LEFT JOIN search_people_branches ON search_people.ForeignId = search_people_branches.UserId
LEFT JOIN search_people_specialismen ON search_people.ForeignId = search_people_specialismen.UserId
LEFT JOIN wp_usermeta AS wpu ON (wpu.user_id = search_people.ForeignId)
WHERE
(
Firstname LIKE '%statutair%'
OR Lastname LIKE '%statutair%'
AND Displayname LIKE '%statutair%'
OR Email LIKE '%statutair%'
OR Address LIKE '%statutair%'
OR Initials LIKE '%statutair%'
OR Location LIKE '%statutair%'
OR Givenname LIKE '%statutair%'
OR Nickname LIKE '%statutair%'
OR JobTitle LIKE '%statutair%'
OR Login LIKE '%statutair%'
OR Title LIKE '%statutair%'
OR Phone LIKE '%statutair%'
OR Fax LIKE '%statutair%'
OR Plant LIKE '%statutair%'
OR Displayname LIKE '%statutair%'
OR Zoekwoorden LIKE '%statutair%'
)
AND (1=1) AND search_people.IsHidden = 0 AND search_people.Activated = 1 UNION SELECT DISTINCT Plant, Email, Nicename, Displayname, JobTitle, Department, Initials, Lastname, LastnameForSort,
search_people.ForeignId, IsVennoot, 0 AS SearchTerm, 0 AS ByName, 0 AS InSection, 1 AS InBranche, 1 AS ShowAll,
(SELECT COUNT(*) FROM search_hasarticles WHERE UserId = search_people.ForeignId) > 0 AS HasWritten
FROM search_people
LEFT JOIN search_people_branches ON search_people.ForeignId = search_people_branches.UserId
LEFT JOIN search_branches ON search_branches.ForeignId = search_people_branches.BrancheId
LEFT JOIN search_people_specialismen ON search_people.ForeignId = search_people_specialismen.UserId
WHERE Name LIKE '%statutair%' AND (1=1) AND search_people.IsHidden = 0 AND search_people.Activated = 1 UNION SELECT DISTINCT Plant, Email, Nicename, Displayname, JobTitle, Department, Initials, Lastname, LastnameForSort, search_people.ForeignId, IsVennoot, 0 AS SearchTerm, 0 AS ByName, 1 AS InSection, 0 AS InBranche, 1 AS ShowAll, (SELECT COUNT(*) FROM search_hasarticles WHERE UserId = search_people.ForeignId) > 0 AS HasWritten FROM search_people LEFT JOIN search_people_specialismen ON search_people.ForeignId=search_people_specialismen.UserId LEFT JOIN search_specialties ON search_specialties.ForeignId=search_people_specialismen.SpecialismeId LEFT JOIN search_people_branches ON search_people.ForeignId=search_people_branches.UserId WHERE (Name LIKE '%statutair%' OR SearchTerms LIKE '%statutair%') AND (1=1) AND search_people.IsHidden = 0 AND search_people.Activated = 1 UNION SELECT DISTINCT Plant, Email, Nicename, Displayname, JobTitle, Department, Initials, Lastname, LastnameForSort, search_people.ForeignId, IsVennoot, 0 AS SearchTerm, 0 AS ByName, 0 AS InSection, 0 AS InBranche, 0 AS ShowAll, 1 AS HasWritten FROM search_posts LEFT JOIN search_posts_branches ON search_posts.ForeignId=search_posts_branches.PostId LEFT JOIN search_branches ON search_posts_branches.BrancheId=search_branches.ForeignId LEFT JOIN search_people_specialismen ON search_posts.PostAuthor=search_people_specialismen.UserId LEFT JOIN search_specialties ON search_people_specialismen.SpecialismeId=search_specialties.ForeignId INNER JOIN search_people ON search_people.ForeignId=search_posts.PostAuthor WHERE (PostTitle LIKE '%statutair%' OR PostContent LIKE '%statutair%' OR search_branches.Name LIKE '%statutair%' OR search_specialties.Name LIKE '%statutair%') AND PostStatus='publish' AND PostType='post' AND (1=1) AND search_people.IsHidden = 0 AND search_people.Activated = 1) AS search_results ORDER BY SearchTerm DESC, ByName DESC, SorteerKolom DESC, IsVennoot DESC, InSection DESC, InBranche DESC, HasWritten DESC, LastnameForSort ASC, Initials ASC;
如您所见,执行查询大约需要 22 秒,如果直接在 MySQL 中执行相同的查询,大约需要 4 秒。
我对同一个查询做了 EXPLAIN,结果如下:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 33 Using filesort
2 DERIVED search_people ALL NULL NULL NULL NULL 323 Using where; Using temporary
2 DERIVED search_people_branches ALL NULL NULL NULL NULL 2013 Distinct
2 DERIVED search_people_specialismen ALL NULL NULL NULL NULL 1013 Distinct
2 DERIVED wpu ref user_id user_id 8 wordpress.search_people.ForeignId 84 Using index; Distinct
3 DEPENDENT SUBQUERY search_hasarticles ALL NULL NULL NULL NULL 101 Using where
4 UNION search_branches ALL NULL NULL NULL NULL 19 Using where; Using temporary
4 UNION search_people ALL NULL NULL NULL NULL 323 Using where; Using join buffer
4 UNION search_people_specialismen ALL NULL NULL NULL NULL 1013 Distinct
4 UNION search_people_branches ALL NULL NULL NULL NULL 2013 Using where; Distinct; Using join buffer
5 DEPENDENT SUBQUERY search_hasarticles ALL NULL NULL NULL NULL 101 Using where
6 UNION search_specialties ALL NULL NULL NULL NULL 73 Using where; Using temporary
6 UNION search_people ALL NULL NULL NULL NULL 323 Using where; Using join buffer
6 UNION search_people_specialismen ALL NULL NULL NULL NULL 1013 Using where; Distinct; Using join buffer
6 UNION search_people_branches ALL NULL NULL NULL NULL 2013 Distinct
7 DEPENDENT SUBQUERY search_hasarticles ALL NULL NULL NULL NULL 101 Using where
8 UNION search_posts ALL NULL NULL NULL NULL 15860 Using where; Using temporary
8 UNION search_posts_branches ALL NULL NULL NULL NULL 149 Distinct
8 UNION search_branches ALL NULL NULL NULL NULL 19 Distinct
8 UNION search_people_specialismen ALL NULL NULL NULL NULL 1013 Distinct
8 UNION search_specialties ALL NULL NULL NULL NULL 73 Using where; Distinct
8 UNION search_people ALL NULL NULL NULL NULL 323 Using where; Distinct; Using join buffer
UNION RESULT <union2,4,6,8> ALL NULL NULL NULL NULL NULL
谁能解释为什么同样的查询在我的网站上比直接在 MySQL 中慢得多?或者更重要的是,有没有办法让这个网站上的查询更快?
如果您需要更多信息来进行故障排除,请大声说出来,我会尽力提供。
非常感谢,一月
这是查询的 PROFILE:
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000431 |
| Opening tables | 0.002004 |
| System lock | 0.000012 |
| Table lock | 0.000502 |
| optimizing | 0.000033 |
| statistics | 0.000042 |
| preparing | 0.000034 |
| Creating tmp table | 0.000085 |
| executing | 0.000004 |
| Copying to tmp table | 0.001957 |
| Sending data | 0.000006 |
| optimizing | 0.000025 |
| statistics | 0.000027 |
| preparing | 0.000041 |
| Creating tmp table | 0.000114 |
| executing | 0.000001 |
| Copying to tmp table | 0.000058 |
| Sending data | 0.000004 |
| optimizing | 0.000021 |
| statistics | 0.000027 |
| preparing | 0.000037 |
| Creating tmp table | 0.000095 |
| executing | 0.000003 |
| Copying to tmp table | 0.007376 |
| optimizing | 0.000013 |
| statistics | 0.000017 |
| preparing | 0.000011 |
| executing | 0.000005 |
| Sending data | 0.001248 |
| executing | 0.000014 |
| Sending data | 0.001894 |
| executing | 0.000007 |
| Sending data | 0.003249 |
| executing | 0.000004 |
| Sending data | 0.001487 |
| executing | 0.000001 |
| Sending data | 0.000433 |
| executing | 0.000001 |
| Sending data | 0.012100 |
| executing | 0.000006 |
| Sending data | 0.000713 |
| executing | 0.000002 |
| Sending data | 0.000681 |
| executing | 0.000001 |
| Sending data | 0.015382 |
| executing | 0.000005 |
| Sending data | 0.001048 |
| executing | 0.000002 |
| Sending data | 0.000916 |
| executing | 0.000004 |
| Sending data | 0.000421 |
| executing | 0.000001 |
| Sending data | 0.000561 |
| executing | 0.000001 |
| Sending data | 0.005126 |
| executing | 0.000008 |
| Sending data | 0.014534 |
| executing | 0.000004 |
| Sending data | 0.001666 |
| executing | 0.000006 |
| Sending data | 0.001641 |
| Sending data | 0.000203 |
| optimizing | 0.000045 |
| statistics | 0.000050 |
| preparing | 0.000049 |
| Creating tmp table | 0.000182 |
| executing | 0.000002 |
| Copying to tmp table | 5.101209 |
| Sending data | 0.000226 |
| optimizing | 0.000007 |
| statistics | 0.000008 |
| preparing | 0.000007 |
| executing | 0.000001 |
| Sending data | 0.000217 |
| removing tmp table | 0.000044 |
| Sending data | 0.000007 |
| removing tmp table | 0.000012 |
| Sending data | 0.000017 |
| removing tmp table | 0.000011 |
| Sending data | 0.000005 |
| removing tmp table | 0.000033 |
| Sending data | 0.000008 |
| removing tmp table | 0.000030 |
| Sending data | 0.000009 |
| init | 0.000044 |
| optimizing | 0.000005 |
| statistics | 0.000004 |
| preparing | 0.000007 |
| executing | 0.000002 |
| Sorting result | 0.000074 |
| Sending data | 0.000164 |
| end | 0.000003 |
| query end | 0.000005 |
| freeing items | 0.000210 |
| removing tmp table | 0.000061 |
| closing tables | 0.000051 |
| logging slow query | 0.000003 |
| cleaning up | 0.000026 |
+----------------------+----------+
最佳答案
我看到很多不可索引的条件,例如 Firstname LIKE '%statutair%'
。一种可能是 MySQL 实际上正在使用它的 results cache ,而 PHP 无法利用结果缓存。这可能会发生,例如,如果您将 PDO 与 ATTR_EMULATE_PREPARES option disabled 一起使用.
要找出答案,请在从 MySQL 中进行测试时添加 SQL_NO_CACHE 子句,如下所示:
SELECT SQL_NO_CACHE id, name FROM customer;
关于php - 在 MySQL 中查询速度快,但在 PHP 中查询速度慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756932/
我的应用程序中有以下查询: SELECT a.*, f.* FROM flights_database f JOIN airports a ON f.airport = a.airportNameCl
我们在使用 MySQL(以及 MariaDB)时遇到了一个奇怪的问题。一个简单的数据库,有 2 个表(InnoDB 引擎),都包含(以及其他一些)3 或 4 个带有 XML 数据的文本列。大小为 1-
我在 MySQL 上的执行路径上遇到问题,导致查询缓慢且不一致。这是一个全新的现象。我们还有其他具有完全相同(好吧,尽可能接近)设置的表,这很好,但出于某种原因,现在创建新表会遇到这个缓慢/不一致的问
我使用 Eclipse Marketplace 的下载速度始终非常慢(现在从 http://download.eclipse.org 开始,下载速度为 3 MB/s,下载速度为 25 kB/s),这使
我正在开发一个 Qt Creator 项目,其中包含大量头文件(点云库、Boost 等)。例如。 Boost 有大约 9000 个头文件。现在看来,包含的数量确实减慢了 IDE。代码完成很慢,大约。
我在一个项目中使用 document.elementFromPoint,它看起来很慢。 100,000 次迭代需要 7051 毫秒。 document.getElementsByTagName("*"
我有一个 tableView ,每行有四个图表,大约 20 行。当我尝试滚动表格时,我将删除现有图表并为每一行构建新图表。 此操作使 TableView 的滚动非常慢。任何使滚动速度更快以及加载新图表
我有一个如下所示的数据框: date,time,metric_x 2016-02-27,00:00:28.0000000,31 2016-02-27,00:01:19.0000000,40 2016-
TLDR:我的微调器瞬间显示了错误的颜色。 我的微调器有问题。每当我运行应用程序时,如果 Activity 没有缓存在内存中,它有时会滞后。在我可以将其设置为正确的颜色之前,文本是默认颜色(如黑色)。
我在使用 SELECT COUNT(*) 对大型表进行 SQLite 时遇到性能问题。 由于我还没有收到可用的答案并且我做了一些进一步的测试,所以我编辑了我的问题以纳入我的新发现。 我有 2 个表:
当音频因加载数据不足(速度慢)而暂停时,我可以使用什么事件? 就像: $audio.on('suspendToLoading',function(){ alert('loading...');
这是我的 MATLAB 程序的分析模拟运行结果。我需要运行此模拟数十万次(约 100,000 次)。 因此我需要一种更快的方法来读取 Excel 文件。 规范:Excel 文件由 10000x2 个单
每当与数据透视表交互时,Excel 都非常慢,这让我感到非常困难。添加/删除字段、更改过滤器或切片器,所有这些都需要 Excel 卡住几分钟才能响应。 看来生成的 MDX 效率极低。我可以理解他们必须
我正在使用 Entity Framework 来检索大型数据集。 数据集有parent/child关系,我需要和parent同时带回child信息。 我发现 EF 最初发送一个查询以获取父对象列表,然
我有一个使用 gridview 的应用程序,它非常慢。 添加 Trace=true 后对于页面,我追踪了时间花费的地方:在 GridView 上调用 BindData() 时。 GridView连接到
我编写了一个小代码来使用 QtCreator 测试 QGraphicsView 的功能。 代码非常简单,只是创建了一个继承自 QGraphicsView 的类,上面有一个 QGraphicsScene
后期以补充作品的形式自动加入成员(member)。数据库速度较慢。有没有办法加快这个速度?用户无所谓..除了自动补码之外如何停止写?(自动补码;城市输入。成员(member)表格位于。) 注册.php
我有一个文件 (insert.sql),其中有 250k 行,没有键,没有索引: INSERT `project_383`.`entity_metrics_build_1` VALUES ('d402
我最近开发了一个应用程序(java 8、spring-boot、hibernate、maven),它通过 REST API 公开数据库。我遇到的问题是数据库调用很慢(3000 毫秒以上),只是为了获取
我正在尝试在 Canvas 上使用旋转,我现在有了它,因此每个对象都有自己的旋转。如果没有它们旋转,我可以在一台非常低端的计算机上在屏幕上显示大约 400 个对象,在一台正常库存的计算机上显示近 20
我是一名优秀的程序员,十分优秀!