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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:27:58+00:00 2026-05-21T10:27:58+00:00

I have a hand written ORM built on top of the Qt object system.

  • 0

I have a hand written ORM built on top of the Qt object system. I’m testing it with SQLite back end, and I’m seeing weird performance issues. There are about 10k objects stored in the database. The objects are loaded one by one with separate queries.

One of the queries exhibits changes in execution time: from 1 msec to 10 depending on the primary key ID. This time also includes some operations done by the Qt Sql module.

The query is very simple and looks like this (the id=100 differs between the queries):

SELECT * FROM t1, t2 WHERE t1.id = 100 AND t2.id = 100

What might cause the same query to perform 10 times worse depending on the row id?

  • 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-21T10:27:59+00:00Added an answer on May 21, 2026 at 10:27 am

    Considering that you are timing operations in milliseconds the behaviour that you are observing makes quite a bit of sense. Benchmarking single query runs with this kind of time granularity normally makes no sense, unless you are only interested in latency, rather than throughput.

    With your particular query, for example, you would see a significant difference depending on whether there are mathing rows in t1, since that would determine whether SQLite should bother looking at t2 at all.

    Even running exactly the same query will produce different results depending on the OS filesystem cache, the process scheduler, the SQLite cache, the position of the hard disk plates and heads and various other factors.

    Two be more specific, there are two possibilities:

    A. t1.id and t2.id are indexed

    This is the most probable case – I’d expect a table column aptly named id to be indexed.

    Most SQL engines, including SQLite, use some variation of a B-tree for each index. On SQLite each tree node is a single page in the DB file. With your particular query, SQLite will have to go through:

    • Some pages of the t1.id index
    • Some pages of the t2.id index
    • The DB pages where the matching rows from both tables are contained.

    Depending on your hardware and how the pages are located on the physical medium (e.g. your hard drive), loading a page can easily add a latency of several milliseconds. This is especially visible on large or freshly-loaded databases where the pages are neither in the OS filesystem cache nor in the SQLite3 cache.

    In addition, unless your DB is really small, it usually won’t fit in the SQLite3 cache and cache hits and misses alone can account for rather severe variations in the time a single query needs to complete: an SQLite cache miss forces a read from the filesystem, which can easily cause the DB process to be rescheduled by the OS in favour of another process.

    B. t1.id and t2.id are not indexed

    This is probably easier to visualise: with no indexes, SQLite has to scan the whole table. Assuming that you have a limit in your SELECT statement (you do not have one in your example), whether a matching entry will be found immediately or after going through the whole table is up to luck, hence the severe variation in query completion times.

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

Sidebar

Related Questions

I have a three tier system, SQL Server backend, hand written data access layer,
I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools
I have never hand-coded object creation code for SQL Server and foreign key decleration
We are currently evaluating options for migrating from hand-written persistence layer to ORM. We
Kind of looking for affirmation here. I have some hand-written code, which I'm not
We currently have a solution that was completely written by hand in ASP.NET and
I have several hand-written Java classes in a REST Server that uses JAXB to
I've started switching over a project from hand-written JDBC ORM code to Ebeans. So
Traditionally I have always written my sql scripts by hand so they are nice
I have a hand-written CSS parser done in C# which is getting unmanageable and

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.