Clarify code that aims at fixing #1357

This commit is contained in:
Gwendal Roué committed 2025-01-19 16:26:59 +01:00
1 parent 61c7fdf81b
commit a4132a00db
2 files changed
+14 -4

No files matched your search

+1 -1
View File
@@ -636,7 +636,7 @@ extension SQLRelation {
}
// <https://github.com/groue/GRDB.swift/issues/1357>
guard selection.allSatisfy(\.isTriviallyCountable) else {
if selection.contains(where: \.requiresTrivialCount) {
return try fetchTrivialCount(db)
}
+13 -3
View File
@@ -245,15 +245,25 @@ extension SQLSelection {
}
}
/// Returns whether this selection MUST be counted with a "trivial"
/// count: `SELECT COUNT(*) FROM (SELECT ...)`.
///
/// Supports SQLRelation.fetchCount.
///
/// See <https://github.com/groue/GRDB.swift/issues/1357>
var isTriviallyCountable: Bool {
var requiresTrivialCount: Bool {
switch impl {
case .aliasedExpression, .literal:
return false
case .allColumns, .qualifiedAllColumns, .expression:
// Trivial count is required.
//
// For example, the WHERE clause here requires the aliased
// column to be preserved in the counting request:
// SELECT *, column AS alt FROM player WHERE alt
return true
case .allColumns, .qualifiedAllColumns:
return false
case .expression:
return false
}
}
}