| 2313 | } |
| 2314 | |
| 2315 | void StatementGenerator::generateNextCreateTable(RandomGenerator & rg, const bool in_parallel, CreateTable * ct) |
| 2316 | { |
| 2317 | SQLTable next; |
| 2318 | bool has_ttl = false; |
| 2319 | bool added_pkey = false; |
| 2320 | TableEngine * te = ct->mutable_engine(); |
| 2321 | const bool alltables = rg.nextMediumNumber() < 26; |
| 2322 | const bool prev_enforce_final = this->enforce_final; |
| 2323 | const bool prev_allow_not_deterministic = this->allow_not_deterministic; |
| 2324 | |
| 2325 | SQLBase::setDeterministic(fc, rg, next); |
| 2326 | this->allow_not_deterministic = !next.is_deterministic; |
| 2327 | this->enforce_final = next.is_deterministic; |
| 2328 | next.is_temp = fc.allow_memory_tables && rg.nextMediumNumber() < 11; |
| 2329 | ct->set_is_temp(next.is_temp); |
| 2330 | |
| 2331 | const auto tableLikeLambda = [&next, &alltables](const SQLTable & t) |
| 2332 | { return t.isAttached() && (!t.is_temp || alltables) && (t.is_deterministic || !next.is_deterministic); }; |
| 2333 | const auto replaceTableLambda |
| 2334 | = [&next](const SQLTable & t) { return t.isAttached() && !t.hasDatabasePeer() && (t.is_deterministic || !next.is_deterministic); }; |
| 2335 | const bool replace = collectionCount<SQLTable>(replaceTableLambda) > 3 && rg.nextMediumNumber() < 16; |
| 2336 | if (replace) |
| 2337 | { |
| 2338 | const SQLTable & t = rg.pickRandomly(filterCollection<SQLTable>(replaceTableLambda)); |
| 2339 | |
| 2340 | next.db = t.db; |
| 2341 | next.name = t.getBaseName(); |
| 2342 | next.counter = t.counter; |
| 2343 | } |
| 2344 | else |
| 2345 | { |
| 2346 | if ((!next.is_temp || alltables) && collectionHas<std::shared_ptr<SQLDatabase>>(attached_databases) && rg.nextSmallNumber() < 9) |
| 2347 | { |
| 2348 | next.db = rg.pickRandomly(filterCollection<std::shared_ptr<SQLDatabase>>(attached_databases)); |
| 2349 | } |
| 2350 | next.counter = this->table_counter++; |
| 2351 | next.name = rg.nextIdentifier("t", next.counter, fc.allow_nasty_identifiers); |
| 2352 | } |
| 2353 | ct->set_create_opt( |
| 2354 | replace ? (rg.nextBool() ? CreateReplaceOption::CreateOrReplace : CreateReplaceOption::Replace) : CreateReplaceOption::Create); |
| 2355 | next.setName(ct->mutable_est(), false); |
| 2356 | if (!collectionHas<SQLTable>(tableLikeLambda) || rg.nextSmallNumber() < 9) |
| 2357 | { |
| 2358 | /// Create table with definition |
| 2359 | TableDef * colsdef = ct->mutable_table_def(); |
| 2360 | |
| 2361 | getNextTableEngine(rg, !in_parallel, next); |
| 2362 | te->set_engine(next.teng); |
| 2363 | if (!in_parallel) |
| 2364 | { |
| 2365 | getNextPeerTableDatabase(rg, next); |
| 2366 | } |
| 2367 | added_pkey |
| 2368 | |= (!next.isMergeTreeFamily() && !next.isRocksEngine() && !next.isKeeperMapEngine() && !next.isRedisEngine() |
| 2369 | && !next.isMaterializedPostgreSQLEngine()); |
| 2370 | has_ttl = !next.is_deterministic && (next.isMergeTreeFamily() || rg.nextLargeNumber() < 8) && rg.nextBool(); |
| 2371 | |
| 2372 | const bool add_version_to_replacing |
no test coverage detected