Difference between Count & CountApprox
chandrurec
Member Posts: 560
Hi all,
I want to know the difference between Count keyword and CountApprox keyword which is assosiated with table.
Both are used for counting the number of records in the given table , if that is the case what is the difference between these two keywords and in what situation we go for Count and CountApprox.
If anybody knows the difference , kindly reply me back.
Thanks in advance.
Regards,
Chandru.
I want to know the difference between Count keyword and CountApprox keyword which is assosiated with table.
Both are used for counting the number of records in the given table , if that is the case what is the difference between these two keywords and in what situation we go for Count and CountApprox.
If anybody knows the difference , kindly reply me back.
Thanks in advance.
Regards,
Chandru.
0
Comments
-
Have you read the on-line help for these two commands?0
-
Hi Kine,
I do read the online help.It is saying that Count is inappropriate because it takes into consideration of both the committed as well as non committed entries into account whereas CountApprox dont.
But still I am not very clear with what do u mean by comitted and non comitted entries.
So if you know the difference , kindly let me know.
Thanks in advance.
Regards,
Chandru.0 -
Than it is not about the function but it is about what does it mean "commited and uncommited"... ;-) It will be quicker for all of us to enter the correct question... ;-)
Commited - any record which was created/modified and the transaction is already commited (the record is there, is not locked, is persistent)
Uncommited - any record which was created/modified/deleted but the transaction is not commited yet - it means that the insert/modify/delete could be rolled back and you cannot be sure if the record will be there as it is or not ("Work in progress" on this record... another process is working with it)
I highly recommend to learn something about transactions and commit and rollback functionality in database systems...0 -
The difference is this:
A COUNT command actually sends a SELECT COUNT(*) FROM ... statement to the SQL Server, thus the SQL Server is actually counting the number of rows within the filter. Hence, the result is 100% correct.
To perform such a query OK the SQL Server need apropriate indexes, statistics, etc..
A COUNTAPPROX tells the SQL Server to only create a Query Execution Plan for a query:
1. SET SHOWPLAN_ALL ON
2. SELECT * FROM ...
3. SET SHOWPLAN_ALL OFF
Thus SQL Server is not performing a count, it only compiles a QEP. This QEP contains a field names "Estimate Rows" which tells the estimated number of rows within the filtered result. This estimate is shown in NAV - as it says: it's an estimate and might be incorrect.
As the query is not really executed it's faster than a real COUNT.Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
I always use CountApprox when I need to count the total rows to show a progress bar. Since it is only a progress bar, it is not needed to be 100% accuratte.
Salut!Laura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.0 -
I have to admit that I use a full COUNT even with Progress-Bars as I find it so annoying if the status is not telling the truth ](*,) ... means it shows 80% and is finished or it's 100% and still processing ...kitik wrote:I always use CountApprox when I need to count the total rows to show a progress bar. Since it is only a progress bar, it is not needed to be 100% accuratte.
Salut!
Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
When do you use CountApprox then?
Salut!
Laura NicolàsLaura Nicolàs
Author of the book Implementing Dynamics NAV 2013
Cursos Dynamics NAV (spanish) : http://clipdynamics.com/ - A new lesson released every day.0 -
Well, I don't use it at all ... :roll:Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
The only valid place for CountApprox might be in Progress Dialogs.0
-
stryk wrote:Hence, the result is 100% correct.
Well. Result is usually %100 correct
What exactly does COUNT count?Tomas,
Dynamics NAV Enthusiast0 -
stryk wrote:The difference is this:
A COUNT command actually sends a SELECT COUNT(*) FROM ... statement to the SQL Server, thus the SQL Server is actually counting the number of rows within the filter. Hence, the result is 100% correct.Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions



