SQLite User Forum

Official support for BEGIN CONCURRENT
Login

Official support for BEGIN CONCURRENT

(1) By Aaron Boodman (aboodman) on 2024-08-03 19:08:41 [link] [source]

Hello, we recently discovered BEGIN CONCURRENT and started investigating its use for a new product (https://zerosync.dev).

To accomplish its work, our product needs to maintain materialized views of large, expensive queries. It's not tractable for us re-run the query each time it is needed. Also, what we really need is the differences in the view, not the view itself (because we will be sending those diffs to the client).

We have developed an approach to maintaining these views efficiently and getting their diffs on top of SQLite (loosely based on https://www.vldb.org/pvldb/vol16/p1601-budiu.pdf). Our approach requires a series of interactive write/read steps – for an incoming write transaction, we write a row to sqlite, do some queries, write another row, do some queries, etc. At the end of these series of steps we have the output that we send to the client and we commit.

Importantly, we cannot do all the writes up front - the correctness of the algorithm requires the write/read interleaving.

This all works, but we'd like to run our IVM on multiple threads to fully utilize server capacity. If we do so naively, we will have to synchronize each thread at the write points of the algorithm which would mitigate much of using multiple threads in the first place. And if we do the writes on each thread, they will take locks in SQLite and conflict.

BEGIN CONCURRENT give us an awesome out of this situation: we can open transactions in parallel, do our write/read pairs, then abort the transactions. Then we just have a single 'writer' transaction that actually flushes the persistent writes to the db at the end.

Thus, I'm very curious if there is any updated information on whether BEGIN CONCURRENT might become officially supported, or anything we can do to influence that.

Thank you!

(2) By Stephan Beal (stephan) on 2024-08-06 11:53:31 in reply to 1 [link] [source]

(With my apologies for the delay.)

I'm very curious if there is any updated information on whether BEGIN CONCURRENT might become officially supported

It's not on any written-down roadmap, but almost nothing is in this project - features get added as they become relevant/interesting...

or anything we can do to influence that.

... or, in some cases, they're sponsored by a 3rd party.

(3.1) By Nuno Cruces (ncruces) on 2024-08-06 18:09:54 edited from 3.0 in reply to 2 [link] [source]

I'll cheat and ask a different question.

For a user that ignores BEGIN CONCURRENT and wal2 how buggy do you expect the bedrock branch to be?

My point is, are these features gated a in a way that (for the most part) they can safely be ignored, or do they change the “core” in ways that are likely to introduce bugs for those that don't use them?

I want to provide a Wasm build a that includes both, and I'm wondering if I should have 2 binaries or just one (where users who value stability can safely ignore the features rather than bundle a different binary).

(4) By Stephan Beal (stephan) on 2024-08-06 18:50:33 in reply to 3.1 [link] [source]

For a user that ignores BEGIN CONCURRENT and wal2 how buggy do you expect the bedrock branch to be?

i happen to know that there is at least one highly-active user of the bedrock branch. As for the wal2 and begin-concurrent branches... no clue.

... or do they change the “core” in ways that are likely to introduce bugs for those that don't use them?

i unfortunately cannot answer that beyond saying that i have no reason to believe that they introduce new bugs in features/subsystems which predate them. That unhelpfully vague, but anything more specific would be pure speculation on my part.

(5) By Nuno Cruces (ncruces) on 2024-08-06 19:10:36 in reply to 4 [link] [source]

Thanks! I wasn't expecting any promises, as that's unrealistic. So this is really the best I could hope for.

(6) By ddevienne on 2024-08-07 06:59:24 in reply to 4 [link] [source]

Lets ask the question a little differently.

SQLite has very strong testing guarantees for its main branch.

Do these guarantees extend to other branches? These two branches?

(7) By Stephan Beal (stephan) on 2024-08-07 09:29:37 in reply to 6 [link] [source]

Do these guarantees extend to other branches?

Not specifically, no - we'd be doing little more running tests if that were the case.

These two branches?

No clue - my involvement with those features is only as an idle observer.

(8) By Nuno Cruces (ncruces) on 2024-08-09 09:13:59 in reply to 4 [source]

Just FYI, I don't know how relevant you think this is, but building from the bedrock branch (specifically bedrock-3.46).

I'm getting these warnings (no warnings at all building from main):

build/sqlite3.c:70209:46: warning: comparison of integers of different signs: 'int' and 'u32' (aka 'unsigned int') [-Wsign-compare]
 70209 |         for(iHash=walFramePage(iFirst); iHash<=iLastHash; iHash += (1+bWal2)){
       |                                         ~~~~~^ ~~~~~~~~~
build/sqlite3.c:70492:18: warning: comparison of integers of different signs: 'u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
 70492 |   if( aWalData[3]!=iCmp ){
       |       ~~~~~~~~~~~^ ~~~~
build/sqlite3.c:70542:43: warning: comparison of integers of different signs: 'u32' (aka 'unsigned int') and 'int' [-Wsign-compare]
 70542 |      && walidxGetMxFrame(&pWal->hdr, iApp)>=nWalSize
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ ~~~~~~~~
build/sqlite3.c:84497:27: warning: comparison of integers of different signs: 'Pgno' (aka 'unsigned int') and 'int' [-Wsign-compare]
 84497 |             if( pTab->tnum==(int)pgnoRoot ){
       |                 ~~~~~~~~~~^ ~~~~~~~~~~~~~
build/sqlite3.c:84503:31: warning: comparison of integers of different signs: 'Pgno' (aka 'unsigned int') and 'int' [-Wsign-compare]
 84503 |                 if( pIdx->tnum==(int)pgnoRoot ){
       |                     ~~~~~~~~~~^ ~~~~~~~~~~~~~

(9) By Stephan Beal (stephan) on 2024-08-09 10:54:21 in reply to 8 [link] [source]

I'm getting these warnings...

Those are resolved now in the bedrock and (where relevant) begin-concurrent branches. Thank you for the report.

(10) By anonymous on 2024-10-25 20:03:08 in reply to 9 [link] [source]

Hi Stephan! Any updates on the "BEGIN CONCURRENT" feature?

(11) By Stephan Beal (stephan) on 2024-10-25 20:43:51 in reply to 10 [link] [source]

Any updates on the "BEGIN CONCURRENT" feature?

My initial response still applies to that one:

It's not on any written-down roadmap.

That branch, like several others, continues to get actively updated from trunk, but there are currently no concrete plans to merge them to the trunk.

(12) By Nuno Cruces (ncruces) on 2024-10-26 00:39:11 in reply to 3.1 [link] [source]

Just as a follow-up, if you're using Go, I make the bedrock branch easy to test.