Open Fischkopppp opened 2 years ago
In SQLite, tables are also indexes which have the primary key as ROWID, which is invisible. So if you are updating using mac_id upon conflict, it would have no choice other than searching the table sequentially. I would suggest using without rowid
clause to force mac_id as primary key of the table instead of ROWID to improve speed. Example:
create table t1 (c1 primary key, c2, c3) without rowid;
insert into t1 values ('v1', 'v2', 'v3');
insert into t1 values ('v1', 'v2', 'v3') on conflict (c1) do update set c3= 'v4'
For using the FRAM you would have to change esp32.c to write to FRAM using API for whatever file system it supports. If it is raw data storage then you would have to implement your own way of storing and retrieving files.
Alternatively you could also look at https://github.com/siara-cc/sqlite_micro_logger_arduino which has callback methods for IO which lets you store/retrieve from whichever storage medium as you please. However there are a lot of limitations. SQL not supported. It was made mainly for storing sensor data.
Hi Arun, your suggestions made it a tiny bit faster ;) However I don't think I can make it any quicker with a SPI SD configuration. The real deal breaker seems to use a SD MMC configuration. I wrote a little program that fetch information from the SQL database, stores them in variables, shows them on a serial Monitor. And afterwards manipulates the SQL data to change the output in the next loop run. I am using two SQL prepare statements (one for SELECT + JOIN) and one for (UPDATE to manipulate by random). With an SD SPI card and about 40 rows / 7 columns it took about 5 to 7 second. While the sqlite3_step(res) part runs quite fast (a few Milliseconds). Before and after that it took quite some time to process the statements (between 2 - 4 seconds). My goal is to use the SQL database for graphical information. Storing all graphical information in the database and to be able to manipulate it with a PC via SD Card.
BUT ;-) If I use ESP32 with an SD MMC configuration the whole process takes 400 milliseconds without a "Begin Transaction" statement in the setup. Instead of 5 to 7 seconds! Using the "Begin Transaction" the total time needed shrinks to 30 milliseconds! That is great! ON CONFLICT (...) DO UPDATE statements are also much, much faster with an SD MMC configuration. In the case of the example in my first post I can "upsert" instead of 22 rows per seconds about 400 to 500 rows per second.
Summary: SPI SD = 5000-7000 milisec. SDMMC without transaction: 400 milisec. SDMMC with transaction: 30 milisec! (22 for Select+Join and 8 for Update)
This brings me to another question. Where the hell do I get ESP32 boards with SDMMC configuration?! ;-). I have tried to find the board from your picture without success. I have also tried soooo many boards that on paper looked promising. I also tried the Waveshare Micro SD Storage Board, that has all the right resistors in place. However I was not able to get it running. Only the AI-Thinker ESP32-CAM is working out of the box. Is it possible to change the pin mapping for SD MMC? I would like to try the layout from the ESP32 documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html
Thanks for sharing your experience!! I purchased the esp32+sdmmc board from banggood.com but I am unable to find it now either.
Should I close this issue? Or should I let it open? By the way. I copied the database to spiff and tried the SPIFF and LITTLEFS library. Without the "Begin Transaction" statement updates were quite slow (nearly a second for each row). With it I am getting the following results:
total time for all processes (described in the post above:Select+Join & Update) spiff with SPIFF library; 350ms (very inconsistent between 170 to 500ms) spiff with LITTLEFS library: 140ms (very consistent between 135 to 145ms: about 6ms for Updating and 130 for select+join)
To get LITTLEFS running I had to add the solutions posted here: LittleFS.begin(false, "/spiffs")
+ modifying esp32.cpp
I will fix it for LITTLEFS during weekend and close both. Thanks for the info!!
Hi, any update on LittleFS fix?
@pasleto I fixed the issue and also added an example for Little FS. Thanks @Fischkopppp !!
Hi everyone thank you so much for this SQLITE use on my ESP32 working great for a couple of years with UPDATE and INSERT but I tried INSERT ON CONFLICT DO UPDATE to simplify my code and I just can't get it running!!
In Platformio with an esp32doit-devkit-v1, with SQLITE3Esp32 v2.3 from 2020 march files, with database on LittleFS, I get "syntax error near update" with something like INSERT INTO marchandises(navire, marchandise, tonnage, CD) VALUES('a','b',c,'C') ON CONFLICT DO UPDATE set marchandise=excluded.marchandise,tonnage=excluded.tonnage;
and "parser stack overflow" with INSERT INTO marchandises(navire, marchandise, tonnage, CD) VALUES('a','b',c,'C') ON CONFLICT(navire,CD) DO UPDATE set marchandise=excluded.marchandise,tonnage=excluded.tonnage; where (navire,CD) is unique index.
Only INSERT INTO marchandises(navire, marchandise, tonnage, CD) VALUES('a','b',c,'C') ON CONFLICT DO NOTHING; is working for me.
executed with sqlite3_exec() or sqlite3_prepare_v2() doesn't change anything Thoses SQLITE requests are working with python3 console from .platformio with import SQLITE3 and sqlite3.connect() etc...
I suppose the trouble is coming from my config_ext.h ? which is
I tried different variants but never got the insert working! by the way I have 50 warnings "assignment discards 'const' qualifier from pointer target type" on build...
please if you could enlighten me!! best regards
You might try increasing YYSTACKDEPTH and making SQLITE_SMALL_STACK 0 but beyond that I am not sure if anything else will solve this.
thank you for your help but I didn't manage to get that INSERT Conflict working after 2 days of different tries (new database, new table without rowid, index, primary key, and options in config_ext.h and sqlite3_exec or prepare_v2 and controlling heap...)! So I give up and go back to UPDATE then INSERT OR IGNORE!
Hi Arun, first of all thank you for this great library! I absolutely love it.
I have used your "bulk_data_insert" example, adding "BEGIN TRANSACTION" / "END TANSACTION" and I am using a SPI SD card (WEMOS MINI D1 ESP32 with SD shield). I can insert or update more than 800 rows per second in a database. However if I add "ON CONFLICT (mac_id) DO UPDATE set type=?" to INSERT I will only get 22 rows per second (I am not using any Indexes). Any idea how I could improve this? I am still new to sqlite and c++ programming.
By the way, I have ordered a 4 Mbit / 512 KBytes FRAM (MB85RS4MT Adafruit), that can be read/written 10,000,000,000,000 times :) It is not here yet, but I am very excited to get this running on a FRAM. Although I am unsure if this is possible at all. Does someone has any suggestion where to start to get this running?
With best regards, Alex
@siara-cc @siara-in