B
B
beduin012021-05-07 12:10:22
PostgreSQL
beduin01, 2021-05-07 12:10:22

Fast alternative to COUNT(*)?

Now I use SELECT COUNT(*) СложныйЗапрос
COUNT (*) predictably slows down. How to speed it up without big edits?

Arrange options:
1. Return an approximate amount
2. Return COUNT (*) for the first 1000 elements. They say that there are so many files falling under the condition in the database

SELECT COUNT(*) FROM files t1

    WHERE NOT EXISTS (SELECT 1
              FROM files t2
              WHERE t1."Number" = t2."Number" AND
                t1."docDate" < t2."docDate"
            )
    AND t1.status IS NULL
   AND t1.section_name='Users' AND t1.status IS NULL


The subquery is needed to select the newest version of the document. there may be duplicate numbers in the database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
parallel47adm, 2021-05-07
@parallel47adm

It was yesterday!
How to quickly count the number of records in a table with a billion records without an index?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question