我正在使用此查询来获取记录
SELECT *
FROM (`content` as c)
LEFT JOIN `content_assets` AS ca ON `ca`.`contentid` = `c`.`id`
LEFT JOIN `assets` AS a ON `a`.`act_id` = `ca`.`actorid`
INNER JOIN `content_gens` AS cg ON `cg`.`contentid` = `c`.`id`
INNER JOIN `gens` AS g ON `cg`.`genid` = `g`.`gen_id`
LEFT JOIN `live_data` AS l ON `l`.`contentid` = `c`.`id`
LEFT JOIN `live_type` AS lt ON `lt`.`lt_id` = `l`.`live_type`
LEFT JOIN `returned` AS r ON `r`.`content_id` = `c`.`id`
WHERE `c`.`id` = '14175'
我的 live_data 表是导致此加载时间的主要问题,它包含大约 200k 条记录,并且需要 20-40 秒来加载页面。如果我不加入那张桌子,一切都很好。我目前正在使用基于文件的缓存来缓存上述查询的结果,但我想知道是否可以进一步优化上述查询。
编辑:我的表索引可以在这里看到。
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 08, 2013 at 11:07 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `database`
--
-- --------------------------------------------------------
--
-- Table structure for table `assets`
--
CREATE TABLE IF NOT EXISTS `assets` (
`act_id` int(11) NOT NULL AUTO_INCREMENT,
......
PRIMARY KEY (`act_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8726 ;
-- --------------------------------------------------------
--
-- Table structure for table `content`
--
CREATE TABLE IF NOT EXISTS `content` (
`id` int(11) NOT NULL AUTO_INCREMENT,
.........
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14267 ;
-- --------------------------------------------------------
--
-- Table structure for table `content_asset`
--
CREATE TABLE IF NOT EXISTS `content_asset` (
`contentid` int(11) NOT NULL,
`actorid` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `content_gener`
--
CREATE TABLE IF NOT EXISTS `content_gener` (
`contentid` int(11) NOT NULL,
`genid` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `gens`
--
CREATE TABLE IF NOT EXISTS `gens` (
`gen_id` int(11) NOT NULL AUTO_INCREMENT,
......
PRIMARY KEY (`gen_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=65 ;
-- --------------------------------------------------------
--
-- Table structure for table `live_data`
--
CREATE TABLE IF NOT EXISTS `live_data` (
`link_id` int(11) NOT NULL AUTO_INCREMENT,
.....
PRIMARY KEY (`link_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=214014 ;
-- --------------------------------------------------------
--
-- Table structure for table `live_type`
--
CREATE TABLE IF NOT EXISTS `live_type` (
`lt_id` int(11) NOT NULL AUTO_INCREMENT,
....
PRIMARY KEY (`lt_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
-- --------------------------------------------------------
--
-- Table structure for table `returned`
--
CREATE TABLE IF NOT EXISTS `returned` (
`r_id` int(11) NOT NULL AUTO_INCREMENT,
....
PRIMARY KEY (`r_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
并解释查询结果:
谢谢你的帮助。