←back to thread

175 points frectonz | 2 comments | | HN request time: 0.42s | source

pglite-fusion is a PostgreSQL extension that allows you to embed SQLite databases into your PostgreSQL tables by enabling the creation of columns with the `SQLITE` type. This means every row in the table can have an embedded SQLite database.

In addition to the PostgreSQL `SQLITE` type, pglite-fusion provides the `query_sqlite`` function for querying SQLite databases and the `execute_sqlite` function for updating them. Additional functions are listed in the project’s README.

The pglite-fusion extension is written in Rust using the pgrx framework [1].

----

Implementation Details

The PostgreSQL `SQLITE` type is stored as a CBOR-encoded `Vec<u8>`. When a query is made, this `Vec<u8>` is written to a random file in the `/tmp` directory. SQLite then loads the file, performs the query, and returns the result as a table containing a single row with an array of JSON-encoded values.

The `execute_sqlite` function follows a similar process. However, instead of returning query results, it returns the contents of the SQLite file (stored in `/tmp`) as a new `SQLITE` instance.

[1] https://github.com/pgcentralfoundation/pgrx

Show context
kunley ◴[] No.42184254[source]
Speed, anyone?

How long does it take to update a table of, say, 1k rows? 1m rows? Same when subqueries and joins are involved to calculate what's to be updated?

replies(1): >>42184909 #
1. kevincox ◴[] No.42184909[source]
The current implementation is writing out the DB to `/tmp` then reading the resulting file back and writing it to the column.

So on the bright side updating 1k rows takes the same amount of time as updating one row. On the other hand every write is a full table write (actually two).

I don't think there is a way to do this efficently with the current API as PostgreSQL is MVCC so it needs to write out each version separately (unless it has some sort of support of partial string sharing, I don't think so). Maybe a better version of this would write every page of the SQLite DB as a separate row so that you only need to update the changed pages.

replies(1): >>42186534 #
2. Suppafly ◴[] No.42186534[source]
>The current implementation is writing out the DB to `/tmp` then reading the resulting file back and writing it to the column.

I think there was already another comment where someone told OP how to solve that.