如何在不断开连接的情况下使用 Node.js 终止 MySQL 查询?

How to kill a MySQL query with Node.js without disconnecting?

上下文: 我正在构建一个从大型数据库调用数据的 Web 应用程序(table 有数百万行);有时用户可以改变主意并在数据库查询完成之前调用新数据。

技术问题: 在这种情况下,我尝试使用以下方法终止查询:

app.get("/data", function(req, res) {
    if (req.query.killQuery == "true") {
        con.query("KILL \"" + threadId + "\"", function(err) {
            if (err) throw err;
            console.log("I have interrupted the executing query for a new request");
            giveData(req, res); //The function that will execute a new query
        }); 
        return;
    }
    giveData(req, res); //The function that will execute a new query
});

现在我对这段代码有几点疑惑:

如果您使用的是 MySQL 的现代版本,则可以使用 KILL QUERY <threadId> 代替,这将 终止该连接上当前正在执行的查询,但离开连接完好。