MCPcopy Create free account
hub / github.com/dolthub/doltgresql / FoldComparisonExpr

Function FoldComparisonExpr

postgres/parser/sem/tree/eval.go:1634–1672  ·  view source on GitHub ↗

FoldComparisonExpr folds a given comparison operation and its expressions into an equivalent operation that will hit in the CmpOps map, returning this new operation, along with potentially flipped operands and "flipped" and "not" flags.

(
	op ComparisonOperator, left, right Expr,
)

Source from the content-addressed store, hash-verified

1632// this new operation, along with potentially flipped operands and "flipped"
1633// and "not" flags.
1634func FoldComparisonExpr(
1635 op ComparisonOperator, left, right Expr,
1636) (newOp ComparisonOperator, newLeft Expr, newRight Expr, flipped bool, not bool) {
1637 switch op {
1638 case NE:
1639 // NE(left, right) is implemented as !EQ(left, right).
1640 return EQ, left, right, false, true
1641 case GT:
1642 // GT(left, right) is implemented as LT(right, left)
1643 return LT, right, left, true, false
1644 case GE:
1645 // GE(left, right) is implemented as LE(right, left)
1646 return LE, right, left, true, false
1647 case NotIn:
1648 // NotIn(left, right) is implemented as !IN(left, right)
1649 return In, left, right, false, true
1650 case NotLike:
1651 // NotLike(left, right) is implemented as !Like(left, right)
1652 return Like, left, right, false, true
1653 case NotILike:
1654 // NotILike(left, right) is implemented as !ILike(left, right)
1655 return ILike, left, right, false, true
1656 case NotSimilarTo:
1657 // NotSimilarTo(left, right) is implemented as !SimilarTo(left, right)
1658 return SimilarTo, left, right, false, true
1659 case NotRegMatch:
1660 // NotRegMatch(left, right) is implemented as !RegMatch(left, right)
1661 return RegMatch, left, right, false, true
1662 case NotRegIMatch:
1663 // NotRegIMatch(left, right) is implemented as !RegIMatch(left, right)
1664 return RegIMatch, left, right, false, true
1665 case IsDistinctFrom:
1666 // IsDistinctFrom(left, right) is implemented as !IsNotDistinctFrom(left, right)
1667 // Note: this seems backwards, but IS NOT DISTINCT FROM is an extended
1668 // version of IS and IS DISTINCT FROM is an extended version of IS NOT.
1669 return IsNotDistinctFrom, left, right, false, true
1670 }
1671 return op, left, right, false, false
1672}

Callers 4

memoizeFnMethod · 0.85
initFunction · 0.85
typeCheckComparisonOpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected