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 7188355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:03:57+00:00 2026-05-28T19:03:57+00:00

What would be faster; searching a sqlite3 database table for a row whose primary

  • 0

What would be faster; searching a sqlite3 database table for a row whose primary key equals a specific string

OR

In Python, I obtain all the primary keys from a sqlite3 database table (using a query) as a Python list and use Pythons in keyword to test whether a specific string occurs within that list.

I guess I am asking does SQLite3 employ a more advanced algorithm to find a specific row with the primary key I am searching for or would it be faster to just get all the primary keys myself & search using python(or employ my own Binary search once I get them all)?

Code to do either way:

import sqlite3
conn = sqlite3.connect("d.db")
cur = conn.cursor()
isPresent = cur.execute( "SELECT target FROM stringList WHERE target='specificString';" ).fetchall()
return isPresent == None

// Alternate
primaryKeyList = cur.execute( "SELECT target FROM stringList;" ).fetchall()
return 'specificString' in primaryKeyList 

// Or I can sort the list then use a binary search or other fast algorithm
primaryKeyList = cur.execute( "SELECT target FROM stringList;" ).fetchall()
//..sort primaryKeyList
primaryKeyList = sortList(primaryKeyList)
return binarySearch('specificString') == True 

PS: Is there a way to tell SQLite3 in what order I want the rows to be stored in? So I can always have my rows in a table sorted alphabetically (according to their primary key)?

  • 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-28T19:03:59+00:00Added an answer on May 28, 2026 at 7:03 pm

    The answer to every “would it be faster?” question is “test it yourself”.

    That said, the answer is that SQLite searching on an index is going to be faster than a SQLite table-scan plus an O(N) scan in Python.

    As for your “tell SQLite how to store the rows” bit, you don’t want that. You can do an ORDER BY to retrieve the results in a certain order – the way they’re stored is an implementation detail.

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

Sidebar

Related Questions

Which query would run faster? SELECT * FROM topic_info LEFT JOIN topic_data ON topic_info.id
For example,We have a DWORD = $12345678 Which of the instructions would be faster
In a visual studio C++ project, would MFC be faster than using the CLR?
Would NTFS allocation blocks of 16KB or 32KB make compile time faster in comparison
I would like to know if ParseExact is faster than Parse. I think that
which would you recommend? which is faster, reliable? apache mod_python or nginx/lighttpd FastCGI?
I am wondering which way would end up being faster, selecting elements by: $('element[href=#my_link]');
What is faster: Function pointers or switch? The switch statement would have around 30
As prescribed by Yahoo!, gzip'ng files would make your websites load faster. The problem?
Would it not make sense to support a set of languages (Java, Python, Ruby,

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.