MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / do_check

Method do_check

sql/sys_vars.h:141–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139 DBUG_ASSERT(def_val % block_size == 0);
140 }
141 bool do_check(THD *thd, set_var *var)
142 {
143 my_bool fixed= FALSE;
144 longlong v;
145 ulonglong uv;
146 const T *vmin, *vmax;
147
148 v= var->value->val_int();
149 if (SIGNED) /* target variable has signed type */
150 {
151 if (var->value->unsigned_flag)
152 {
153 /*
154 Input value is such a large positive number that MySQL used an
155 unsigned item to hold it. When cast to a signed longlong, if the
156 result is negative there is "cycling" and this is incorrect (large
157 positive input value should not end up as a large negative value in
158 the session signed variable to be set); instead, we need to pick the
159 allowed number closest to the positive input value, i.e. pick the
160 biggest allowed positive integer.
161 */
162 if (v < 0)
163 uv= max_of_int_range(ARGT);
164 else /* no cycling, longlong can hold true value */
165 uv= (ulonglong) v;
166 }
167 else
168 uv= v;
169 /* This will further restrict with VALID_RANGE, BLOCK_SIZE */
170 var->save_result.ulonglong_value=
171 getopt_ll_limit_value(uv, &option, &fixed);
172 }
173 else
174 {
175 if (var->value->unsigned_flag)
176 {
177 /* Guaranteed positive input value, ulonglong can hold it */
178 uv= (ulonglong) v;
179 }
180 else
181 {
182 /*
183 Maybe negative input value; in this case, cast to ulonglong makes it
184 positive, which is wrong. Pick the closest allowed value i.e. 0.
185 */
186 uv= (ulonglong) (v < 0 ? 0 : v);
187 }
188 var->save_result.ulonglong_value=
189 getopt_ull_limit_value(uv, &option, &fixed);
190 }
191
192 if (max_var_ptr())
193 {
194 /* check constraint set with --maximum-...=X */
195 if (SIGNED)
196 {
197 longlong max_val= *max_var_ptr();
198 if (((longlong)(var->save_result.ulonglong_value)) > max_val)

Callers

nothing calls this directly

Calls 7

max_of_int_rangeFunction · 0.85
getopt_ll_limit_valueFunction · 0.85
getopt_ull_limit_valueFunction · 0.85
throw_bounds_warningFunction · 0.85
val_intMethod · 0.45

Tested by

no test coverage detected