导航

[原创]同样的SQL Server查询,不一样的效率

Posted on 2007-03-30 16:21  o摆摆o0O   阅读(615)  评论(0)    收藏  举报

一、测试条件

操作系统:Win 2003

数据库引擎:Sql Server2000

脚本解释程序:ASP

数据库:保存有225000条的IP地址数据库(ID,IP1,IP2,CITY),ID为主键&标识

目的:通过浏览者的IP地址转换为相应的城市名称

cip_address为客户端IP地址,格式为:标准IP地址格式转换为十进制格式数字

二、测试结果

1.使用 “select top 1 city,province from ip_address where "&cip_address&">=ip1 and "&cip_address&"<=ip2  order by id desc”

程序执行时间:最高 296.875毫秒 最低 281.25毫秒

2.使用 “select city,province from ip_address where "&cip_address&">=ip1 and "&cip_address&"<=ip2  order by id desc”

程序执行时间:最高 93.75毫秒 最低 78.125毫秒

3.使用 “select city,province from ip_address where "&cip_address&">=ip1 and "&cip_address&"<=ip2”

程序执行时间:最高 62.5毫秒 最低 46.875毫秒

4.使用 “select city,province from ip_address where "&cip_address&">=ip1 and "&cip_address&"<=ip2”且将ip1字段设置为主键

程序执行时间:最高 15.625毫秒 最低 0毫秒(0也可以啊?不解)

5.使用 “select city,province from ip_address where "&cip_address&">=ip1 and "&cip_address&"<=ip2”且将ip2字段设置为主键

程序执行时间:最高 31.25毫秒 最低 31.25毫秒