There is no upper bound to the time a SQL query can take.  Even a simple 
"select" which requires a full table scan can take hours when run on a 
sufficiently large table.  Ditto a complex "update" command,  or a schema 
modification.

You don't have to apply any time limit at all.  But if you do, it's up to 
you to decide what is sensible in your environment, given the size of your 
dataset and the types of operation you are doing.  You should think about 
*why* you want a timeout at all, and under what situations it would be 
desirable to terminate a query before it has had time to complete - and in 
what situations it would cause problems.

You may also have some implicit timeout in your environment already: e.g. 
if you are handling HTTP requests, and those have their own timeout and run 
within their own context, then you could use the same context for your 
database queries.

On Saturday, 15 January 2022 at 22:20:20 UTC ja7...@gmail.com wrote:

> hi
> I just joined a project and have been reading codes.
>
> dbContext, cancelFunc = context.WithTimeout(context.Background(), 
> 20*time.Minute)
>
> For a database query, I found the context With Time Out, and it has been 
> set to *20 minutes*.
> How much time is appropriate for a timeout query in Go?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7f090163-993d-42bb-8ef0-622446c43f5en%40googlegroups.com.

Reply via email to