MCPcopy Create free account
hub / github.com/apache/cloudberry / scalararraysel_containment

Function scalararraysel_containment

src/backend/utils/adt/array_selfuncs.c:81–236  ·  view source on GitHub ↗

* scalararraysel_containment * Estimate selectivity of ScalarArrayOpExpr via array containment. * * If we have const =/<> ANY/ALL (array_var) then we can estimate the * selectivity as though this were an array containment operator, * array_var op ARRAY[const]. * * scalararraysel() has already verified that the ScalarArrayOpExpr's operator * is the array element type's default equality or

Source from the content-addressed store, hash-verified

79 * Returns selectivity (0..1), or -1 if we fail to estimate selectivity.
80 */
81Selectivity
82scalararraysel_containment(PlannerInfo *root,
83 Node *leftop, Node *rightop,
84 Oid elemtype, bool isEquality, bool useOr,
85 int varRelid)
86{
87 Selectivity selec;
88 VariableStatData vardata;
89 Datum constval;
90 TypeCacheEntry *typentry;
91 FmgrInfo *cmpfunc;
92
93 /*
94 * rightop must be a variable, else punt.
95 */
96 examine_variable(root, rightop, varRelid, &vardata);
97 if (!vardata.rel)
98 {
99 ReleaseVariableStats(vardata);
100 return -1.0;
101 }
102
103 /*
104 * leftop must be a constant, else punt.
105 */
106 if (!IsA(leftop, Const))
107 {
108 ReleaseVariableStats(vardata);
109 return -1.0;
110 }
111 if (((Const *) leftop)->constisnull)
112 {
113 /* qual can't succeed if null on left */
114 ReleaseVariableStats(vardata);
115 return (Selectivity) 0.0;
116 }
117 constval = ((Const *) leftop)->constvalue;
118
119 /* Get element type's default comparison function */
120 typentry = lookup_type_cache(elemtype, TYPECACHE_CMP_PROC_FINFO);
121 if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
122 {
123 ReleaseVariableStats(vardata);
124 return -1.0;
125 }
126 cmpfunc = &typentry->cmp_proc_finfo;
127
128 /*
129 * If the operator is <>, swap ANY/ALL, then invert the result later.
130 */
131 if (!isEquality)
132 useOr = !useOr;
133
134 /* Get array element stats for var, if available */
135 if (HeapTupleIsValid(vardata.statsTuple) &&
136 statistic_proc_security_check(&vardata, cmpfunc->fn_oid))
137 {
138 Form_pg_statistic stats;

Callers 1

scalararrayselFunction · 0.85

Calls 7

examine_variableFunction · 0.85
lookup_type_cacheFunction · 0.85
get_attstatsslotFunction · 0.85
free_attstatsslotFunction · 0.85

Tested by

no test coverage detected