下面这条语句是不是可以有性能更优的方法? 还有就是我64位的2003操作系统,数据库SQL2005只能用到3.6G内存是什么原因?,系统内存有24G;select  a.pro_id,a.pro_name,a.pro_postdate,a.pro_fk_coid from productinfo a ,(select top 4 max(pro_id) as pro_id,pro_fk_coid from productinfo where pro_fk_coid>@id  group by pro_fk_coid  order by pro_fk_coid  ) b where   a.pro_id=b.pro_id and a.pro_fk_coid=b.pro_fk_coid
union
select c.pro_id,c.pro_name,c.pro_postdate,c.pro_fk_coid from productinfo c ,(select  top 4 max(pro_id) as pro_id,pro_fk_coid from productinfo where pro_fk_coid<@id group by pro_fk_coid order by pro_fk_coid desc ) d where c.pro_id=d.pro_id  and c.pro_fk_coid=d.pro_fk_coid以上语句的功能是查询出某一个公司相邻8家公司(前4家,后4家,按外键pro_fk_coid来确定)的各一条最新产品;产品表结构为,pro_id(主键);pro_fk_coid (公司外键)哪位高手能给出更佳性能的解决方案啊? 先谢谢了~~~

解决方案 »

  1.   

    数据库SQL2005只能用到3.6G内存是什么原因?,系统内存有24G;开启SQL server的“使用AWE非配内存”选项。
      

  2.   

    看是否设置了最大的内存限制sp_configure 'max server memory (MB)' 
      

  3.   

    先说明关于内存的问题。
    http://blog.csdn.net/claro/archive/2008/10/18/3094807.aspx
    通过更快的数据访问提高了性能并减少了访问磁盘的频率。故决定打开SQL2K5的AWE参数,将6G的内存锁定,完全给SQL使用。
      大致配置步骤如下:
      1、因服务器已打开/PAE参数,否则需在系统盘根目录下修改Boot.ini文件(去除只读属性),在=optin /fastdetect后添加/PAE参数。
      2、在windows的组策略中启用锁定内存页选项:
         a)在"开始"菜单上单击"运行"子菜单,然后在"打开"框中键入"gpedit.msc"。
         b)在"组策略"控制台上,展开"计算机配置",然后展开"Windows   设置"。
         c)展开"安全设置",然后展开"本地策略",选择"用户权限分配"复选框。
         d)在详细资料窗格中,双击"锁定内存页"。
         e)在"本地安全策略设置"对话框中,单击"添加"按钮。
         f)在"选择用户或组"对话框中,添加有权运行sqlservr.exe的帐户。
      3、启用SQLServer2K5的AWE支持。
         a)在对象资源管理器中,右键单击服务器并选择“属性”。
         b)单击“内存”节点。
         c)在“服务器内存选项”下,选择“使用 AWE 分配内存”。
         d)在对象资源管理器中,右键单击服务器并选择“属性”。
         e)单击“内存”节点。
         f)在“服务器内存选项”下,选择“使用 AWE 分配内存”。
         g)配置相应最小内存数和最大内存数。  
         同时也可以用脚本执行的方式操作:
         --当 show advanced options 设置为'1'时才能更改AWE
         sp_configure 'show advanced options', 1
       RECONFIGURE
       GO
         --启用AWE 选项
       sp_configure 'awe enabled', 1
       RECONFIGURE
       GO
         --设置最大内存为6G
       sp_configure 'max server memory', 6144
       RECONFIGURE
       GO
      4、注意需要重新启动SQL 服务。
      

  4.   

    数据库SQL2005只能用到3.6G内存是什么原因?,系统内存有24G;开启SQL server的“使用AWE非配内存”选项。
    64位不用的.你的内存太小了,调整下你的服务器的内存大小。
      

  5.   

    你的操作系统是32位的吧,64位才支持4g以上内存,如果是32位你得强制打开windows的pae开关,是在boot.ini文件里,你可以google一下,不过那样windows会变成很不稳定,建议还是升级操作系统吧
      

  6.   

    优化不懂这样是不是好一点?减少一次连接。。
    select a.pro_id,a.pro_name,a.pro_postdate,a.pro_fk_coid from productinfo a ,(
    select top 4 max(pro_id) as pro_id,pro_fk_coid from productinfo where pro_fk_coid>@id group by pro_fk_coid order by pro_fk_coid
    UNION ALL
    select top 4 max(pro_id) as pro_id,pro_fk_coid from productinfo where pro_fk_coid<@id group by pro_fk_coid order by pro_fk_coid desc)b where a.pro_id=b.pro_id and a.pro_fk_coid=b.pro_fk_coid