目前手头有个查询:

SELECT LPP.learning_project_pupilID, SL.serviceID, MAX(LPPO.start_date), SUM(LPPOT.license_mode_value) totalAssignedLicenses
FROM t_services_licenses SL
INNER JOIN t_pupils_offers_services POS ON POS.service_licenseID = SL.service_licenseID
INNER JOIN j_learning_projects_pupils_offers LPPO ON LPPO.learning_project_pupil_offerID = POS.learning_project_pupil_offerID
INNER JOIN j_learning_projects_pupils LPP ON LPPO.learning_project_pupilID = LPP.learning_project_pupilID
INNER JOIN j_learning_projects_pupils_offers_tracking LPPOT ON LPPOT.pupil_offer_serviceID = POS.pupil_offer_serviceID
INNER JOIN t_filters_items FI ON FI.itemID = LPP.learning_project_pupilID_for_filter_join
WHERE FI.filterID = '4dce2235-aafd-4ba2-b248-c137ad6ce8ca'
AND SL.serviceID IN ('OnlineConversationClasses', 'TwentyFourSeven')
GROUP BY LPP.learning_project_pupilID, SL.serviceID

查询非常慢,需要耗时半个多小时之多。

下面是表的一些详细信息:

t_filters_items表:

j_learning_projects_pupils_offers_tracking表:

j_learning_projects_pupils表:

j_learning_projects_pupils_offers表:

t_pupils_offers_services表:

t_services_licenses表:

执行计划如下:

sql脚本如下:

DROP TABLE IF EXISTS t_services_licenses;
CREATE TABLE t_services_licenses (
service_licenseID varchar(36) NOT NULL,
serviceID varchar(36) NOT NULL,
disciplineID varchar(36) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
serial_key varchar(50) DEFAULT NULL,
deleted tinyint(3) unsigned NOT NULL DEFAULT '',
PRIMARY KEY (service_licenseID),
KEY FK_t_services_licenses_serviceID (serviceID),
KEY IDX_disciplineID (disciplineID),
KEY IDX_deleted (deleted),
CONSTRAINT FK_t_services_licenses_serviceID FOREIGN KEY (serviceID) REFERENCES p_services (serviceID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS t_pupils_offers_services;
CREATE TABLE t_pupils_offers_services (
pupil_offer_serviceID varchar(36) NOT NULL,
learning_project_pupil_offerID varchar(36) NOT NULL,
service_licenseID varchar(36) NOT NULL,
triggered_pupil_offer_serviceID varchar(36) DEFAULT NULL,
triggered_right_of_use_typeID int(10) unsigned DEFAULT NULL,
triggered_right_of_use_value bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (pupil_offer_serviceID),
KEY FK_t_pupils_offers_services_offer_serviceID (service_licenseID),
KEY IDX_ID_SERVICE (learning_project_pupil_offerID,service_licenseID),
CONSTRAINT FK_t_pupils_offers_services_lppoID FOREIGN KEY (learning_project_pupil_offerID) REFERENCES j_learning_projects_pupils_offers (learning_project_pupil_offerID) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FK_t_pupils_offers_services_slID FOREIGN KEY (service_licenseID) REFERENCES t_services_licenses (service_licenseID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS j_learning_projects_pupils_offers;
CREATE TABLE j_learning_projects_pupils_offers (
learning_project_pupil_offerID varchar(36) NOT NULL,
learning_project_pupilID bigint(20) unsigned NOT NULL,
offerID varchar(36) NOT NULL,
start_date datetime NOT NULL,
end_date datetime NOT NULL,
deleted tinyint(3) unsigned NOT NULL DEFAULT '',
interruption_count int(10) unsigned NOT NULL DEFAULT '',
PRIMARY KEY (learning_project_pupil_offerID),
KEY FK_j_learning_projects_pupils_offers_projID (learning_project_pupilID),
KEY FK_j_learning_projects_pupils_offers_offerID (offerID),
KEY IDX_start_date (start_date) USING BTREE,
KEY IDX_end_date (end_date) USING BTREE,
KEY IDX_deleted (deleted),
CONSTRAINT FK_LPPO_LP FOREIGN KEY (learning_project_pupilID) REFERENCES j_learning_projects_pupils (learning_project_pupilID) ON DELETE CASCADE,
CONSTRAINT FK_LPPO_O FOREIGN KEY (offerID) REFERENCES t_offers (offerID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS j_learning_projects_pupils;
CREATE TABLE j_learning_projects_pupils (
learning_project_pupilID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_actorID varchar(36) NOT NULL,
active tinyint(3) unsigned DEFAULT '' COMMENT '',
disciplineID varchar(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
deleted tinyint(3) unsigned NOT NULL DEFAULT '',
active_work_reminder tinyint(3) unsigned NOT NULL DEFAULT '',
enable_change_of_reminder_settings tinyint(3) unsigned NOT NULL DEFAULT '',
enable_objective_redefinition tinyint(3) unsigned NOT NULL DEFAULT '',
enable_sequence_removing tinyint(3) unsigned NOT NULL DEFAULT '',
send_detailed_report tinyint(3) unsigned NOT NULL DEFAULT '',
send_learning_path tinyint(3) unsigned NOT NULL DEFAULT '',
send_test_result tinyint(3) unsigned NOT NULL DEFAULT '',
weekly_availability_time bigint(20) unsigned NOT NULL DEFAULT '',
working_reminder_periodicityID tinyint(3) unsigned NOT NULL,
working_reminder_periodicity_value bigint(20) unsigned NOT NULL DEFAULT '',
registration_date datetime NOT NULL,
current_free_mode_learning_levelID bigint(20) unsigned DEFAULT NULL,
enable_change_of_difficulty_settings tinyint(3) unsigned NOT NULL DEFAULT '',
was_activated tinyint(3) unsigned NOT NULL DEFAULT '',
was_connected tinyint(3) unsigned NOT NULL DEFAULT '',
snapshot_running tinyint(3) unsigned NOT NULL DEFAULT '',
visible tinyint(3) unsigned NOT NULL DEFAULT '',
tempID varchar(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
learning_project_pupilID_for_filter_join varchar(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
objectives_expected_time_on_formation smallint(5) unsigned NOT NULL DEFAULT '',
objectives_expected_time_enabled tinyint(3) unsigned NOT NULL DEFAULT '',
cecr_level tinyint(3) unsigned NOT NULL DEFAULT '',
enable_show_popup_phone_lesson_and_live_tutoring TINYINT(3) UNSIGNED NOT NULL DEFAULT '',
PRIMARY KEY (learning_project_pupilID),
KEY user_actorID (user_actorID),
KEY FK_j_learning_projects_pupils_level (current_free_mode_learning_levelID),
KEY IDX_statuses (was_activated,was_connected,deleted,active),
KEY IDX_LPP_TEMPID (tempID),
KEY IDX_LPP_TEMPFILTERID (learning_project_pupilID_for_filter_join),
KEY IDX_DAVA (deleted,active,visible,active_work_reminder),
KEY IDX_discipline_v (disciplineID,visible) USING BTREE,
CONSTRAINT FK_j_learning_projects_pupils_discipline FOREIGN KEY (disciplineID) REFERENCES p_disciplines (disciplineID),
CONSTRAINT FK_j_learning_projects_pupils_j_users_actors FOREIGN KEY (user_actorID) REFERENCES j_users_actors (user_actorID),
CONSTRAINT FK_j_learning_projects_pupils_level FOREIGN KEY (current_free_mode_learning_levelID) REFERENCES p_learning_levels (learning_levelID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS j_learning_projects_pupils_offers_tracking;
CREATE TABLE j_learning_projects_pupils_offers_tracking (
learning_project_pupil_offer_trackingID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
pupil_offer_serviceID varchar(36) NOT NULL,
license_mode_typeID int(10) unsigned NOT NULL,
license_mode_value bigint(20) unsigned NOT NULL DEFAULT '',
effective_consumption_value bigint(20) unsigned NOT NULL DEFAULT '',
PRIMARY KEY (learning_project_pupil_offer_trackingID),
KEY FK_j_learning_projects_pupils_offers_tracking_posID (pupil_offer_serviceID),
CONSTRAINT FK_j_learning_projects_pupils_offers_tracking_posID FOREIGN KEY (pupil_offer_serviceID) REFERENCES t_pupils_offers_services (pupil_offer_serviceID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS t_filters_items;
CREATE TABLE t_filters_items (
filterID varchar(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
itemID varchar(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
row_order bigint(20) unsigned NOT NULL DEFAULT '',
selected tinyint(3) unsigned NOT NULL DEFAULT '',
PRIMARY KEY (filterID,itemID),
CONSTRAINT FK_t_filters_items_ID FOREIGN KEY (filterID) REFERENCES t_filters (filterID) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

MYSQL查询优化的更多相关文章

  1. Atitit Mysql查询优化器 存取类型 范围存取类型 索引存取类型 AND or的分析

    Atitit Mysql查询优化器 存取类型 范围存取类型 索引存取类型 AND or的分析     Atitit Mysql查询优化器 存取类型 范围存取类型 索引存取类型 AND or的分析1 存 ...

  2. MySQL查询优化之explain的深入解析

    在分析查询性能时,考虑EXPLAIN关键字同样很管用.EXPLAIN关键字一般放在SELECT查询语句的前面,用于描述MySQL如何执行查询操作.以及MySQL成功返回结果集需要执行的行数.expla ...

  3. 1025WHERE执行顺序以及MySQL查询优化器

    转自http://blog.csdn.net/zhanyan_x/article/details/25294539 -- WHERE执行顺序-- 过滤比较多的放在前面,然后更加容易匹配,从左到右进行执 ...

  4. MySQL查询优化:查询慢原因和解决技巧

    在开发的朋友特别是和mysql有接触的朋友会碰到有时mysql查询很慢,当然我指的是大数据量百万千万级了,不是几十条了,下面我们来看看解决查询慢的办法. MySQL查询优化:查询慢原因和解决方法 会经 ...

  5. mysql查询优化器为什么可能会选择错误的执行计划

    有可能导致mysql优化器选择错误的执行计划的原因如下: A:统计信息不准确,mysql依赖存储引擎为其提供的统计信息来评估成本,然而有的存储引擎提供的信息是准确的,有的引擎提供的可能就偏差很大,如: ...

  6. Mysql查询优化器

    Mysql查询优化器 本文的目的主要是通过告诉大家,查询优化器为我们做了那些工作,我们怎么做,才能使查询优化器对我们的sql进行优化,以及启示我们sql语句怎么写,才能更有效率.那么到底mysql到底 ...

  7. MySQL查询优化 (一)

    以下的文章主要讲述的是MySQL查询优化的5个十分好用方法,熟悉SQL语句的人都清楚,如果要对一个任务进行操作的话,SQL语句可以有很多种相关写法,但是不同的写法查询的性能可能会有天壤之别. 本文列举 ...

  8. MySQL查询优化:连接查询排序limit

    MySQL查询优化:连接查询排序limit(join.order by.limit语句) 2013-02-27      个评论       收藏    我要投稿   MySQL查询优化:连接查询排序 ...

  9. MySQL查询优化之explain

    在分析查询性能时,考虑EXPLAIN关键字同样很管用.EXPLAIN关键字一般放在SELECT查询语句的前面,用于描述MySQL如何执行查询操作.以及MySQL成功返回结果集需要执行的行数.expla ...

  10. Mysql查询优化器浅析

    --Mysql查询优化器浅析 -----------------------------2014/06/11 1 定义    Mysql查询优化器的工作是为查询语句选择合适的执行路径.查询优化器的代码 ...

随机推荐

  1. 什么是Java实例初始化块

    在本篇文章,我将会使用一个例子展示什么是实例变量初始化块,实例初始化块和静态初始化块,然后说明在Java中实例初始化块是如何工作的. 执行顺序 查看下面的代码,你知道哪个先执行吗? package s ...

  2. ThreadLocal源码分析

    1.概述 ThreadLocal,可以理解为线程的局部变量,作用就是为每一个使用该变量的线程都提供一个变量值的副本,每一个线程都可以独立地改变自己的副本,而不会和其它线程的副本冲突. ThreadLo ...

  3. pom.xml 样例

    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven ...

  4. Java NIO 基础

    Java在JDK1.4中引入了 java.nio 类库,为Java进军后端Server和中间件开发打开了方便之门. 一般而言,这里的 nio 代表的是 New I/O,但是从实质上来说,我们可以将其理 ...

  5. Java api 入门教程 之 JAVA的IO处理

    IO是输入和输出的简称,在实际的使用时,输入和输出是有方向的.就像现实中两个人之间借钱一样,例如A借钱给B,相对于A来说是借出,而相对于B来说则是借入.所以在程序中提到输入和输出时,也需要区分清楚是相 ...

  6. Linux磁盘管理之磁盘结构、概念、原理01

    一.磁盘的分类 磁盘主要有IDE.SATA.SCSI.IDE是比较老的硬盘,数据速度比较慢:SATA是现在用的比较多的,台式机.笔记本大多都用的SATA硬盘:SCSI硬盘速度最快,但是价格相对较高. ...

  7. (转)Yii的组件机制之一:组件基础类CComponent分析

    Yii的组件机制 组件机制,是Yii整个体系的思想精髓,在使用Yii之前,最应该先了解其组件机制,如果不了解这个机制,那么阅读Yii源代码会非常吃力.组件机制给Yii框架赋予了无穷的灵活性和可扩展性, ...

  8. RAM,SRAM,DRAM,SDRAM,DDR RAM,ROM,PROM,EPROM,EEPROM,NAND FLASH,NOR FLASH的区别

    RAM:由字面意思就可以理解,SDRAM SRAM DRAM(下面蓝色字体的这几种)都可以统称RAM,random access memory(随机存取存储器)的缩写,下面是51hei.com为大家整 ...

  9. 理解 OpenStack Swift (3):监控和一些影响性能的因素 [Monitoring and Performance]

    本系列文章着重学习和研究OpenStack Swift,包括环境搭建.原理.架构.监控和性能等. (1)OpenStack + 三节点Swift 集群+ HAProxy + UCARP 安装和配置 ( ...

  10. [转]jqGrid 属性、事件全集

    本文转自:http://blog.csdn.net/rosanu_blog/article/details/8334070 以下是jqGrid 最常用的属性和事件,经过一段时间的整理,终于弄的差不多了 ...