“select count()”非常慢

时间:2010-07-19 18:12:14

标签: vb.net networking foxpro

我有一个包含1,000,000条记录的数据库和一个这样的查询:

select count(code) from table1

它在本地系统上运行良好,但在网络上变得非常慢。其他查询(例如select * from table)执行得很快,但select count(code) from table1非常慢。我无法改变数据库的结构。我的数据库是Foxpro,我使用的是VB.NET。

有解决方案吗?

编辑:我应该编写这样的代码吗?

dim ds as new dataset
dim da as new datadapter("select count(*) from table ", connection)
da.fill(ds,"tbl1")

那么如何从数据集中获取select count(code) from table1

或者我必须使用LINQ吗?

编辑2:我的意思是select count(*)select count(code)之间的比较。
解决方案是什么?

2 个答案:

答案 0 :(得分:6)

这样做会更快

select count(*) from table1

然后使用count(code)

答案 1 :(得分:0)

选择计数(代码)从表中选择列'代码',然后对它们进行计数,但是选择*只选择它们,但不进行计数。所以,如果你比较这两个,那么逻辑上选择*就是快。

对于我的表,其记录超过1,000,000条,执行时间为:

选择* = 0.9818625

select count(column_name)= 1.571275

相关问题