| 30 | } |
| 31 | |
| 32 | BlockIO InterpreterAdviseQuery::execute() |
| 33 | { |
| 34 | Block advise_result{ |
| 35 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "database"}, |
| 36 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "table"}, |
| 37 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "column"}, |
| 38 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "advise_type"}, |
| 39 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "original"}, |
| 40 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "optimized"}, |
| 41 | ColumnWithTypeAndName{std::make_shared<DataTypeString>(), "status"}}; |
| 42 | Block optimized_ddls_result = advise_result.cloneEmpty(); |
| 43 | auto advise_result_columns = advise_result.mutateColumns(); |
| 44 | auto optimized_ddls_columns = optimized_ddls_result.mutateColumns(); |
| 45 | |
| 46 | std::vector<String> queries = loadQueries(); |
| 47 | WorkloadTables tables = loadTables(); |
| 48 | |
| 49 | auto start_watch = std::chrono::high_resolution_clock::now(); |
| 50 | Advisor advisor(query_ptr->as<const ASTAdviseQuery &>().type); |
| 51 | auto advises = advisor.analyze(queries, getContext()); |
| 52 | auto stop_watch = std::chrono::high_resolution_clock::now(); |
| 53 | |
| 54 | LOG_DEBUG(&Poco::Logger::get("InterpreterAdviseQuery"), "Analyze cost: {} ms", |
| 55 | std::chrono::duration_cast<std::chrono::milliseconds>(stop_watch - start_watch).count()); |
| 56 | |
| 57 | start_watch = std::chrono::high_resolution_clock::now(); |
| 58 | |
| 59 | for (auto & advise : advises) |
| 60 | { |
| 61 | String result = advise->apply(tables); |
| 62 | |
| 63 | advise_result_columns[0]->insert(advise->getTable().database); |
| 64 | advise_result_columns[1]->insert(advise->getTable().table); |
| 65 | advise_result_columns[2]->insert(advise->getColumnName().value_or("")); |
| 66 | advise_result_columns[3]->insert(advise->getAdviseType()); |
| 67 | advise_result_columns[4]->insert(advise->getOriginalValue()); |
| 68 | advise_result_columns[5]->insert(advise->getOptimizedValue()); |
| 69 | advise_result_columns[6]->insert(result); |
| 70 | } |
| 71 | |
| 72 | stop_watch = std::chrono::high_resolution_clock::now(); |
| 73 | |
| 74 | LOG_DEBUG(&Poco::Logger::get("InterpreterAdviseQuery"), "Apply advises cost: {} ms", |
| 75 | std::chrono::duration_cast<std::chrono::milliseconds>(stop_watch - start_watch).count()); |
| 76 | |
| 77 | if (query_ptr->as<const ASTAdviseQuery &>().output_ddl) |
| 78 | { |
| 79 | start_watch = std::chrono::high_resolution_clock::now(); |
| 80 | |
| 81 | std::vector<std::pair<QualifiedTableName, String>> optimized_ddls = tables.getOptimizedDDLs(); |
| 82 | |
| 83 | auto optimized_file = query_ptr->as<const ASTAdviseQuery &>().optimized_file; |
| 84 | if (optimized_file) |
| 85 | { |
| 86 | std::vector<String> ddls; |
| 87 | for (const auto & item : optimized_ddls) |
| 88 | ddls.emplace_back(item.second); |
| 89 | write(optimized_file.value(), ddls); |
nothing calls this directly
no test coverage detected