private static bool TryGetExistsSubselect(BoundExpression expression, out BoundExistsSubselect existsSubselect, out bool isNegated) { var negation = expression as BoundUnaryExpression; if (negation != null && negation.Result.Selected.Signature.Kind == UnaryOperatorKind.LogicalNot) { if (!TryGetExistsSubselect(negation.Expression, out existsSubselect, out isNegated)) { return(false); } isNegated = !isNegated; return(true); } isNegated = false; existsSubselect = expression as BoundExistsSubselect; return(existsSubselect != null); }
protected override BoundExpression RewriteExistsSubselect(BoundExistsSubselect node) { var relation = RewriteRelation(node.Relation); // TODO: This isn't ideal. In many cases, the relation will not have any output values. // This means, we've to create a new value slot factory which in turn means that // we have create multiple slots with the same name. It seems we should think of // a better way to carry the factories. Maybe we should just expose on specific // bound nodes? var facory = node.Relation.GetOutputValues().FirstOrDefault()?.Factory ?? new ValueSlotFactory(); var valueSlot = facory.CreateTemporary(typeof(bool)); var subquery = new Subquery(SubqueryKind.Exists, valueSlot, relation, CurrentPassthru); var subqueries = _subqueryStack.Peek(); subqueries.Add(subquery); return(Expression.Value(valueSlot)); }
protected override void VisitExistsSubselect(BoundExistsSubselect node) { SubqueryFound = true; }