简体   繁体   English

MySQL离开了连接优化

[英]MySQL left join optimization

I have 2 tables: 我有2张桌子:

  • formfill has the columns idmessage , value , namefield . formfill有列idmessagevaluenamefield
  • fields has the columns namefield , typefield , optionsfield . fields的列namefieldtypefieldoptionsfield

I don't have any primary key. 我没有任何主键。 Relationship is between namefield columns. 关系是名称字段列之间的关系。

My query is: 我的查询是:

select e.namefield,e.typefield,e.optionsfield,b.value,b.id
from fields as e
left join formfill as b on e.namefield = b.namefield and b.id=1011

This query is ok. 这个查询没问题。 But it runs very slowly (about 10 seconds). 但它运行得非常慢(大约10秒钟)。 How can I make it faster? 我怎样才能让它更快?

You probably should post your query plan with 您可能应该发布您的查询计划

http://dev.mysql.com/doc/refman/5.0/en/explain.html http://dev.mysql.com/doc/refman/5.0/en/explain.html

but low speed of query execution migh mean 但是查询执行的速度很慢

  • you don't have indexes, and engine has to do fullscan, so it's good idea to add indexes on fields you have operations like '='. 你没有索引,引擎必须执行全扫描,所以最好在你有'='之类的操作的字段上添加索引。 The type of index may be 'hash' if you are using = or <>, and btree for operations like < or > 如果使用=或<>,索引的类型可以是'hash',而对于<或>等操作,则可以是btree

  • the number of rows in right table is greater than one in left table by magnitude of 10 and more, so indexes wouldn't help much and you will need to think about partitioning the data 右表中的行数大于左表中的一个,大小为10或更多,所以索引没有多大帮助,你需要考虑分区数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM