Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:14:13+00:00 2026-05-13T18:14:13+00:00

I’ve a mobile application. My client has a large data set ~100.000 records. It’s

  • 0

I’ve a mobile application. My client has a large data set ~100.000 records. It’s updated frequently.
When we sync we need to copy from one database to another.

I’ve attached the second database to the main, and run an insert into table select * from sync.table.

This is extremely slow, it takes about 10 minutes I think.
I noticed that the journal file gets increased step by step.

How can I speed this up?

EDITED 1

I have indexes off, and I have journal off.
Using

insert into table select * from sync.table

it still takes 10 minutes.

EDITED 2

If I run a query like

select id,invitem,invid,cost from inventory where itemtype = 1 
order by invitem limit 50 

it takes 15-20 seconds.

The table schema is:

CREATE TABLE inventory  
('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
 'serverid' INTEGER NOT NULL DEFAULT 0,
 'itemtype' INTEGER NOT NULL DEFAULT 0,
 'invitem' VARCHAR,
 'instock' FLOAT  NOT NULL DEFAULT 0,
 'cost' FLOAT NOT NULL DEFAULT 0,
 'invid' VARCHAR,
 'categoryid' INTEGER  DEFAULT 0,
 'pdacategoryid' INTEGER DEFAULT 0,
 'notes' VARCHAR,
 'threshold' INTEGER  NOT NULL DEFAULT 0,
 'ordered' INTEGER  NOT NULL DEFAULT 0,
 'supplier' VARCHAR,
 'markup' FLOAT NOT NULL DEFAULT 0,
 'taxfree' INTEGER NOT NULL DEFAULT 0,
 'dirty' INTEGER NOT NULL DEFAULT 1,
 'username' VARCHAR,
 'version' INTEGER NOT NULL DEFAULT 15
)

Indexes are created like

CREATE INDEX idx_inventory_categoryid ON inventory (pdacategoryid);
CREATE INDEX idx_inventory_invitem ON inventory (invitem);
CREATE INDEX idx_inventory_itemtype ON inventory (itemtype);

I am wondering, the insert into … select * from isn’t the fastest built-in way to do massive data copy?

EDITED 3

SQLite is server-less, so please stop voting a particular answer, because that is not the answer I’m sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:14:14+00:00Added an answer on May 13, 2026 at 6:14 pm

    I don’t think that attaching the two databases and running INSERT INTO foo (SELECT * FROM bar) is the fastest way to do this. If you are synching between a handheld device and a server (or another device) could the transport mechanism be the bottleneck? Or are the two database files already on the same filesysem? If the filesystem on the device is slower flash-memory, could this be a bottleneck?

    Are you able to compile/run the raw SQLite C code on your device? (I think that the RAW sqlite3 amalgamation should compile for WinCE/Mobile) If so, and you are willing:

    • To write some C code (using the SQLite C API)
    • Increase risk of data loss by turning off disk journaling

    It should be possible for to write a small stand-alone executable to copy/synchronize the 100K records between the two databases extremely quickly.

    I’ve posted some of what I learned about optimizing SQLite inserts here: Improve INSERT-per-second performance of SQLite?


    Edit: Tried this out with real code…

    I don’t know all the steps involved in building a Windows Mobile executable, but the SQLite3 amalgamation should compile out-of-the box using Visual Studio. Here is a sample main.c program that opens two SQLite databases (both have to have the same schema – see the #define TABLE statement) and executes a SELECT statement and then binds the resulting rows to an INSERT statement:

    /*************************************************************
    ** The author disclaims copyright to this source code.  In place of
    ** a legal notice, here is a blessing:
    **
    **    May you do good and not evil.
    **    May you find forgiveness for yourself and forgive others.
    **    May you share freely, never taking more than you give.
    **************************************************************/
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    #include "sqlite3.h"
    
    #define SOURCEDB "C:\\source.sqlite"
    #define DESTDB "c:\\dest.sqlite"
    
    #define TABLE "CREATE TABLE IF NOT EXISTS TTC (id INTEGER PRIMARY KEY, Route_ID TEXT, Branch_Code TEXT, Version INTEGER, Stop INTEGER, Vehicle_Index INTEGER, Day Integer, Time TEXT)"
    #define BUFFER_SIZE 256
    
    int main(int argc, char **argv) {
    
        sqlite3 * sourceDB;
        sqlite3 * destDB;
    
        sqlite3_stmt * insertStmt;
        sqlite3_stmt * selectStmt;
    
        char * insertTail = 0;
        char * selectTail = 0;
    
        int n = 0;
        int result = 0;
        char * sErrMsg = 0;
        clock_t cStartClock;
    
        char sInsertSQL [BUFFER_SIZE] = "\0";
        char sSelectSQL [BUFFER_SIZE] = "\0";
    
        /* Open the Source and Destination databases */
        sqlite3_open(SOURCEDB, &sourceDB);
        sqlite3_open(DESTDB, &destDB);
    
        /* Risky - but improves performance */
        sqlite3_exec(destDB, "PRAGMA synchronous = OFF", NULL, NULL, &sErrMsg);
        sqlite3_exec(destDB, "PRAGMA journal_mode = MEMORY", NULL, NULL, &sErrMsg);
    
        cStartClock = clock(); /* Keep track of how long this took*/
    
        /* Prepared statements are much faster */
        /* Compile the Insert statement */
        sprintf(sInsertSQL, "INSERT INTO TTC VALUES (NULL, @RT, @BR, @VR, @ST, @VI, @DT, @TM)");
        sqlite3_prepare_v2(destDB, sInsertSQL, BUFFER_SIZE, &insertStmt, &insertTail);
    
        /* Compile the Select statement */
        sprintf(sSelectSQL, "SELECT * FROM TTC LIMIT 100000");
        sqlite3_prepare_v2(sourceDB, sSelectSQL, BUFFER_SIZE, &selectStmt, &selectTail);
    
        /* Transaction on the destination database */
        sqlite3_exec(destDB, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
    
        /* Execute the Select Statement.  Step through the returned rows and bind
        each value to the prepared insert statement.  Obviously this is much simpler
        if the columns in the select statement are in the same order as the columns
        in the insert statement */
        result = sqlite3_step(selectStmt);
        while (result == SQLITE_ROW)
        {
    
            sqlite3_bind_text(insertStmt, 1, sqlite3_column_text(selectStmt, 1), -1, SQLITE_TRANSIENT); /* Get Route */
            sqlite3_bind_text(insertStmt, 2, sqlite3_column_text(selectStmt, 2), -1, SQLITE_TRANSIENT); /* Get Branch */
            sqlite3_bind_text(insertStmt, 3, sqlite3_column_text(selectStmt, 3), -1, SQLITE_TRANSIENT); /* Get Version */
            sqlite3_bind_text(insertStmt, 4, sqlite3_column_text(selectStmt, 4), -1, SQLITE_TRANSIENT); /* Get Stop Number */
            sqlite3_bind_text(insertStmt, 5, sqlite3_column_text(selectStmt, 5), -1, SQLITE_TRANSIENT); /* Get Vehicle */
            sqlite3_bind_text(insertStmt, 6, sqlite3_column_text(selectStmt, 6), -1, SQLITE_TRANSIENT); /* Get Date */
            sqlite3_bind_text(insertStmt, 7, sqlite3_column_text(selectStmt, 7), -1, SQLITE_TRANSIENT); /* Get Time */
    
            sqlite3_step(insertStmt);       /* Execute the SQL Insert Statement (Destination Database)*/
            sqlite3_clear_bindings(insertStmt); /* Clear bindings */
            sqlite3_reset(insertStmt);      /* Reset VDBE */
    
            n++;
    
            /* Fetch next from from source database */
            result = sqlite3_step(selectStmt);
    
        }
    
        sqlite3_exec(destDB, "END TRANSACTION", NULL, NULL, &sErrMsg);
    
        printf("Transfered %d records in %4.2f seconds\n", n, (clock() - cStartClock) / (double)CLOCKS_PER_SEC);
    
        sqlite3_finalize(selectStmt);
        sqlite3_finalize(insertStmt);
    
        /* Close both databases */
        sqlite3_close(destDB);
        sqlite3_close(sourceDB);
    
        return 0;
    }
    

    On my Windows desktop machine this code copies 100k records from source.sqlite to dest.sqlite in 1.20 seconds. I don’t know exactly what kind of performance you’ll see on a mobile device with flash memory (but I am curious).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 356k
  • Answers 356k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What about using the same cookie for both sides? If… May 14, 2026 at 8:59 am
  • Editorial Team
    Editorial Team added an answer This was pulled off of forum post linked to above.… May 14, 2026 at 8:59 am
  • Editorial Team
    Editorial Team added an answer Here's one option. It's a bit ugly, but allows you… May 14, 2026 at 8:59 am

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.