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

SQL Updates #92

Open
BackInFiveMinutes opened this issue Jun 30, 2024 · 4 comments
Open

SQL Updates #92

BackInFiveMinutes opened this issue Jun 30, 2024 · 4 comments

Comments

@BackInFiveMinutes
Copy link

Brilliant library and really appriciate it. I have an issue with my code which hopefully someone can help

I have a small databast circa 170K in size. There is a config table of around 40 rows, no indexing. It takes me arounf 8 seconds to perform a SQL update which is pretty slow.

If I use SQLite Expert to perform the same update, the time is around 20ms.

I used this example
https://github.com/siara-cc/esp32_arduino_sqlite3_lib/blob/master/examples/sqlite3_littlefs/sqlite3_littlefs.ino
and pointed to my database and added a SQL update

This reproduces the same (slow) SQL update.

So do I have to live woth the slow SQL updates or is there something I can do that will speed the SQL updates up.

As a side note I am definatly an amateur with coding!

Thanks for reading

Garry

@siara-cc
Copy link
Owner

siara-cc commented Jul 1, 2024

8 seconds sounds quite high for a 40 row table on LITTLEFS, unless the row length is huge and all rows are updated.

@siara-cc
Copy link
Owner

siara-cc commented Jul 1, 2024

I think the issue you are facing is unusual so need more info or a reproducible sample to suggest further opinion.

@BackInFiveMinutes
Copy link
Author

Hi Arun

Thanks for taking the trouble to look at this issue

I have created a sample code snippet which is largly based on your littlefs example

In my sample I test two databases

The first, small database has only one table, tblConfig in it and 2 columns.
The second is larger, it still has tblConfig in it plus many other tables, which are not used in this sample.
Both databases were Vacuumed

I found that wrapping the UPDATE query within a transaction significaly improved the update speed.

What you will see when running the sample code is

  1. The smaller the database the faster the UPDATES are, irrespective of wrapping in a transaction
  2. Wrapping the UPDATE in a transaction is always faster.

So is it best practice to use transactions when updating? (My gut feeling is that is shouldn't matter in this case)

Also do you expect the size of the database to impact the UPDATE, even though the UPDATE is not affecting any of those extra tables?

main.zip
platformio.zip
data.zip

I've zipped up the code, the two sample databases and the platformm.ini. If there's anything else you need please let me know
Again, thanks for you help

Garry

@siara-cc
Copy link
Owner

siara-cc commented Jul 5, 2024

@BackInFiveMinutes I am having trouble loading the data onto the board, so unable to test what you have provided.

It may help to try using Prepared Statements instead of plain SQL statements and using a WITHOUT ROWID table.
Also the page size used is 4096. Please try using 512 page size (PRAGMA page_size 512; VACUUM;)

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

No branches or pull requests

2 participants