Remove redundant COALESCE()s around COUNT()s in database queries (#11570)

`COUNT()` never returns `NULL`. A `COUNT(*)` over 0 rows is 0 and a
`COUNT(NULL)` is also 0.
This commit is contained in:
Sean Quah 2021-12-14 12:34:30 +00:00 committed by GitHub
parent 33abbc3278
commit a4dce5b53d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 21 deletions

View file

@ -794,7 +794,7 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore):
yesterday = int(self._clock.time()) - (60 * 60 * 24)
sql = """
SELECT user_type, COALESCE(count(*), 0) AS count FROM (
SELECT user_type, COUNT(*) AS count FROM (
SELECT
CASE
WHEN is_guest=0 AND appservice_id IS NULL THEN 'native'
@ -819,7 +819,7 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore):
def _count_users(txn):
txn.execute(
"""
SELECT COALESCE(COUNT(*), 0) FROM users
SELECT COUNT(*) FROM users
WHERE appservice_id IS NULL
"""
)