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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:11+00:00 2026-06-11T14:03:11+00:00

During testing of our implementation of SQLite Virtual Table mechanism we’ve encountered an unexpected

  • 0

During testing of our implementation of SQLite Virtual Table mechanism we’ve encountered an unexpected behavior.
For the following virtual table structure:

create table X(ID int, RL real)

This query returns all the records in the correct descending order by RL
field.

Query 1:

select * from VTab t1 left outer join VTab t2 on t1.ID = t2.ID order by t1.RL desc;

Execution plan 1:

explain query plan select * from VTab t1 left outer join VTab t2 on t1.ID = t2.ID order by t1.RL desc;  

0|0|0| SCAN TABLE VTab AS t1 VIRTUAL TABLE INDEX 0:D1; (~0 rows)
0|1|1| SCAN TABLE VTab AS t2 VIRTUAL TABLE INDEX 4:C0=0; (~0 rows)

D1 here is a value generated by our xBestIndex method implementation and means descending sorting by the field #1 = RL.
C0=0 here means equal operation for the field #0 = ID.
This works as expected.

However, the next query returns rows (the alias of RL field is different) without any sorting.

Query 2:

select * from VTab t1 left outer join VTab t2 on t1.ID = t2.ID order by t2.RL desc

Execution plan 2:

explain query plan select * from VTab t1 left outer join VTab t2 on t1.ID = t2.ID order by t2.RL desc;  

0|0|0| SCAN TABLE VTab AS t1 VIRTUAL TABLE INDEX 0: (~0 rows)
0|11| SCAN TABLE VTab AS t2 VIRTUAL TABLE INDEX 4:C0=0; (~0 rows)

As you can see there is no index mentioned to sort by.
The query executed against a real table (having the very same structure as our virtual table) looks as follows:

Query 3:

select * from Table1 t1 left outer join Table1 t2 on t1.ID = t2.ID order by t2.RL desc

Execution plan 3:

explain query plan select * from Table1 t1 left outer join Table1t2 on t1.ID = t2.ID order by t2.RL desc;  

0|0|0| SCAN TABLE Table1 AS t1 (~1000000 rows)
0|1|0| SEARCH TABLE Table1 AS t2 USING AUTOMATIC COVERING INDEX (ID=?)
0|1|0| (~7 rows)
0|0|0| USE TEMP B-TREE FOR ORDER BY

As you can see there is sorting using B-tree there.

From our side we examined what we received in sqlite3_index_orderby structures (the part of sqlite3_index_info structure) when they had come to xBestIndex and they didn’t contain any information about sorting.
Also the orderByConsumed out parameter returns False (as our output is not ordered and we presume that sqlite itself will order rows).

Is this a bug in SQLite Virtual Table support or we missed something?

  • 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-11T14:03:12+00:00Added an answer on June 11, 2026 at 2:03 pm

    The reason of the problem lied in improper handling of the orderByConsumed output flag value.

    For this query with JOIN, our xBestIndex implementation returned orderByConsumed = True for the index that matched ON condition, which actually wasn’t correct because no ordering was done in that case. This disregarded any further ORDER BY clause members.

    After the fix orderByConsumed started return True only for the indexes where nOrderBy flag was greater than 0 and False otherwise.

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

Sidebar

Related Questions

found a interesting problem during testing our web application. I have application on localhost
We're currently facing some issues during Unit Testing. Our class is multithreading some function
During testing a weakness was exposed in how our app builds f:selectItems lists, specifically,
During testing, I'm stuck with testing a piece of code that receives a list
During the process of building software applications, you would start testing what you have
Is it possible for the nose unit testing framework to perform tests during the
During the installation of my app, I want to create a PostgreSQL-Database and some
During our efforts to design InApp Billing for our Android App, we came up
I am trying to work out a bug we've found during our last iteration
During testing I have a mock object which sets errno = ETIMEDOUT; The object

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.