“选择计数()”很慢
我有一个包含 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)
之间的比较。
解决办法是什么?
I have a database with 1,000,000 records and a query like this:
select count(code) from table1
It works well on the local system but becomes very slow on the network. Other queries like select * from table
execute quickly, but select count(code) from table1
is very slow. I can't change the database's structure. My database is Foxpro and I use VB.NET.
Is there a solution?
Edit: Should I write code like this?
dim ds as new dataset
dim da as new datadapter("select count(*) from table ", connection)
da.fill(ds,"tbl1")
Then how can I get select count(code) from table1
from the dataset?
Or do I have to use LINQ?
Edit 2: I mean the comparison between select count(*)
and select count(code)
.
What is the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
会更快。
使用
count(code)
It will be faster to do
then to use
count(code)
.select count(code) 从表中选择“code”列,然后对它们进行计数,但 select * 只是选择它们,但不进行计数。因此,如果您比较这两者,那么逻辑上 select * 很快。
对于拥有超过 1,000,000 条记录的表,执行时间为:
select * = 0.9818625
select count(column_name) = 1.571275
The select count(code) selects the column 'code' from the table, and then counts them, but select * just selects them, but does not do the count. So if you are comparing these two then logically select * is fast.
For my table which has more than 1,000,000 records the execution time is:
select * = 0.9818625
select count(column_name) = 1.571275