Please answer these questions before submitting your issue. Thanks!
What version of Go and beego are you using (bee version)?
go 1.11.5
beego v1.12.0
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOOS="darwin"
What did you do?
Update to beego version v1.12.0
What did you expect to see?
What did you see instead?
Get error: Error 1461: Can't create more than max_prepared_stmt_count statements
The prepare statement count from database always increase
Check with query
SELECT sp.thread_id, t.processlist_user user, t.processlist_host host,
sp.count_star - sd.count_star open_com_query_ps,
cp.count_star - cc.count_star open_com_prepare_ps
FROM
( SELECT COUNT_STAR,
THREAD_ID
FROM events_statements_summary_by_thread_by_event_name
WHERE event_name = 'statement/sql/prepare_sql' ) sp
JOIN
( SELECT COUNT_STAR,
THREAD_ID
FROM events_statements_summary_by_thread_by_event_name
WHERE event_name = 'statement/com/Prepare' ) cp
ON (cp.THREAD_ID = sp.THREAD_ID)
JOIN
( SELECT COUNT_STAR,
THREAD_ID
FROM events_statements_summary_by_thread_by_event_name
WHERE event_name = 'statement/sql/dealloc_sql' ) sd
ON (sd.THREAD_ID = sp.THREAD_ID)
JOIN
( SELECT COUNT_STAR,
THREAD_ID
FROM events_statements_summary_by_thread_by_event_name
WHERE event_name = 'statement/com/Close stmt' ) cc
ON (cc.THREAD_ID = sp.THREAD_ID)
JOIN threads t ON (t.thread_id = sp.thread_id)
ORDER BY GREATEST(open_com_query_ps, open_com_prepare_ps) DESC;
database: performance_schema
English:
This is the error code, the prepare-stmt opened but not closed.
The author wants to cache stmt and reuse it, but if you use the original query string without a placeholder, then the cache key will be a large number depending on your query parameters.
the current solution is rollback the beego version to 1.11.1
汉语:以下是错误代码,prepare stmt 开启了但是没有关闭。作者想要把prepare stmt 缓存起来重用,但是如果你使用raw qurey,并且没有使用占位符手动拼接的参数的话,prepare的数量将持续增长。目前的解决方案是将beego的版本回退到1.11.1
func (d *DB) getStmt(query string) (*sql.Stmt, error) {
d.RLock()
if stmt, ok := d.stmts[query]; ok {
d.RUnlock()
return stmt, nil
}
d.RUnlock()
stmt, err := d.Prepare(query)
if err != nil {
return nil, err
}
d.Lock()
d.stmts[query] = stmt
d.Unlock()
return stmt, nil
}
Most helpful comment
English:
This is the error code, the prepare-stmt opened but not closed.
The author wants to cache stmt and reuse it, but if you use the original query string without a placeholder, then the cache key will be a large number depending on your query parameters.
the current solution is rollback the beego version to 1.11.1
汉语:以下是错误代码,prepare stmt 开启了但是没有关闭。作者想要把prepare stmt 缓存起来重用,但是如果你使用raw qurey,并且没有使用占位符手动拼接的参数的话,prepare的数量将持续增长。目前的解决方案是将beego的版本回退到1.11.1