MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / normalize

Method normalize

pkg/sql/sem/tree/normalize.go:117–166  ·  view source on GitHub ↗
(v *NormalizeVisitor)

Source from the content-addressed store, hash-verified

115}
116
117func (expr *BinaryExpr) normalize(v *NormalizeVisitor) TypedExpr {
118 left := expr.TypedLeft()
119 right := expr.TypedRight()
120 expectedType := expr.ResolvedType()
121
122 if !expr.fn.NullableArgs && (left == DNull || right == DNull) {
123 return DNull
124 }
125
126 var final TypedExpr
127
128 switch expr.Operator {
129 case Plus:
130 if v.isNumericZero(right) {
131 final = ReType(left, expectedType)
132 break
133 }
134 if v.isNumericZero(left) {
135 final = ReType(right, expectedType)
136 break
137 }
138 case Minus:
139 if types.IsAdditiveType(left.ResolvedType()) && v.isNumericZero(right) {
140 final = ReType(left, expectedType)
141 break
142 }
143 case Mult:
144 if v.isNumericOne(right) {
145 final = ReType(left, expectedType)
146 break
147 }
148 if v.isNumericOne(left) {
149 final = ReType(right, expectedType)
150 break
151 }
152 // We can't simplify multiplication by zero to zero,
153 // because if the other operand is NULL during evaluation
154 // the result must be NULL.
155 case Div, FloorDiv:
156 if v.isNumericOne(right) {
157 final = ReType(left, expectedType)
158 break
159 }
160 }
161
162 if final == nil {
163 return expr
164 }
165 return final
166}
167
168func (expr *AndExpr) normalize(v *NormalizeVisitor) TypedExpr {
169 left := expr.TypedLeft()

Callers

nothing calls this directly

Calls 7

TypedLeftMethod · 0.95
TypedRightMethod · 0.95
IsAdditiveTypeFunction · 0.92
ReTypeFunction · 0.85
isNumericZeroMethod · 0.80
isNumericOneMethod · 0.80
ResolvedTypeMethod · 0.65

Tested by

no test coverage detected