Skip to content

Commit 699122a

Browse files
committed
Feedback.
1 parent d1430e2 commit 699122a

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,19 @@ protected override void GenerateSetOperationOperand(SetOperationBase setOperatio
103103
// however, we can instead wrap the nested set operation in a SELECT * FROM () to achieve the same effect.
104104
// The following is a copy-paste of the base implementation from QuerySqlGenerator, adding the SELECT.
105105

106-
// INTERSECT has higher precedence over UNION and EXCEPT, but otherwise evaluation is left-to-right.
107-
// To preserve evaluation order, add parentheses whenever a set operation is nested within a different set operation
108-
// - including different distinctness.
109-
// In addition, EXCEPT is non-commutative (unlike UNION/INTERSECT), so add parentheses for that case too (see #36105).
110-
if (TryUnwrapBareSetOperation(operand, out var nestedSetOperation)
111-
&& (nestedSetOperation is ExceptExpression
112-
|| nestedSetOperation.GetType() != setOperation.GetType()
113-
|| nestedSetOperation.IsDistinct != setOperation.IsDistinct))
114-
{
115-
Sql.AppendLine("SELECT * FROM (");
116-
117-
using (Sql.Indent())
118-
{
119-
Visit(operand);
120-
}
121-
122-
Sql.AppendLine().Append(")");
123-
}
124-
// ValuesExpression with multiple rows uses UNION ALL by default.
125-
// We wrap it in a SELECT * FROM () to ensure that the rows are treated as a single set operation.
126-
else if (operand is { Tables: [ValuesExpression { RowValues.Count: > 1 }] })
106+
if (
107+
// INTERSECT has higher precedence over UNION and EXCEPT, but otherwise evaluation is left-to-right.
108+
// To preserve evaluation order, add parentheses whenever a set operation is nested within a different set operation
109+
// - including different distinctness.
110+
// In addition, EXCEPT is non-commutative (unlike UNION/INTERSECT), so add parentheses for that case too (see #36105).
111+
(TryUnwrapBareSetOperation(operand, out var nestedSetOperation)
112+
&& (nestedSetOperation is ExceptExpression
113+
|| nestedSetOperation.GetType() != setOperation.GetType()
114+
|| nestedSetOperation.IsDistinct != setOperation.IsDistinct))
115+
||
116+
// ValuesExpression with multiple rows uses UNION ALL by default.
117+
// We wrap it in a SELECT * FROM () to ensure that the rows are treated as a single set operation.
118+
(operand is { Tables: [ValuesExpression { RowValues.Count: > 1 }] }))
127119
{
128120
Sql.AppendLine("SELECT * FROM (");
129121

0 commit comments

Comments
 (0)