diff --git a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift index 525e32728..1924d8d55 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLGenerationContext.swift @@ -20,22 +20,10 @@ public struct SQLGenerationContext { /// Used for SQLQuery.makeSelectStatement() and SQLQuery.makeDeleteStatement() static func queryGenerationContext(aliases: [TableAlias]) -> SQLGenerationContext { - // TODO: since 5d9fa76, in the lines below, we started uniquing aliases. - // Something tells me this is a wrong fix. We should try to investigate - // and maybe revert this change. I don't see why we'd really need to - // unique aliases, and I'm afraid we're hiding some latent bug - // somewhere else. - - // Unique aliases, but with preserved ordering, so that we have stable SQL generation - let uniqueAliases = aliases.reduce(into: [TableAlias]()) { - if !$0.contains($1) { - $0.append($1) - } - } return SQLGenerationContext( arguments: [], - resolvedNames: uniqueAliases.resolvedNames, - qualifierNeeded: uniqueAliases.count > 1) + resolvedNames: aliases.resolvedNames, + qualifierNeeded: aliases.count > 1) } /// Used for TableRecord.selectionSQL diff --git a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index 05393763e..321313ed0 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -426,15 +426,14 @@ private struct SQLQualifiedRelation { /// SELECT ... FROM ... AS ... JOIN ... WHERE ... ORDER BY ... /// | /// • alias - let alias: TableAlias + var alias: TableAlias { return source.alias } /// All aliases, including aliases of joined relations var allAliases: [TableAlias] { - var aliases = [alias] + var aliases = source.allAliases for join in joins.values { aliases.append(contentsOf: join.relation.allAliases) } - aliases.append(contentsOf: source.allAliases) return aliases } @@ -495,7 +494,6 @@ private struct SQLQualifiedRelation { // this SQLQualifiedRelation generates SQL. source = SQLQualifiedSource(relation.source) let alias = source.alias - self.alias = alias // Qualify all joins, selection, filter, and ordering, so that all // identifiers can be correctly disambiguated and qualified.