You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any plan for support of canceling with context?
This feature is implemented on other database/sql drivers like on this one for PG.
A common scenario for the usage of this feature is when a user closes the request but the query remains on running state and it will cause to occupying system resources on heavy queries.
The text was updated successfully, but these errors were encountered:
@meysampg I have a similar use case, and this is what I'm currently doing that gets the job done, hope it helps!
funcdoQuery(ctx context.Context, db*sql.DB, querystring) error {
// prepend a unique identifier to the query stringquery=fmt.Sprintf("/* my-program-%s */ %s", generateID(), query)
rows, err:=db.QueryContext(ctx, query)
iferr!=nil {
// ...
}
deferrows.Close()
// Grab the ID of the query from the runtime table that stores all active running queries// This is why we used the unique identifier, so that way two queries with the same SQL won't// collide on this table.varqueryIDstringiferr:= db.QueryRow("SELECT query_id FROM system.runtime.queries WHERE query = ?', query).Scan(&queryID); err != nil {
// ...
}
forrows.Next() {
// do what you will
}
// Handle the error returned from context cancellation and deadline expiration separately// from normal errors so we can run the cancel logic.// Can even handle them separately if you'd like.iferr:=rows.Err(); err==context.Canceled||err==context.DeadlineExceeded {
killQuery:=fmt.Sprintf("CALL system.runtime.kill_query('%s')", queryID)
iferr:=db.Exec(killQuery); err!=nil {
// something went wrong cancellingreturnerr
}
} elseiferr!=nil {
// all other errorsreturnerr
}
returnnil
}
Is there any plan for support of canceling with context?
This feature is implemented on other
database/sql
drivers like on this one for PG.A common scenario for the usage of this feature is when a user closes the request but the query remains on running state and it will cause to occupying system resources on heavy queries.
The text was updated successfully, but these errors were encountered: