MCPcopy Create free account
hub / github.com/anse1/sqlsmith / atomic_subselect

Method atomic_subselect

expr.cc:278–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278atomic_subselect::atomic_subselect(prod *p, sqltype *type_constraint)
279 : value_expr(p), offset((d6() == 6) ? d100() : d6())
280{
281 match();
282 if (d6() < 3) {
283 if (type_constraint) {
284 auto idx = scope->schema->aggregates_returning_type;
285 auto iters = idx.equal_range(type_constraint);
286 agg = random_pick(random_pick(iters)->second);
287 } else {
288 agg = &random_pick<>(scope->schema->aggregates);
289 }
290 if (agg->argtypes.size() != 1)
291 agg = 0;
292 else
293 type_constraint = agg->argtypes[0];
294 } else {
295 agg = 0;
296 }
297
298 if (type_constraint) {
299 auto idx = scope->schema->tables_with_columns_of_type;
300 col = 0;
301 auto iters = idx.equal_range(type_constraint);
302 tab = random_pick(random_pick(iters)->second);
303
304 for (auto &cand : tab->columns()) {
305 if (type_constraint->consistent(cand.type)) {
306 col = &cand;
307 break;
308 }
309 }
310 assert(col);
311 } else {
312 tab = &random_pick<>(scope->schema->tables);
313 col = &random_pick<>(tab->columns());
314 }
315
316 type = agg ? agg->restype : col->type;
317}
318
319void atomic_subselect::out(std::ostream &out)
320{

Callers

nothing calls this directly

Calls 4

d6Function · 0.85
d100Function · 0.85
random_pickFunction · 0.85
consistentMethod · 0.45

Tested by

no test coverage detected