我将不胜感激任何帮助试图找到基本查询表连接的返回时间非常慢的原因。
我遇到了麻烦,所以我打开了需要 19.7903 秒才能返回的分析和查询,显示以下配置文件详细信息:
Profiling
Status Time
starting 0.000044
Opening tables 0.000067
System lock 0.000002
Table lock 0.000006
init 0.000009
optimizing 0.000005
statistics 0.000011
preparing 0.000014
executing 0.000031
Sending data 0.000050
end 0.000004
end 0.000003
query end 0.000002
freeing items 0.000009
closing tables 0.000003
removing tmp table 0.000011
closing tables 0.000003
logging slow query 0.000002
cleaning up 0.000003
Showing rows 0 - 29 (2,200 total, Query took 19.7903 sec)
我不明白为什么配置文件时间加起来不等于“19.7903 秒”。
- 'profile'时间和'total,Query'时间相加吗?<<<<<<<
查询是:
SELECT OWNER.ID OWNER_ID,
OWNER.LAST_NAME OWNER_LAST_NAME,
OWNER.FIRST_NAME OWNER_FIRST_NAME,
OWNER.PHONE_HOME_AREACODE OWNER_PHONE_HOME_AREACODE,
OWNER.PHONE_HOME_PREFIX OWNER_PHONE_HOME_PREFIX,
OWNER.PHONE_HOME_LINE_NUMBER OWNER_PHONE_HOME_LINE_NUMBER,
OWNER.PHONE_CELL_AREACODE OWNER_PHONE_CELL_AREACODE,
OWNER.PHONE_CELL_PREFIX OWNER_PHONE_CELL_PREFIX,
OWNER.PHONE_CELL_LINE_NUMBER OWNER_PHONE_CELL_LINE_NUMBER,
/*Some columns from OWNER removed for brevity*/
OWNER.CITY OWNER_CITY,
OWNER.PROVINCE OWNER_PROVINCE,
OWNER.POSTAL OWNER_POSTAL,
OWNER.NOTES OWNER_NOTES,
OWNER.REFERRED_BY OWNER_REFERRED_BY,
VISITOR.NAME VISITOR_NAME,
VISITOR.SIZE VISITOR_SIZE,
VISITOR.INACTIVE VISITOR_INACTIVE,
VISITOR.ID VISITOR_ID,
VISITOR.DELETED VISITOR_DELETED,
VACCINATIONS.CANINE_DISTEMPER_PARVOVIRUS_EXPIRES VACCINATIONS_CANINE_DISTEMPER_PARVOVIRUS_EXPIRES,
VACCINATIONS.CANINE_RABIES_EXPIRES VACCINATIONS_CANINE_RABIES_EXPIRES,
VACCINATIONS.CANINE_BORDETELLA_EXPIRES VACCINATIONS_CANINE_BORDETELLA_EXPIRES,
VACCINATIONS.FELINE_FVRCPC_EXPIRES VACCINATIONS_FELINE_FVRCPC_EXPIRES,
VACCINATIONS.FELINE_RABIES_EXPIRES VACCINATIONS_FELINE_RABIES_EXPIRES
FROM OWNER
LEFT JOIN VISITOR
ON VISITOR.OWNER_ID = OWNER.ID
LEFT JOIN VACCINATIONS
ON VACCINATIONS.VISITOR_ID = VISITOR.ID
ORDER BY VISITOR_NAME
解释的结果:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE OWNER ALL NULL NULL NULL NULL 1483 Using temporary; Using filesort
1 SIMPLE VISITOR ref OWNER_ID OWNER_ID 4 wayDEV.OWNER.ID 1
1 SIMPLE VACCINATIONS ALL VISITOR_ID NULL NULL NULL 2059
索引:
VISITOR:
Indexes: Documentation Keyname Type Cardinality Action Field
PRIMARY PRIMARY 2227 Edit Drop ID
NAME INDEX 2227 Edit Drop NAME
OWNER_ID INDEX 2227 Edit Drop OWNER_ID
OWNER:
Indexes: Documentation Keyname Type Cardinality Action Field
PRIMARY PRIMARY 1601 Edit Drop ID
LAST_NAME INDEX 1601 Edit Drop LAST_NAME
VACCINATIONS:
Indexes: Documentation Keyname Type Cardinality Action Field
PRIMARY PRIMARY 2131 Edit Drop ID
VISITOR_ID UNIQUE 2131 Edit Drop VISITOR_ID
BOARDING:
Indexes: Documentation Keyname Type Cardinality Action Field
PRIMARY PRIMARY 2256 Edit Drop ID
OWNER INDEX 2256 Edit Drop OWNER_ID
VISITOR INDEX 2256 Edit Drop VISITOR_ID
GROOMING:
Indexes: Documentation Keyname Type Cardinality Action Field
PRIMARY PRIMARY 2077 Edit Drop ID
VISITOR_ID UNIQUE 2077 Edit Drop VISITOR_ID
OWNER INDEX 2077 Edit Drop OWNER_ID
这个查询已经好几个月了。只是最近才间歇性地恢复缓慢。大约 20% 的时间会很慢。其余时间它返回就好(显示第 0 - 29 行(总共 2,200 行,查询耗时 0.0018 秒))。? :\
它是一个间歇性问题的事实是否表明查询本身存在其他问题?<<<<<<<
正如我上面问的......我不明白为什么配置文件时间加起来不等于“19.7903 秒”。
'profile'时间和'total,Query'时间相加吗?<<<<<<<
整个数据库中只有几千条记录。
任何帮助,将不胜感激。我在 Godaddy 服务器上。
(我知道我的查询可能有问题。或者它可以被优化。但我在这里问一些非常具体的问题 - 由......“<<<<<<<”)
老实说......我们在这里谈论>>>>>>>20<<<<<<<秒!当然,对 2000 条记录数据库的查询不应该在 20 秒后返回???