Skip to content

Commit 76b2ec0

Browse files
SA: Standardize methods which use COUNT queries (#6505)
- Replace `-1` in return values with `0`. No callers were depending on `-1`. - Replace `count(` with `COUNT(` for the sake of readability. - Replace `COUNT(1)` with `COUNT(*)` (https://mariadb.com/kb/en/count). Both versions provide identical outputs but let's standardize on the docs. Fixes #6494
1 parent 7533813 commit 76b2ec0

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

db/map_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ func TestTableFromQuery(t *testing.T) {
142142
expectedTable: "`registrations`",
143143
},
144144
{
145-
query: "SELECT COUNT(1) FROM registrations WHERE initialIP = ? AND ? < createdAt AND createdAt <= ?",
145+
query: "SELECT COUNT(*) FROM registrations WHERE initialIP = ? AND ? < createdAt AND createdAt <= ?",
146146
expectedTable: "registrations",
147147
},
148148
{
149-
query: "SELECT count(1) FROM orders WHERE registrationID = ? AND created >= ? AND created < ?",
149+
query: "SELECT COUNT(*) FROM orders WHERE registrationID = ? AND created >= ? AND created < ?",
150150
expectedTable: "orders",
151151
},
152152
{

sa/database_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestAutoIncrementSchema(t *testing.T) {
148148
var count int64
149149
err = dbMap.SelectOne(
150150
&count,
151-
`SELECT COUNT(1) FROM columns WHERE
151+
`SELECT COUNT(*) FROM columns WHERE
152152
table_schema LIKE 'boulder%' AND
153153
extra LIKE '%auto_increment%' AND
154154
data_type != "bigint"`)

sa/precertificates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (ssa *SQLStorageAuthority) AddPrecertificate(ctx context.Context, req *sapb
9494
var row struct {
9595
Count int64
9696
}
97-
err := txWithCtx.SelectOne(&row, "SELECT count(1) as count FROM precertificates WHERE serial=?", serialHex)
97+
err := txWithCtx.SelectOne(&row, "SELECT COUNT(*) as count FROM precertificates WHERE serial=?", serialHex)
9898
if err != nil {
9999
return nil, err
100100
}

sa/sa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (ssa *SQLStorageAuthority) AddCertificate(ctx context.Context, req *sapb.Ad
183183
var row struct {
184184
Count int64
185185
}
186-
err := txWithCtx.SelectOne(&row, "SELECT count(1) as count FROM certificates WHERE serial=?", serial)
186+
err := txWithCtx.SelectOne(&row, "SELECT COUNT(*) as count FROM certificates WHERE serial=?", serial)
187187
if err != nil {
188188
return nil, err
189189
}

sa/sa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ func TestAddCertificateRenewalBit(t *testing.T) {
19141914
var count int
19151915
err := sa.dbMap.SelectOne(
19161916
&count,
1917-
`SELECT COUNT(1) FROM issuedNames
1917+
`SELECT COUNT(*) FROM issuedNames
19181918
WHERE reversedName = ?
19191919
AND renewal = ?`,
19201920
ReverseName(name),

sa/saro.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (ssa *SQLStorageAuthorityRO) CountRegistrationsByIP(ctx context.Context, re
183183
var count int64
184184
err := ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(
185185
&count,
186-
`SELECT COUNT(1) FROM registrations
186+
`SELECT COUNT(*) FROM registrations
187187
WHERE
188188
initialIP = :ip AND
189189
:earliest < createdAt AND
@@ -194,7 +194,7 @@ func (ssa *SQLStorageAuthorityRO) CountRegistrationsByIP(ctx context.Context, re
194194
"latest": time.Unix(0, req.Range.Latest),
195195
})
196196
if err != nil {
197-
return &sapb.Count{Count: -1}, err
197+
return nil, err
198198
}
199199
return &sapb.Count{Count: count}, nil
200200
}
@@ -216,7 +216,7 @@ func (ssa *SQLStorageAuthorityRO) CountRegistrationsByIPRange(ctx context.Contex
216216
beginIP, endIP := ipRange(req.Ip)
217217
err := ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(
218218
&count,
219-
`SELECT COUNT(1) FROM registrations
219+
`SELECT COUNT(*) FROM registrations
220220
WHERE
221221
:beginIP <= initialIP AND
222222
initialIP < :endIP AND
@@ -229,7 +229,7 @@ func (ssa *SQLStorageAuthorityRO) CountRegistrationsByIPRange(ctx context.Contex
229229
"endIP": endIP,
230230
})
231231
if err != nil {
232-
return &sapb.Count{Count: -1}, err
232+
return nil, err
233233
}
234234
return &sapb.Count{Count: count}, nil
235235
}
@@ -430,7 +430,7 @@ func (ssa *SQLStorageAuthorityRO) CountFQDNSets(ctx context.Context, req *sapb.C
430430
var count int64
431431
err := ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(
432432
&count,
433-
`SELECT COUNT(1) FROM fqdnSets
433+
`SELECT COUNT(*) FROM fqdnSets
434434
WHERE setHash = ?
435435
AND issued > ?`,
436436
HashNames(req.Domains),
@@ -548,7 +548,7 @@ func (ssa *SQLStorageAuthorityRO) PreviousCertificateExists(ctx context.Context,
548548
var count int
549549
err = ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(
550550
&count,
551-
`SELECT COUNT(1) FROM certificates
551+
`SELECT COUNT(*) FROM certificates
552552
WHERE serial = ?
553553
AND registrationID = ?`,
554554
serial,
@@ -1025,7 +1025,7 @@ func (ssa *SQLStorageAuthorityRO) CountPendingAuthorizations2(ctx context.Contex
10251025

10261026
var count int64
10271027
err := ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(&count,
1028-
`SELECT COUNT(1) FROM authz2 WHERE
1028+
`SELECT COUNT(*) FROM authz2 WHERE
10291029
registrationID = :regID AND
10301030
expires > :expires AND
10311031
status = :status`,
@@ -1102,7 +1102,7 @@ func (ssa *SQLStorageAuthorityRO) CountInvalidAuthorizations2(ctx context.Contex
11021102
var count int64
11031103
err := ssa.dbReadOnlyMap.WithContext(ctx).SelectOne(
11041104
&count,
1105-
`SELECT COUNT(1) FROM authz2 WHERE
1105+
`SELECT COUNT(*) FROM authz2 WHERE
11061106
registrationID = :regID AND
11071107
status = :status AND
11081108
expires > :expiresEarliest AND

0 commit comments

Comments
 (0)