“选择计数()”很慢

发布于 2024-09-10 20:05:10 字数 660 浏览 12 评论 0原文

我有一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笙痞 2024-09-17 20:05:10

会更快。

select count(*) from table1

使用 count(code)

It will be faster to do

select count(*) from table1

then to use count(code).

明月夜 2024-09-17 20:05:10

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文