Mysql 如何使用大量这样的连接优化SELECT查询?
我有一个视图,它被定义为一个SELECT波纹管。有没有办法优化这个?现在非常非常慢Mysql 如何使用大量这样的连接优化SELECT查询?,mysql,sql,query-optimization,Mysql,Sql,Query Optimization,我有一个视图,它被定义为一个SELECT波纹管。有没有办法优化这个?现在非常非常慢 SELECT -- lots of columns FROM (((((((((((`table1` `t1` LEFT JOIN `table2` `t2` ON(( `t2`.`userid` = `t1`.`userid` ))) LEFT JOIN `table3` `t3`
SELECT
-- lots of columns
FROM (((((((((((`table1` `t1`
LEFT JOIN `table2` `t2`
ON(( `t2`.`userid` = `t1`.`userid` )))
LEFT JOIN `table3` `t3`
ON(( `t1`.`orderid` = `t3`.`orderid` )))
LEFT JOIN `table4` `t4`
ON(( `t4`.`orderitemlicenseid` =
`t3`.`orderitemlicenseid` )))
LEFT JOIN `table5` `t5`
ON(( `t1`.`orderid` = `t5`.`orderid` )))
LEFT JOIN `table6` `t6`
ON(( `t5`.`transactionid` = `t6`.`transactionid` )))
LEFT JOIN `table7` `t7`
ON(( `t7`.`transactionid` = `t5`.`transactionid` )))
LEFT JOIN `table8` `t8`
ON(( `t8`.`voucherid` = `t7`.`voucherid` )))
LEFT JOIN `table9` `t9`
ON(( `t8`.`voucherid` = `t9`.`voucherid` )))
LEFT JOIN `table10` `t10`
ON(( ( `t10`.`vouchergroupid` = `t9`.`vouchergroupid` )
AND ( `t2`.`territoryid` = `t10`.`territoryid` ) )))
LEFT JOIN `table11` `t11`
ON(( `t11`.`voucherid` = `t8`.`voucherid` )))
LEFT JOIN `table12` `t12`
ON(( `t12`.`orderid` = `t1`.`orderid` )))
GROUP BY `t5`.`transactionid`
EXPLAIN将返回如下内容:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 11571
2 DERIVED t1 ALL NULL NULL NULL NULL 11737 "Using temporary; Using filesort"
2 DERIVED t2 eq_ref PRIMARY PRIMARY 4 database.o.userID 1
2 DERIVED t3 ref fk_tblOrderItemLicenses_tblOrders1 fk_tblOrderItemLicenses_tblOrders1 4 database.o.orderID 1
2 DERIVED t4 ref fk_tblOrderItemLicenseRefunds_tblOrderItemLicenses1 fk_tblOrderItemLicenseRefunds_tblOrderItemLicenses1 4 database.oil.orderItemLicenseID 1 "Using index"
2 DERIVED t5 ref fk_tblTransactions_tblOrders1 fk_tblTransactions_tblOrders1 4 database.o.orderID 1
2 DERIVED t6 ref fk_tblTransactionCardDetails_tblTransactions1 fk_tblTransactionCardDetails_tblTransactions1 4 database.t.transactionID 1
2 DERIVED t7 ref fk_tblVoucherTransactions_tblTransactions1 fk_tblVoucherTransactions_tblTransactions1 4 database.t.transactionID 1
2 DERIVED t8 eq_ref PRIMARY PRIMARY 4 database.vt.voucherID 1
2 DERIVED t9 ref fk_tblVoucherVoucherGroups_tblVouchers1 fk_tblVoucherVoucherGroups_tblVouchers1 4 database.v.voucherID 1 "Using index"
2 DERIVED t10 eq_ref PRIMARY PRIMARY 4 database.vvg.voucherGroupID 1
2 DERIVED t11 ref fk_tblUserVouchers_tblVouchers fk_tblUserVouchers_tblVouchers 4 database.v.voucherID 1 "Using index"
2 DERIVED t12 ref fk_tblTaiwanInvoiceData_tblOrders1 fk_tblTaiwanInvoiceData_tblOrders1 4 database.o.orderID 1
id选择类型表类型可能的键长度参考行额外
1主所有空值11571
2派生t1所有NULL 11737“使用临时;使用文件排序”
2派生的t2 eq_ref PRIMARY PRIMARY 4 database.o.userID 1
2个派生t3参考fk_tblOrderItemLicenses_tblOrders1 fk_tblOrderItemLicenses_tblOrders1 4 database.o.orderID 1
2衍生t4参考fk\u tblorderitem许可证退款\u tblorderitem许可证退款1 fk\u tblorderitem许可证退款\u tblorderitem许可证退款1 4 database.oil.orderItemLicenseID 1“使用索引”
2派生t5参考fk\u tblTransactions\u tblOrders1 fk\u tblTransactions\u tblOrders1 4 database.o.orderID 1
2导出的t6参考fk\u tblTransactionCardDetails\u tblTransactions1 fk\u tblTransactionCardDetails\u tblTransactions1 4 database.t.transactionID 1
2派生t7参考fk\u tblVoucherTransactions\u TbltTransactions 1 fk\u tblVoucherTransactions\u TbltTransactions 1 4 database.t.transactionID 1
2派生t8 eq_ref PRIMARY 4 database.vt.voucherID 1
2派生t9参考fk_TblvoucherGroups_tblVouchers1 fk_TblvoucherGroups_tblVouchers1 4 database.v.voucherID 1“使用索引”
2派生t10 eq_ref PRIMARY 4数据库.vvg.voucherGroupID 1
2派生t11参考fk_tblUserVouchers_tblUserVouchers fk_tblUserVouchers_tblUserVouchers 4 database.v.voucherID 1“使用索引”
2派生t12参考fk_tblTaiwanInvoiceData_tblOrders1 fk_tblTaiwanInvoiceData_tblOrders1 4 database.o.orderID 1
您可以创建一个“结果表”,将查询结果插入其中。您的项目从该结果选项卡读取其数据。然后创建一个作业(不确定mysql选项是什么),该作业每小时/天/周运行一次慢速查询,以使结果表保持最新
此外,通常的索引之类的东西,您可以创建一个“结果表”,将查询结果插入其中。您的项目从该结果选项卡读取其数据。然后创建一个作业(不确定mysql选项是什么),该作业每小时/天/周运行一次慢速查询,以使结果表保持最新
此外,通常的索引输出是什么?尝试删除所有括号。(是的,所有的都有。)输出是什么?尝试删除所有括号。(是的,所有的都是。)这是我对一个类似的查询所做的,该查询包含很多连接和条件。我别无选择,只能每天运行它并将其存储在表中,因为查询需要运行几个小时!这就是我对一个类似的查询所做的,该查询包含很多连接和条件。我别无选择,只能每天运行它并将其存储在表中,因为查询需要运行几个小时!