- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到一个非常大的 MYSQL 查询的问题,该查询处理显示记录的时间超过 10 分钟。
查询如下所示:
SELECT SQL_CALC_FOUND_ROWS * FROM (
SELECT 't-0' as typo, sh_inquiry.id as ref, sh_inquiry.pid as pid, partner, sh_inquiry.order, if(p_status IS NULL OR p_status = 0,'not paid','paid') as payment, p_voucher, country, city, delivery_date, sh_inquiry.amount as c_amount, currency as c_currency, NULL as s_amount, NULL as s_currency, IF(confirmed=0,if(delivered=0,"not confirmed","delivered"),if(delivered=0,"confirmed","delivered")) as conf
FROM sh_inquiry
LEFT JOIN sh_orders ON sh_inquiry.id = sh_orders.i_id
LEFT JOIN sh_partners ON sh_partners.pid = sh_inquiry.pid
LEFT JOIN sh_currency ON sh_currency.id = sh_inquiry.curr_id
LEFT JOIN sh_country ON sh_country.id = sh_inquiry.cid
LEFT JOIN sh_debts ON sh_inquiry.id = sh_debts.i_id
WHERE sh_inquiry.del = 0 AND sh_inquiry.type = 1 AND sh_orders.del = 0
UNION
SELECT 't-1' as typo, sh_orders.i_id as ref, sid as pid, partner, sh_inquiry.order, if(p_status IS NULL OR p_status = 0,'not paid','paid') as payment, p_voucher, country, city, delivery_date, NULL as c_amount, NULL as c_currency, sh_orders.amount as s_amount, currency as s_currency, IF(confirmed=0,if(delivered=0,'not confirmed','delivered'),if(delivered=0,'confirmed','delivered')) as conf FROM sh_orders
LEFT JOIN sh_partners ON sh_partners.pid = sh_orders.sid
LEFT JOIN sh_currency ON sh_currency.id = sh_orders.curr_id
LEFT JOIN sh_inquiry ON sh_inquiry.id = sh_orders.i_id
LEFT JOIN sh_country ON sh_country.id = sh_inquiry.cid
LEFT JOIN sh_debts ON sh_orders.id = sh_debts.o_id
WHERE sh_orders.del = 0 AND sh_inquiry.del = 0
) AS U
ORDER BY typo ASC, delivery_date
asc
LIMIT 0, 10
问题是我使用的 2 个表必须连接到一个表中(这 2 个表非常大),这就是我使用 UNION 语句的原因。我正在 jquery 数据表服务器端页面中显示记录,因此限制显示的记录无济于事。
有人能想出一个关于加速这个查询的想法吗?如果您需要有关数据库结构的更多信息,请询问。
EXPLAIN 语句被触发:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 17630 Using filesort
2 DERIVED sh_orders ALL i_id NULL NULL NULL 8696 Using where
2 DERIVED sh_inquiry eq_ref PRIMARY,id PRIMARY 4 reur3918_sh.sh_orders.i_id 1 Using where
2 DERIVED sh_partners eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_inquiry.pid 1
2 DERIVED sh_currency eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_inquiry.curr_id 1
2 DERIVED sh_country eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_inquiry.cid 1
2 DERIVED sh_debts ALL NULL NULL NULL NULL 18678
3 UNION sh_orders ALL i_id NULL NULL NULL 8696 Using where
3 UNION sh_partners eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_orders.sid 1
3 UNION sh_currency eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_orders.curr_id 1
3 UNION sh_inquiry eq_ref PRIMARY,id PRIMARY 4 reur3918_sh.sh_orders.i_id 1 Using where
3 UNION sh_country eq_ref PRIMARY PRIMARY 4 reur3918_sh.sh_inquiry.cid 1
3 UNION sh_debts ALL NULL NULL NULL NULL 18678
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
对所有 ID 建立索引后,查询大约需要 133 秒..
最佳答案
谢谢大家的想法!实际上,运行 EXPLAIN 语句帮助我找到了没有定义 INDEX 的表。在查询中使用过的所有字段(主要是JOIN ON子句)添加INDEX后,运行时间减少到0.83秒
关于php - 加快 MYSQL LARGE 查询速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24291163/
matplotlibrc 示例文件指出: ## The font.size property is the default font size for text, given in pts. ## 1
在 HTML/CSS 中,可以通过以下方式指定字体大小(已弃用,但所有浏览器都支持): text n 是 {1, 2, 3, 4, 5, 6, 7} 的一个元素。 另一种可能性是: text s 是
我正在编写物理模拟代码,最近我遇到了异常结果。我设法调试了我的程序,错误出在用大整数除以大 double ,形式如下: cout << my_large_double/my_large_int <<
由于“大”是一个相对术语,我想知道“大”的确切含义是什么。更具体地说,我想在数据库中存储从几个字节到 50 个字节的二进制数据,并且想知道是否应该使用 Blob 或其他数据类型。 最佳答案 所有 DB
这是我的代码的想法: 我有一个很大的电子邮件数据 RDD,称为 email。大约 7 亿封电子邮件。它看起来像这样: [['value1','value2','value3','value4'],['
我需要拆分由另一个 Pig 脚本生成的输出部分文件,并生成每个包含 1000 行的组。这些组将发布到网络服务以供进一步处理。数据之间没有关系,所以我无法将数据分组到特定字段。 我如何在 Pig 中执行
它们都有 2vcpu 和 8G 内存。但对于 t2.large,您只能使用单个 vcpu 的 60%,两个 vcpu 平均各使用 30%。即使考虑到“CPU积分”,t2.large似乎也比m4.lar
我正在尝试使用 git svn 克隆一个大型 svn 存储库。 repo 有 100000 次修订。大小约为 9GB(原始文件夹)。 repo 协议(protocol)中的最大文件是 300 MB。
我刚接触 android。在我的教程书中(有点过时)在Eclipse中教学,只是在layout-large目录下编写另一个layout xml文件以适配大屏。 我使用的是android studio,
如果我要升级亚马逊实例,我会创建镜像的快照并从该镜像创建新实例,然后升级该实例。 我的问题与 mongodb 以及从 m1.large 升级到 m3.large 实例的最佳方式有关 - 基本上 m3
这个问题可能需要一些编译器知识才能回答。我目前正在做一个项目,我将在其中创建一个数组,可能是 int[2][veryLargeNumber] 或 int [veryLargeNumber][2] 逻辑
我在使用 mysql 5.5.12 时遇到了 Amazon RDS 的 IO 性能问题。有 2 种实例类型相似且价格接近: 超大数据库实例:15 GB 内存、8 个 ECU(4 个虚拟核心,每个 2
我需要设计一个包含大量字段的网页,每个字段都显示在一行表格中。有几个类别。我希望为每个类别制作一个单独的表格并进行不同的设计。 网页上存在大量表格是否会使速度变慢?哪个更好.. 有 10 个表,每个表
我在my.cnf中添加了如下内容 [mysqld] max_allowed_packet=32M [mysql] max_allowed_packet=32M 而且我还在 JDBC 查询中添加了以下内
我正在为 Nexus 4、Samsung 7.7、Nexus 7、S3 和 Note-2 开发应用程序。我正在为所有这些布局制作一个 apk。除 Nexus 7 和 Samsung 7.7 外,其他一
我有一个包含大约 1000 万行且大小约为 400mb 的文件,我的系统无法处理它。当我尝试使用 gedit 打开文件时,它卡住了。有没有办法处理这么大的数据文件。 最佳答案 使用 gnu(Windo
这个问题已经有答案了: "Integer too large" for a small compile time constant (4 个回答) 已关闭 6 年前。 当我添加整数时,即使我将其加倍,
这个问题已经有答案了: "Integer number too large" error message for 600851475143 (8 个回答) Java long number too l
我们正在开发一个注册系统,但现在由于编译期间出现内存错误而陷入困境。 我们上网查了一下,发现错误信息的原因是.java文件的大小。我们的 EnrollmentSystem 类现在有 10171 行代码
这个问题已经有答案了: How to import large sql file in phpmyadmin (23 个回答) 已关闭 4 年前。 我刚刚在 Digital Ocean 上设置了一个
我是一名优秀的程序员,十分优秀!