Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not skip metadata when quering SELECT * FROM ... #275

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ func (s *Session) SetTrace(trace Tracer) {
s.mu.Unlock()
}

var selectWildcardNextWarning int64

func warnSelectWildcardStartPerformanceIssue() {
now := time.Now().Unix()
if atomic.LoadInt64(&selectWildcardNextWarning) < now {
atomic.StoreInt64(&selectWildcardNextWarning, now+60)
Logger.Println("warning: skipping metadata is disabled for `SELECT * FROM ...` queries due to potential correctness issues when altering the table. This may cause a decrease in performance. It is recommended to avoid using `SELECT * FROM ...` and provide specific column names.")
mykaul marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Query generates a new query object for interacting with the database.
// Further details of the query may be tweaked using the resulting query
// value before the query is executed. Query is automatically prepared
Expand All @@ -483,6 +493,10 @@ func (s *Session) Query(stmt string, values ...interface{}) *Query {
qry := queryPool.Get().(*Query)
qry.session = s
qry.stmt = stmt
if !qry.disableSkipMetadata && strings.HasPrefix(strings.ToLower(stmt), "select *") {
sylwiaszunejko marked this conversation as resolved.
Show resolved Hide resolved
qry.disableSkipMetadata = true
warnSelectWildcardStartPerformanceIssue()
}
qry.values = values
qry.defaultsFromSession()
qry.routingInfo.lwt = false
Expand All @@ -506,6 +520,10 @@ func (s *Session) Bind(stmt string, b func(q *QueryInfo) ([]interface{}, error))
qry := queryPool.Get().(*Query)
qry.session = s
qry.stmt = stmt
if !qry.disableSkipMetadata && strings.HasPrefix(strings.ToLower(stmt), "select *") {
qry.disableSkipMetadata = true
warnSelectWildcardStartPerformanceIssue()
}
qry.binding = b
qry.defaultsFromSession()
qry.routingInfo.lwt = false
Expand Down
Loading