关于优化SQL语句,加快查询速度

字体: | 打印

以下是我部分的PHP代码,当我访问该代码页面时,总是等待很长时间,这是为什么,是不是我SQL语句有问题,帮我看看?


[ 本帖最后由 hxmtrend 于 2008-7-24 14:38 编辑 ]

我也来说两句 查看全部评论 相关评论

  • hxmtrend (2008-7-21 17:30:33)

    有什么方法吗

    [ 本帖最后由 hxmtrend 于 2008-7-23 09:16 编辑 ]
  • hxmtrend (2008-7-21 17:31:44)

  • hxmtrend (2008-7-21 17:53:56)

  • 余额不足 (2008-7-21 17:59:18)

    1.
    $selectCount="select count(*) from products where PSPID in (select SPID from sproducts where SGPID =$GPID) order by Pdate desc ";
    将 order by部份去掉。

    2. 你的UID如果是整数型,将
    $select_user = "select Utruename,Ucompany,Utel,Uemail from users where UID='$arr_sprod[PUID]'";
    改为
    $select_user = "select Utruename,Ucompany,Utel,Uemail from users where UID=".$arr_sprod[PUID];

    以上是根据你现有的语句改的。
    不过,我想根本的原因是你的结构有问题,在while里产生了大量的查询语句。
    试试从整体上改变一下吧。
  • hxmtrend (2008-7-21 18:18:26)

  • hxmtrend (2008-7-21 18:18:58)

  • hxmtrend (2008-7-22 13:24:40)

  • ShiningRay (2008-7-22 15:22:40)

    "select count(*) from products where PSPID in (select SPID from sproducts where SGPID =$GPID) order by Pdate desc "
    应该避免用子查询,优先使用join
  • hxmtrend (2008-7-23 09:05:42)

    以这上面为例

    [ 本帖最后由 hxmtrend 于 2008-7-23 10:46 编辑 ]
  • hxmtrend (2008-7-23 09:06:02)

  • hxmtrend (2008-7-23 09:10:31)

  • hxmtrend (2008-7-23 09:17:23)

  • hxmtrend (2008-7-23 10:12:55)

    有没有甚者高效率查询

    [ 本帖最后由 hxmtrend 于 2008-7-23 12:33 编辑 ]
  • hxmtrend (2008-7-23 12:34:00)

  • hxmtrend (2008-7-23 16:48:21)

  • hxmtrend (2008-7-23 17:16:25)

  • hxmtrend (2008-7-24 09:41:38)

  • hxmtrend (2008-7-24 12:24:19)

  • hxmtrend (2008-7-24 14:39:09)

  • hxmtrend (2008-7-24 16:28:40)