Skip to content
Merged
Changes from 1 commit
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: 16 additions & 2 deletions sqlite3_opt_vtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,22 @@ func goVBestIndex(pVTab unsafe.Pointer, icp unsafe.Pointer) *C.char {
if res.AlreadyOrdered {
info.orderByConsumed = C.int(1)
}
info.estimatedCost = C.double(res.EstimatedCost)
info.estimatedRows = C.sqlite3_int64(res.EstimatedRows)
// SQLite pre-initializes estimatedCost and estimatedRows with sensible
// defaults; overwriting them with the Go zero value would make every
// candidate plan look free and break query planning, so only pass
// values the implementation actually set.
if res.EstimatedCost > 0 {
info.estimatedCost = C.double(res.EstimatedCost)
}
if res.EstimatedRows > 0 {
var rows int64
if res.EstimatedRows >= float64(math.MaxInt64) {
rows = math.MaxInt64
} else {
rows = int64(res.EstimatedRows)
}
info.estimatedRows = C.sqlite3_int64(rows)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

return nil
}
Expand Down
Loading