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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:25:16+00:00 2026-06-09T19:25:16+00:00

I have a table looking like this created with sqlite. CREATE TABLE Cars (

  • 0

I have a table looking like this created with sqlite.

CREATE TABLE Cars ( 

POWER DOUBLE ,
CAPACITY DOUBLE,
SPEED DOUBLE,   
TIME INTEGER  NOT NULL,
TYPE INTEGER  NOT NULL, 
MODEL INTEGER  NOT NULL,

PRIMARY KEY ( TIME, TYPE, MODEL ));

There are 15 different values of TYPE, and each type have 20 different values of MODEL.
For every model there is inserted a new record every 10th second.

A little example:

POWER----TIME----TYPE----MODEL
45.6     2588     3       14
46.8     2588     3       15
44.7     2588     3       16

This table is really huge with millions of rows.

As you can see my primary key is (TIME, TYPE, MODEL) because that is making a unique identifier.

My application runs a select query several times which can take a really long time when when the time range is large, or if I run the query for several models.

For example I run this type of query quite often:

SELECT power, time, type, model 
FROM CARS 
WHERE type = 3 AND model = 14 AND time BETWEEN 2588 and 13550;

I have tried to experiment with a primary key like (TYPE, MODEL, TIME) which has increased the performance for some situations, but not over a large time interval.

My question is how I can optimize this retrieval of records, and what primary key that seems to be optimal for this situation?

Insertions and updates are not an issue in terms of performance.

  • 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-06-09T19:25:18+00:00Added an answer on June 9, 2026 at 7:25 pm

    The order of fields in your primary key should reflect how selective each one is going to be (most selective first).

    Superficially, time should appear to come first, since selecting on a specific time would return fewer records than a specific type or model.

    However, if most or all of your queries are going to select a range of times, then it would be better to have the time at the end of the primary key, since range selection is less selective than specific values.

    I suggest changing the primary key to be (model, type, time) – in that order.

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

Sidebar

Related Questions

I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field
I have this table And my goals is to have a table looking like
I have a MySQL table with a structure like the following: I'm looking for
I have a specific information in a table I am looking for, this query
I have a user table that has many columns, it looks roughly like this:
I have a messages table which looks like this: +------------+-------------+----------+ | sender_id | created_at
I have a table that looks like this: +-------+------------------+------+-----+---------+----------------+ | Field | Type |
I created an oracle Object Type like this: CREATE OR REPLACE TYPE DFBOWNER.RPT_WIRE_IMPORT_ROWTYPE AS
I have a table that has millions of records and we are looking at
I have a table which contains many records. I'm looking for an efficient way

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.