MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / OperatorIsImmutable

Function OperatorIsImmutable

pkg/sql/sem/tree/constant_eval.go:17–38  ·  view source on GitHub ↗

OperatorIsImmutable returns true if the given expression corresponds to a constant operator. Note importantly that this will return true for all expr types other than FuncExpr, CastExpr, UnaryExpr, BinaryExpr, and ComparisonExpr. It does not do any recursive searching.

(expr Expr)

Source from the content-addressed store, hash-verified

15// expr types other than FuncExpr, CastExpr, UnaryExpr, BinaryExpr, and
16// ComparisonExpr. It does not do any recursive searching.
17func OperatorIsImmutable(expr Expr) bool {
18 switch t := expr.(type) {
19 case *FuncExpr:
20 return t.ResolvedOverload().Class == NormalClass && t.fn.Volatility <= volatility.Immutable
21
22 case *CastExpr:
23 v, ok := cast.LookupCastVolatility(t.Expr.(TypedExpr).ResolvedType(), t.typ)
24 return ok && v <= volatility.Immutable
25
26 case *UnaryExpr:
27 return t.op.Volatility <= volatility.Immutable
28
29 case *BinaryExpr:
30 return t.Op.Volatility <= volatility.Immutable
31
32 case *ComparisonExpr:
33 return t.Op.Volatility <= volatility.Immutable
34
35 default:
36 return true
37 }
38}

Callers

nothing calls this directly

Calls 3

LookupCastVolatilityFunction · 0.92
ResolvedOverloadMethod · 0.80
ResolvedTypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…