Preparestmt use LRU Map instead default map#7435
Merged
Conversation
jinzhu
reviewed
Apr 24, 2025
gorm.go
Outdated
| callbacks *callbacks | ||
| cacheStore *sync.Map | ||
| } | ||
| type PrepareStmtLruConfig struct { |
jinzhu
reviewed
Apr 24, 2025
gorm.go
Outdated
| preparedStmt = v.(*PreparedStmtDB) | ||
| } else { | ||
| preparedStmt = NewPreparedStmtDB(db.ConnPool) | ||
| preparedStmt = NewPreparedStmtDB(db.ConnPool, db.Config.PrepareStmtMaxSize, db.Config.PrepareStmtTTL) |
Member
There was a problem hiding this comment.
Do we need to allow session-level configuration? For example, configure it here: https://github.com/go-gorm/gorm/blob/master/gorm.go#L107
Contributor
Author
There was a problem hiding this comment.
if config.PrepareStmt {
preparedStmt := NewPreparedStmtDB(db.ConnPool, config.PrepareStmtMaxSize, config.PrepareStmtTTL)
db.cacheStore.Store(preparedStmtDBKey, preparedStmt)
db.ConnPool = preparedStmt
}
session default use static config
jinzhu
reviewed
Apr 24, 2025
prepare_stmt.go
Outdated
| } | ||
|
|
||
| func NewPreparedStmtDB(connPool ConnPool) *PreparedStmtDB { | ||
| const DEFAULT_MAX_SIZE = (1 << 63) - 1 |
Member
There was a problem hiding this comment.
Could we relocate the majority of the following code to an internal package, such as internal/stmt_store, to prevent the exposure of additional structs or methods?
Contributor
Author
There was a problem hiding this comment.
cause circular dependency
…o feature/sup_lru_prepareStmt
Contributor
|
Build failed in 32bit environment GOARCH=386 go test -timeout 20m -v ./...
shell: /usr/bin/bash -e {0}
# gorm.io/gorm/internal/stmt_store
Error:
../../../go/pkg/mod/gorm.io/[email protected]/internal/stmt_store/stmt_store.go:99:10:
cannot use defaultMaxSize (untyped int constant 9223372036854775807) as int value in assignment (overflows) |
iTanken
added a commit
to iTanken/gorm
that referenced
this pull request
Apr 27, 2025
3 tasks
jinzhu
pushed a commit
that referenced
this pull request
Apr 27, 2025
|
We've just hit this as well in #7442. A .1 release would be highly appreciated. |
phroggyy
pushed a commit
to incident-io/gorm
that referenced
this pull request
Jan 23, 2026
* 支持lru淘汰preparestmt cache * 支持lru淘汰preparestmt cache * 支持lru淘汰preparestmt cache * 只使用lru * 只使用lru * 只使用lru * 只使用lru * 只使用lru * 只使用lru * 只使用lru * 只使用lru * 只使用lru * change const export * Add stmt_store * refact prepare stmt store * Rename lru store * change const export * ADD UT * format code and add session level prepare stmt config * code format according to golinter ci * ADD UT --------- Co-authored-by: xiezhaodong <[email protected]> Co-authored-by: Jinzhu <[email protected]>
phroggyy
pushed a commit
to incident-io/gorm
that referenced
this pull request
Jan 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GROM default map may be cause memory leak
What did this pull request do?
PrepareStmt support use lrumap instead default Map
PreparedStmtDB stmt change to interface to defined maps
User Case Description
TestPreparedStmtLruFromTransaction check lru active