Monday, January 12, 2015

APPROX_COUNT_DISTINCT - New Oracle 12c Function



Oracle 12c has introduced a aggregate function 'APPROX_COUNT_DISTINCT'  that produces approximate count of discount records. 

If you can live with the approximate count , then this will be better choice if the underlying dataset is large. 

In my test database , I have table called 'whlog' that has around 4 million records .
When I used this funcion , Oracle was able to use the index and comeup with the result a lot quickly . 

The difference between this function and the traditional ( count of discount  ) was pretty significant . 

As always , your mileage will vary. 

Here are the examples:
----------------------

SQL> select count(*) from whlog;

  COUNT(*)
----------
   4244970


SQL> Select count(distinct member_id) from  whlog ;

COUNT(DISTINCTMEMBER_ID)
------------------------
                   48090

Elapsed: 00:00:04.62


SQL>  SELECT  APPROX_COUNT_DISTINCT(member_id) from whlog ;

APPROX_COUNT_DISTINCT(MEMBER_ID)
--------------------------------
                           48057

Elapsed: 00:00:00.23


No comments:

Post a Comment