数百万条记录的查询优化

时间:2016-09-28 18:48:58

标签: php mysql database codeigniter

我尝试优化查询,以便通过以下查询获得更好的响应时间

SELECT * FROM `videos` 
WHERE MATCH (name,tags) 
AGAINST ('toto' IN BOOLEAN MODE) 
ORDER BY `id` DESC, `id` DESC  LIMIT 8 

数据库结构

Navicat MySQL Data Transfer

Source Server         : host
Source Server Version : 50550
Source Host           : 137.74.231.89:3306
Source Database       : megaboss

Target Server Type    : MYSQL
Target Server Version : 50550
File Encoding         : 65001

Date: 2016-09-28 20:43:25
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for videos
-- ----------------------------
DROP TABLE IF EXISTS `videos`;
CREATE TABLE `videos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `name_url` varchar(255) DEFAULT NULL,
  `categories` varchar(255) DEFAULT NULL,
  `embed` tinytext,
  `description` text,
  `tags` varchar(255) DEFAULT NULL,
  `hd` smallint(6) DEFAULT '0',
  `views` int(11) NOT NULL DEFAULT '0',
  `likes` int(11) DEFAULT '0',
  `dislikes` int(11) DEFAULT '0',
  `cover` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`,`name`),
  FULLTEXT KEY `categories` (`categories`),
  FULLTEXT KEY `name` (`name`),
  FULLTEXT KEY `tags` (`tags`)
) ENGINE=MyISAM AUTO_INCREMENT=1273355 DEFAULT CHARSET=latin1;

记录计数

Loading Time: Base Classes      0.0069
Controller Execution Time ( Engine / Search )   1.3354
Total Execution Time    1.3430

没有记录计数

Loading Time: Base Classes      0.0063
Controller Execution Time ( Engine / Search )   0.0147
Total Execution Time    0.0216

当我计算结果数量(对于我的分页系统)时,这是非常慢的

$query->get('videos')->num_rows();  

任何解决方案?

0 个答案:

没有答案