- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 SQL 查询,我正在尝试对其进行优化以删除“使用位置;使用临时;使用文件排序”。
这是表格:
CREATE TABLE `special_offers` (
`so_id` int(11) NOT NULL auto_increment,
`so_lid` int(11) NOT NULL,
`so_product_id` int(11) NOT NULL,
`so_bonus_product` int(11) NOT NULL,
`so_reverse_relate` tinyint(1) NOT NULL default '0',
`so_discount_amount` varchar(6) NOT NULL,
`so_start` date NOT NULL default '0000-00-00',
`so_expiry` date NOT NULL default '0000-00-00',
`so_active` tinyint(1) NOT NULL,
`so_archived` tinyint(4) NOT NULL default '0',
`so_added` datetime NOT NULL,
PRIMARY KEY (`so_id`),
KEY `so_archived` (`so_archived`),
KEY `so_active` (`so_active`),
KEY `so_start` (`so_start`),
KEY `so_expiry` (`so_expiry`),
KEY `so_product_id` (`so_product_id`),
KEY `so_bonus_product` (`so_bonus_product`),
KEY `so_lid` (`so_lid`)
) ENGINE=MyISAM AUTO_INCREMENT=65610 DEFAULT CHARSET=latin1
这是查询:
SELECT `so_id` , `so_lid` , `so_bonus_product` , `so_product_id`
FROM `special_offers`
WHERE `so_archived` = '0'
AND `so_active` = '1'
AND (
`so_start` <= CURDATE( )
OR `so_start` = '0000-00-00'
)
AND (
`so_expiry` >= CURDATE( )
OR `so_expiry` = '0000-00-00'
)
GROUP BY `so_lid`
一个解释:
mysql> EXPLAIN SELECT `so_id` , `so_lid` , `so_bonus_product` , `so_product_id` FROM `special_offers` WHERE `so_archived` = '0' AND `so_active` = '1' AND ( `so_start` <= CURDATE( ) OR `so_start` = '0000-00-00' ) AND ( `so_expiry` >= CURDATE( ) OR `so_expiry` = '0000-00-00' ) GROUP BY `so_lid`;
+----+-------------+-------------------+------+------------------------------------------+-------------+---------+-------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------------+------+------------------------------------------+-------------+---------+-------+------+----------------------------------------------+
| 1 | SIMPLE | special_offers | ref | so_archived,so_active,so_start,so_expiry | so_archived | 1 | const | 7684 | Using where; Using temporary; Using filesort |
+----+-------------+-------------------+------+------------------------------------------+-------------+---------+-------+------+----------------------------------------------+
最佳答案
在 (so_archived, so_active, so_lid, so_start, so_end)
上创建复合索引
关于sql - 优化查询以删除 "Using where; Using temporary; Using filesort",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782998/
今天想测试一下PostgreSQL 9.1的一个新特性,就是unlogged table,结果报如下Error,谁能帮帮我? mydb=> CREATE UNLOGGED table testu (a
struct F { private: int* data; public: F( int n ) { data = new int; *dat
我创建了几个中间件类,现在想根据一些真实的 View 来测试它们。由于我的应用程序不包含任何 View 或 url conf 本身,我想知道是否有一种方法可以临时创建 View 和 url 配置,仅用
我正在使用 Spark,我想知道:如何通过对表 A 和 B 执行 sql 查询来创建名为 C 的临时表? sqlContext .read.json(file_name_A) .creat
我最近重新安装了 ubuntu 20.04.3,在做了一些设置后,我现在在运行 apt update 时总是收到以下错误.我一定是不小心删除了某种缓存文件或目录,但我不知道如何诊断或解决这个问题。 任
我的 Magento 版本是 2.2.3。我们使用的是第二代 Google Cloud SQL 实例。 运行索引命令时遇到错误 General error: 1787 Statement violat
此代码用于使用早期的 g++ 版本进行编译,例如5.3.使用 10.2 我得到以下结果(使用编译器选项 -std=c++11) tmp1.cpp: In function ΓÇÿint main(in
有没有办法不使用临时“结果”来编写以下代码? result = func(); if(result == -1) return func2(); else return res
我创建一个临时 NSManagedObject 并将其与主 NSManagedObjectContext 关联。我需要能够将其视为上下文中功能齐全的对象(执行获取请求等),因此无法在没有关联上下文的情
我一直在努力争取在 Azure 中实现角色内的同地缓存(非专用)。 在我的 MVC WebApi 2 项目的 web.config 中: ...
我写了一个类来使用它作为一个方便的 View ,例如基于范围的for s。总的来说,它只是一对带有边界检查的迭代器: template class Range { private: I begin
在运行我的代码(使用 gfortran 编译)时,我收到 Fortran 运行时警告“创建了临时数组”,我想知道是否有更好的方法来解决此警告。 我原来的代码是这样的: allocate(flx_est
经过长时间的研究,我正在写这篇文章,但我真的很难找到解决我问题的最佳方法。 我对 resKit 和 CoreData 都很陌生......无论如何,我正在映射并保存我从 Web 服务接收到的 JSON
我需要在java spring应用程序中实现像临时存储这样的东西。例如,当事件发生时,我放了一个值,但同时这个类正在被另一个监听器类监听,并且一旦需要的值到达此存储,监听器就会调用某些操作。在java
如果你查看MySql临时表的官方文档: http://dev.mysql.com/doc/refman/5.1/en/internal-temporary-tables.html 给出的理由是:
这个问题有点棘手。我正在使用将结果插入 DOM 的第三方库。 示例: $('#puthere').thirdpartyplugin(); 这将调用 thirdpartyplugin 并操作 HTML
这个查询非常简单,我想做的就是获取给定类别中按 last_updated 字段排序的所有文章: SELECT `articles`.* FROM `articles`, `ar
我已经制作了这个 C++ 代码: std::string const & Operand::toString() const { std::ostringstream convert
MySQL 文档说:“您不能在同一个查询中多次引用一个临时表。” 我知道之前有人问过这个问题。但我找不到针对以下内容的具体解决方案。 我正在对临时表进行预选 CREATE TEMPORARY TABL
我对使用 git 比较陌生。 最近我们从 master 分支了 +-10 个功能分支。我们称它们为 A、B、C 等。 我想将这些全部 merge 在一起进行测试。如果我创建一个新分支并 merge 我
我是一名优秀的程序员,十分优秀!