File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments