为什么SELECT *不好做法?如果添加了您想要的新列,是不是意味着要更改的代码更少?
我知道这SELECT COUNT(*)是一些DB上的性能问题,但是如果你真的想要每一列呢?
我知道通常情况下,构建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)
我更喜欢列出所有项目,因为在那个页面上,如果我需要来自数据库的东西,但是如果它会更快,我就不会列出它们,这很容易看到我可以使用的东西.