| 204 | |
| 205 | |
| 206 | BlockIO InterpreterKillQueryQuery::execute() |
| 207 | { |
| 208 | const auto & query = query_ptr->as<ASTKillQueryQuery &>(); |
| 209 | |
| 210 | if (!query.cluster.empty()) |
| 211 | { |
| 212 | DDLQueryOnClusterParams params; |
| 213 | params.access_to_check = getRequiredAccessForDDLOnCluster(); |
| 214 | return executeDDLQueryOnCluster(query_ptr, getContext(), params); |
| 215 | } |
| 216 | |
| 217 | BlockIO res_io; |
| 218 | switch (query.type) |
| 219 | { |
| 220 | case ASTKillQueryQuery::Type::Query: |
| 221 | { |
| 222 | Block processes_block = getSelectResult("query_id, user, query", "system.processes"); |
| 223 | if (processes_block.empty()) |
| 224 | return res_io; |
| 225 | |
| 226 | ProcessList & process_list = getContext()->getProcessList(); |
| 227 | QueryDescriptors queries_to_stop = extractQueriesExceptMeAndCheckAccess(processes_block, getContext()); |
| 228 | |
| 229 | auto header = processes_block.cloneEmpty(); |
| 230 | header.insert(0, {ColumnString::create(), std::make_shared<DataTypeString>(), "kill_status"}); |
| 231 | |
| 232 | if (!query.sync || query.test) |
| 233 | { |
| 234 | MutableColumns res_columns = header.cloneEmptyColumns(); |
| 235 | for (const auto & query_desc : queries_to_stop) |
| 236 | { |
| 237 | if (!query.test) |
| 238 | LOG_DEBUG(getLogger("KillQuery"), "Will kill query {} (asynchronously)", query_desc.query_id); |
| 239 | auto code = (query.test) ? CancellationCode::Unknown : process_list.sendCancelToQuery(query_desc.query_id, query_desc.user); |
| 240 | insertResultRow(query_desc.source_num, code, processes_block, header, res_columns); |
| 241 | } |
| 242 | |
| 243 | res_io.pipeline = QueryPipeline(std::make_shared<SourceFromSingleChunk>(std::make_shared<const Block>(header.cloneWithColumns(std::move(res_columns))))); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | res_io.pipeline = QueryPipeline(std::make_shared<SyncKillQuerySource>( |
| 248 | process_list, std::move(queries_to_stop), std::move(processes_block), std::make_shared<const Block>(header))); |
| 249 | } |
| 250 | |
| 251 | break; |
| 252 | } |
| 253 | case ASTKillQueryQuery::Type::Mutation: |
| 254 | { |
| 255 | Block mutations_block = getSelectResult("database, table, mutation_id, command", "system.mutations"); |
| 256 | if (mutations_block.empty()) |
| 257 | return res_io; |
| 258 | |
| 259 | const ColumnString & database_col = typeid_cast<const ColumnString &>(*mutations_block.getByName("database").column); |
| 260 | const ColumnString & table_col = typeid_cast<const ColumnString &>(*mutations_block.getByName("table").column); |
| 261 | const ColumnString & mutation_id_col = typeid_cast<const ColumnString &>(*mutations_block.getByName("mutation_id").column); |
| 262 | const ColumnString & command_col = typeid_cast<const ColumnString &>(*mutations_block.getByName("command").column); |
| 263 |
nothing calls this directly
no test coverage detected