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

  • SEARCH
  • Home
  • 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 6676801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:02:16+00:00 2026-05-26T04:02:16+00:00

I have an SQLite db with about 400 000 entries. To query the db

  • 0

I have an SQLite db with about 400 000 entries. To query the db I am using the following method:

public double lookUpBigramFrequency(String bigram) throws SQLException {

        SQLiteDatabase db = dbh.getReadableDatabase();
        double frequency = 0;
        bigram = bigram.toLowerCase();

        String select = "SELECT frequency FROM bigrams WHERE bigram = '"
                + bigram + "'";

        Cursor mCursor = db.rawQuery(select, null);
        if (mCursor != null) {

            if (mCursor.moveToFirst()) {
                frequency = Double.parseDouble(mCursor.getString(0));
            } else {
                frequency = 0;
            }
        }

        return frequency;


    }

but it takes about 0.5 sec to retrieve a single entry and having few queries, it builds up and the method is executing for 10 secs. How to speeed it up?

  • 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-26T04:02:16+00:00Added an answer on May 26, 2026 at 4:02 am

    Firstly, use an INDEX

    http://www.sqlite.org/lang_createindex.html

    in your case that will be something like:

    CREATE INDEX idx_bigram ON bigrams (bigram)
    

    Secondly, use ‘?’ instead of literal query. It helps sqlite for caching requests:

    String select = "SELECT frequency FROM bigrams WHERE bigram = ?";
    Cursor mCursor = db.rawQuery(select, new String[]{ bigram });
    

    Thirdly, I trust query is more efficient than rawQuery:

    mCursor = dq.query("bigrams", new String[] { "frequency" }, "bigram = ?",
              new String[]{ bigram }, null, null, null, null);
    

    Fourthly, you can query several values at once (not compatible with point 2):

    SELECT frequency FROM bigrams WHERE bigrams IN ('1', '2', '3')
    

    Fifthly, you don’t need to open your database every time. You should consider leaving it open.

    Edit

    After seeing this question IN clause and placeholders it appears you can combine 2 and 4 after all (not sure it is useful, though)

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

Sidebar

Related Questions

I am using the SQLite database and have the following persistent class (simplified): public
I have about 20,000 records (coming from an SQLite db) that I need to
I currently have a large .sqlite data store of long string text. It's about
I have a purely academic question about SQLite databases. I am using SQLite.net to
I have a sqlite database with about 100 000 rows containing longitudes and latitudes
I have a large sqlite db. Its 185mb. This query is taking about 5seconds
Anyone have idea about how to bind Boolean in sqlite with objective - c.
I have an SQLite database, eventually will be a MySQL database and I'm using
I've been thinking about using SQLite for my next project, but I'm concerned that
Sorry I am a noob, I am trying to learn about sqlite databases using

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.