且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

减少mysql查询的执行时间

更新时间:2021-07-02 23:47:17

首先,为了获得高效的join,您应该以增加的行数顺序保留表.这样可以大大减少行扫描的次数.因此,对于您的查询,join的顺序应为measurement_test mt natural join measurement_point mp natural join measurement_values mv.还要确保联接列上已定义索引,并且它们具有完全相同的数据类型.在MySQL中,char(15)varchar(15)被认为是相似的,但char(15)varchar(10)却不一样.

First off, for an efficient join, you should keep the tables in increasing order of number of rows. This reduces the number of row scans drastically. So for your query, the join order should be measurement_test mt natural join measurement_point mp natural join measurement_values mv. Also ensure that the join columns have indexes defined on them, and they have exactly identical datatypes. char(15) and varchar(15) are considered similar in MySQL, but not char(15) and varchar(10).