Skip to content

Commit a4132a0

Browse files
committed
Clarify code that aims at fixing groue#1357
1 parent 61c7fdf commit a4132a0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

GRDB/QueryInterface/SQL/SQLRelation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ extension SQLRelation {
636636
}
637637

638638
// <https://github.com/groue/GRDB.swift/issues/1357>
639-
guard selection.allSatisfy(\.isTriviallyCountable) else {
639+
if selection.contains(where: \.requiresTrivialCount) {
640640
return try fetchTrivialCount(db)
641641
}
642642

GRDB/QueryInterface/SQL/SQLSelection.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,25 @@ extension SQLSelection {
245245
}
246246
}
247247

248+
/// Returns whether this selection MUST be counted with a "trivial"
249+
/// count: `SELECT COUNT(*) FROM (SELECT ...)`.
250+
///
248251
/// Supports SQLRelation.fetchCount.
249252
///
250253
/// See <https://github.com/groue/GRDB.swift/issues/1357>
251-
var isTriviallyCountable: Bool {
254+
var requiresTrivialCount: Bool {
252255
switch impl {
253256
case .aliasedExpression, .literal:
254-
return false
255-
case .allColumns, .qualifiedAllColumns, .expression:
257+
// Trivial count is required.
258+
//
259+
// For example, the WHERE clause here requires the aliased
260+
// column to be preserved in the counting request:
261+
// SELECT *, column AS alt FROM player WHERE alt
256262
return true
263+
case .allColumns, .qualifiedAllColumns:
264+
return false
265+
case .expression:
266+
return false
257267
}
258268
}
259269
}

0 commit comments

Comments
 (0)