0

Im so sorry ask this but i have no useful msg after google.

dba prevent slow query affect mysql server, so we need control select statement execute time. I know variable max_execution_time affect that。 but i can not find func in dtabase/sql.go , Who big man can give me some advice

sll0925
  • 3
  • 1

1 Answers1

1

Execute SET max_execution_time=500 as a SQL statement. This limits the following SQL statements on the same connection to 0.5 seconds.

It is also possible as a SQL comment hint like SELECT /*+ MAX_EXECUTION_TIME(1000) */ field1, field2 FROM tbl ... like this answer. If you show details about your slow query in a new question performance improvements may be possible.

danblack
  • 12,130
  • 2
  • 22
  • 41
  • 1
    The "on the same connection" caveat is important. As the go `sql` package uses connection pooling you cannot just `db.Exec("SET max_execution_time=500")` and the expect the next `db.Query` will use the same connection. An alternative is to use `context`. – Brits Feb 25 '22 at 05:42
  • Your hint made me enlightened, thank you – sll0925 Feb 25 '22 at 06:01