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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:31:44+00:00 2026-06-15T14:31:44+00:00

Schema: CREATE TABLE [Groups] ([Group] VARCHAR(50) NULL, [ArtNum] INTEGER NULL, [ID] VARCHAR(50) NULL, [Time]

  • 0

Schema:

CREATE TABLE [Groups] ([Group] VARCHAR(50) NULL, [ArtNum] INTEGER NULL, [ID] VARCHAR(50)  NULL, [Time] INTEGER);
CREATE INDEX [GroupTime]   ON [Groups] ([Group], [Time] DESC);
CREATE INDEX [GroupArtNum] ON [Groups] ([Group], [ArtNum]);

I would like optimize the following query:

 SELECT `ID` FROM `Groups` WHERE `Group`=? ORDER BY `Time` DESC LIMIT 1

The problem is that SQLite insists on using the GroupArtNum index instead of the GroupTime index. EXPLAIN QUERY PLAN prints the following:

SEARCH TABLE Groups USING INDEX GroupArtNum (Group=?) (~10 rows)
USE TEMP B-TREE FOR ORDER BY

What’s interesting is that if I try to sort by ArtNum instead of Time, it runs very quickly.

I have only (64-bit) integers in the Time column, same as with ArtNum.

  • 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-15T14:31:45+00:00Added an answer on June 15, 2026 at 2:31 pm
    1. Run ANALYZE (which might or might not help in any specific case); or
    2. use the INDEXED clause to force using a specific index (although the documentation warns against doing this):

      SELECT ID FROM Groups INDEXED BY GroupTime WHERE ...
      
    3. or update to SQLite 3.7.15 (when it’s released), which has query planner optimizations that make it recognize that using GroupTime is more efficient.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following DB schema: CREATE TABLE master ( id integer primary key autoincrement,
So here's my schema (give or take): cmds.Add(@CREATE TABLE [Services] ([Id] INTEGER PRIMARY KEY,
Consider the following database schema: create table UserGroup ( id int not null auto_increment,
I have the schema below CREATE TABLE `vocabulary` ( `vid` int(10) unsigned NOT NULL
With this schema: create table object ( obj_id serial primary key, name varchar(80) not
I have a schema that essentially looks like this: CREATE TABLE `data` ( `id`
I have an orders table with a schema like this. CREATE TABLE orders (
I've just created anew schema & want to create a new table. When ever
I have got the following simplified schema: CREATE TABLE [file] ( id UNIQUEIDENTIFIER NOT
I have 3 tables with the following schema: CREATE TABLE `devices` ( `device_id` int(11)

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.