"select count()" is very slow
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 se开发者_如何学Pythonlect count(*)
and select count(code)
.
It will be faster to do
select count(*) from table1
then to use count(code)
.
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
精彩评论