villadragon.blogg.se

Rust sqlite example
Rust sqlite example









rust sqlite example

This is a little bit frustrating because we have to manually adjust the format of the test files, for example, in some cases like these: Our first version of sqllogictest doesn't strictly follow the sqllogictest wiki. The Python sqllogictest had been experiencing suboptimal runtime that resulted in a slower CI. We expected a 10x performance boost from the switch to Rust.As the sqllogictest-rs crate is maturing, building a new sqllogictest framework based on it would save us a lot of effort in the long run.The previous framework lacked a strict parser at the front end and resulted in errors going undetected.Working with a unified codebase written in Rust would boost our productivity over the long term. The entire Databend team is proficient in Rust.We planned a switch to sqllogictest-rs for the following reasons: The original sqllogictest framework ( RFC for sqllogictest) was written in Python. This is done by comparing query results from multiple SQL engines running the same query. Benefiting from its neutrality towards database engines, we can use Sqllogictest to verify the accuracy of a SQL database engine as well.

rust sqlite example

Sqllogictest was designed with SQLite in mind. We successfully switched the sqllogictest framework from Python to Rust using sqllogictest-rs, a robust implementation of the sqllogictest framework for the Rust ecosystem. This post is about a big move we've made for Databend. Std::cout << "Inserted " << count << " records in " << elapsed << " seconds, at a rate of " << rate << " records per second.Rewriting sqllogictest Framework with Rust Sqlite3_exec(db, "BEGIN", nullptr, nullptr, nullptr) Īuto start = std::chrono::steady_clock::now() ĭouble rate = static_cast(count) / elapsed Sqlite3_exec(db, sql, nullptr, nullptr, nullptr) G++ sqlitetest.cpp -lsqlite3 -luuid -o sqlitetestĬonst char *sql = "CREATE TABLE IF NOT EXISTS users (" I've made a tiny attempt to optimise - likely much more can be done. Inserted 1500000 records in 9 seconds, at a rate of 166667 records per second.Ĭredit goes not to me but to everyone's favorite AI programmer. Inserted 1500000 records in 13 seconds, at a rate of 115385 records per second.

rust sqlite example

Of course there is "lies, damned lies and benchmarks". Here is a totally unscientific benchmark in C++.

rust sqlite example

TLDR: C++ is 115K inserts/sec to 166K inserts/sec Sqlite> insert into users(created_at, username) select strftime('%Y-%m-%dT%H:%M:%fZ'), 'hello' from generate_series limit 100000 In the interest of finding where the bulk of the time is spent and on a hunch I tried swapping the UUID for plain auto-incrementing primary keys as well: It is possible further pragma-tweaking might eke out further performance but I feel like this representative of the no-optimization scenario I typically find myself in. Where the UUID extension comes from the SQLite authors and generate_series is compiled into the SQLite CLI. Sqlite> insert into users(id, created_at, username) Sqlite> create unique index idx_users_on_id on users(id) Sqlite> create table users (id blob primary key not null, created_at text not null, username text not null) The approach here is so similar I tried my prior solution on the slowest VPS I have access to (1 vCPU core 2.4GHz, 512Mi, $2.50/month from vultr): This reminded me of a prior discussion on bulk data generation in SQLite with Rust (vs Python vs PyPy) which previously led me to trying out two different techniques using just SQLite.











Rust sqlite example