duanjuebiao6730 2011-06-09 10:29
浏览 26
已采纳

为什么查询中的额外空格和换行符不好?

I see, from time to time, that people say that SQL query that is sent to a server from client application should not contain any extra linebreaks or spaces. One of the reason I've heard is "why waste network traffic?".

Is there a real reason to make code harder to read and edit in favor of removing all spaces?

With spaces:

$q = 'SELECT
            `po`.*,
            `u`.`nickname`,
            `u`.`login`
        FROM
            `postponed_operations` AS `po`
            LEFT JOIN `users` AS `u` ON `u`.`id` = `po`.`user_id`
        ORDER BY `will_be_deleted_after`';
return mysql_query($q);

Without spaces:

$q = 'SELECT '.
            '`po`.*,'.
            '`u`.`nickname`,'.
            '`u`.`login`'.
        'FROM '.
            '`postponed_operations` AS `po` '.
            'LEFT JOIN `users` AS `u` ON `u`.`id`=`po`.`user_id` '.
        'ORDER BY `will_be_deleted_after`';
return mysql_query($q);
  • 写回答

5条回答 默认 最新

  • douba9425 2011-06-09 10:37
    关注

    It is true, it will cost network traffic and server time; but it will be negligible on all except the most extreme cases. Now, if you are editing the code of FaceBook (or Google, or similar), and optimize in this way the 10 most common queries, then there is a point, since they will be run billions of times per day. But in all the other cases I think it is a waste of time to consider removing spaces.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)