Feature Request
| Q |
A |
| New Feature |
no |
| RFC |
no |
| BC Break |
no |
Summary
I'd like to propose that the Doctrine\ORM\Tools\Pagination\CountWalker should create a count query that selects COUNT(*) instead of COUNT(tbl.id) when a query's HINT_DISTINCT is set/declared false. Both "counts" result in the same number being produced, however COUNT(*) allows some databases (e.g. Postgres) to finish the query faster. Please see the following query plans.
// COUNT(tbl.id) case
EXPLAIN SELECT count(o0_.id) AS sclr_0 FROM "order" o0_;
QUERY PLAN
Finalize Aggregate (cost=40598.68..40598.69 rows=1 width=8)
-> Gather (cost=40598.46..40598.67 rows=2 width=8)
Workers Planned: 2
-> Partial Aggregate (cost=39598.46..39598.47 rows=1 width=8)
-> Parallel Seq Scan on ""order"" o0_ (cost=0.00..38594.17 rows=redacted width=4)
---
// COUNT(*) case
EXPLAIN SELECT count(*) AS sclr_0 FROM "order" o0_;
QUERY PLAN
Finalize Aggregate (cost=36422.71..36422.72 rows=1 width=8)
-> Gather (cost=36422.49..36422.70 rows=2 width=8)
Workers Planned: 2
-> Partial Aggregate (cost=35422.49..35422.50 rows=1 width=8)
-> Parallel Index Only Scan using idx_f5299398f543e763 on ""order"" o0_ (cost=0.42..34418.20 rows=redacted width=0)
Notice how in the case of COUNT(*), Postgres is counting using an "Index Only Scan". The speed difference isn't substantial (at least for the number of rows I tested with), but it's also quite cheap to obtain (by just making the code use COUNT(*)).
Thank you.
Feature Request
Summary
I'd like to propose that the
Doctrine\ORM\Tools\Pagination\CountWalkershould create a count query that selectsCOUNT(*)instead ofCOUNT(tbl.id)when a query'sHINT_DISTINCTis set/declaredfalse. Both "counts" result in the same number being produced, howeverCOUNT(*)allows some databases (e.g. Postgres) to finish the query faster. Please see the following query plans.Notice how in the case of
COUNT(*), Postgres is counting using an "Index Only Scan". The speed difference isn't substantial (at least for the number of rows I tested with), but it's also quite cheap to obtain (by just making the code useCOUNT(*)).Thank you.