Jas*_*vis 11 mysql sql database
我知道通常情况下,构建mysql查询以命名您需要的每个项目总是更好的性能但是例如在个人资料页面上我可能需要除了少数几个项目之外的所有项目.
SELECT user_name,f_name,l_name,country,usa_state,other_state,zip_code,city,gender,birth_date,date_created,date_last_visit,
user_role,photo_url,user_status,friend_count,comment_count,forum_post_count,referral_count,referral_count_total,
setting_public_profile,setting_online,profile_purpose,profile_height,profile_body_type,profile_ethnicity, profile_occupation,profile_marital_status,profile_sex_orientation,profile_home_town,profile_religion,
profile_smoker,profile_drinker,profile_kids,profile_education,profile_income,profile_headline,profile_about_me,
profile_like_to_meet,profile_interest,profile_music,profile_television,profile_books,profile_heroes,profile_here_for,profile_counter FROM users WHERE user_id=1 AND user_role >
Run Code Online (Sandbox Code Playgroud)
因此,如果没有进行大量测试,也许有经验丰富的人可以提出一些建议吗?
这会更糟吗?
SELECT * FROM users WHERE user_id=1 AND user_role >
Run Code Online (Sandbox Code Playgroud)
我更喜欢列出所有项目,因为在那个页面上,如果我需要来自数据库的东西,但是如果它会更快,我就不会列出它们,这很容易看到我可以使用的东西.
Qua*_*noi 18
注意:命名所有字段当然是最佳做法,但在本文中我将仅讨论性能优势,而不是设计或维护优势.
由于*以下原因,语法可能会更慢:
并非所有字段都已编制索引,并且查询使用全表扫描.可能不是你的情况:你返回的所有字段都很难用单一索引编制索引.
从包含可变长度列的表返回尾随字段可能会导致轻微的搜索开销:要返回20th字段,19应检查先前字段并计算偏移量.
只需要返回更多数据(通过连接传递).
由于您几乎需要所有领域,最后一个原因可能是最重要的原因.比如说,该description TEXT字段只能是页面上未使用1的50字段,但可以占用10所有其他字段的空间.
在这种情况下,最好为所有字段命名并省略不需要的长字段.
| 归档时间: |
|
| 查看次数: |
6980 次 |
| 最近记录: |