Answer the question
In order to leave comments, you need to log in
SQL Count, how complex is the query?
Hello, there is a table in the database (ms sql || my sql) there will be a lot of data in it, there are not many columns, just a lot of rows.
It is necessary to request the number of records and the question arose of how best to do this? The Count function sort of runs through the entire table, which will depend on its size. Is there any way to do this instantly?
The only thing that comes to mind is to make a trigger that will write to another table the number or something like that
Answer the question
In order to leave comments, you need to log in
An ID field with a unique number and an index on this field, the index is better clustered. count(ID) will be fast enough, but not instantly, of course.
Sobsno you yourself answered.
On two projects there was a similar problem, there are 30-40 million rows in the database.
It was decided by adding a function of the type Recorded in DB1 - Write LastID in DB2
As a result, there were about a dozen rows in DB2, each with its own LastID (a breakdown was needed by some parameters).
Answer = 1ms!))))
Of course, this is if you really need to frequently receive this Count of yours)))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question