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

cgosqlite: implement BulkQuery/BulkExec #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

crawshaw
Copy link
Member

No description provided.

Designed to minimize allocations and cgo calls.
API requires no allocations to INSERT or SELECT.
(Apparently there is still one allocation, somewhere.)

All cgo calls are amortized across rows.
@crawshaw crawshaw requested a review from bradfitz May 31, 2022 13:35
Copy link
Member

@bradfitz bradfitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have more questions but probably best to just talk to you on a call.

func NewBulkQuery(stmt *Stmt) (*BulkQuery, error) {
b := &BulkQuery{
bulkStmt: newBulkStmt(stmt),
dataText: make([]byte, 1<<16),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only do shifts of 10 (KiB), 20 (MiB), etc.

so 64 << 10. (64 KiB)

Comment on lines +181 to +183
func (b *BulkQuery) resizeDataText() {
b.dataText = append(b.dataText, make([]byte, len(b.dataText))...)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than resizing this and generating garbage, my plan was for the C layer to signal to Go that the row won't fit and that it should be accessed using the C sqlite3 interface instead.

but because of where I was putting this, in Stmt, it wasn't extra work, because the C calls were already there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of the way the iterator works, if a column doesn't fit, the row is punted to the next time the bulk query is run. so the only time dataText gets expanded is if someone tries to read a row more than 16kb, which generally shouldn't happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants