SQLite

Check-in [553b7ba8f8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bug fix in the ORDER BY optimizer. Ticket #1435. (CVS 2707)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 553b7ba8f8ae4cb865494f2d301690149d7edb9f
User & Date: drh 2005-09-17 13:29:24.000
Context
2005-09-17
15:17
Update the webpage description of 3.2.6 changes to talk about ticket #1432. (CVS 2708) (check-in: 0e23c28b25 user: drh tags: trunk)
13:29
Bug fix in the ORDER BY optimizer. Ticket #1435. (CVS 2707) (check-in: 553b7ba8f8 user: drh tags: trunk)
13:07
Make sure dependencies on the right-hand side of IN operators are checked correctly. Ticket #1433. (CVS 2706) (check-in: 21740794ab user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/where.c.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is reponsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.173 2005/09/17 13:07:13 drh Exp $
*/
#include "sqliteInt.h"

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
*/
#define BMS  (sizeof(Bitmask)*8)







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is reponsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.174 2005/09/17 13:29:24 drh Exp $
*/
#include "sqliteInt.h"

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
*/
#define BMS  (sizeof(Bitmask)*8)
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
    for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
      m = getMask(&maskSet, pTabItem->iCursor);
      if( (m & notReady)==0 ){
        if( j==iFrom ) iFrom++;
        continue;
      }
      cost = bestIndex(pParse, &wc, pTabItem, notReady,
                       (j==0 && ppOrderBy) ? *ppOrderBy : 0,
                       &pIdx, &flags, &nEq);
      if( cost<lowestCost ){
        lowestCost = cost;
        pBest = pIdx;
        bestFlags = flags;
        bestNEq = nEq;
        bestJ = j;







|







1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
    for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
      m = getMask(&maskSet, pTabItem->iCursor);
      if( (m & notReady)==0 ){
        if( j==iFrom ) iFrom++;
        continue;
      }
      cost = bestIndex(pParse, &wc, pTabItem, notReady,
                       (i==0 && ppOrderBy) ? *ppOrderBy : 0,
                       &pIdx, &flags, &nEq);
      if( cost<lowestCost ){
        lowestCost = cost;
        pBest = pIdx;
        bestFlags = flags;
        bestNEq = nEq;
        bestJ = j;
Added test/tkt1435.test.






















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 2005 September 17
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket #1435 has been
# fixed.  
#
#
# $Id: tkt1435.test,v 1.1 2005/09/17 13:29:24 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Construct the sample database.
#
do_test tkt1435-1.0 {
  sqlite3 db :memory:
  execsql {
    CREATE TABLE Instances(
    	instanceId INTEGER PRIMARY KEY,
    	troveName STR,
    	versionId INT,
    	flavorId INT,
    	timeStamps STR,
    	isPresent INT,
    	pinned BOOLEAN
    );
    INSERT INTO "Instances"
       VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1);
    INSERT INTO "Instances"
       VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0);
    INSERT INTO "Instances"
       VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0);
    INSERT INTO "Instances"
       VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0);
    
    CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE);
    INSERT INTO "Versions" VALUES(0, NULL);
    INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1');
    
    CREATE TABLE Flavors(flavorId integer primary key, flavor str unique);
    INSERT INTO "Flavors" VALUES(0, NULL);
    INSERT INTO "Flavors" VALUES(1, '1#x86');
    
    CREATE TEMPORARY TABLE tlList (
       row INTEGER PRIMARY KEY,
       name STRING,
       version STRING,
       flavor STRING
    );
    
    INSERT INTO tlList 
      values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86');
    INSERT INTO tlList 
      values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86');
    INSERT INTO tlList 
      values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86');
  }
} {}

# Run the query with an index
#
do_test tkt1435-1.1 {
  execsql {
    select row, pinned from tlList, Instances, Versions, Flavors
        where
            Instances.troveName = tlList.name
        and Versions.version = tlList.version
        and Instances.versionId = Versions.versionId
        and (    Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
             and tlList.flavor = '')
        and Instances.flavorId = Flavors.flavorId
    order by row asc;
  }
} {1 0 2 0 3 1}

# Create a indices, analyze and rerun the query. 
# Verify that the results are the same
#
do_test tkt1435-1.2 {
  execsql {
    CREATE INDEX InstancesNameIdx ON Instances(troveName);
    CREATE UNIQUE INDEX InstancesIdx 
      ON Instances(troveName, versionId, flavorId);
    ANALYZE;
    select row, pinned from tlList, Instances, Versions, Flavors
        where
            Instances.troveName = tlList.name
        and Versions.version = tlList.version
        and Instances.versionId = Versions.versionId
        and (    Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
             and tlList.flavor = '')
        and Instances.flavorId = Flavors.flavorId
    order by row asc;
  }
} {1 0 2 0 3 1}

finish_test
Changes to test/tkt1443.test.
24
25
26
27
28
29
30






31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Expr.pRight field rather than Expr.pList and Expr.pSelect.  
#
# Such a bug could be verifed using a less elaborate test case.  But
# this test case (from the original bug poster) exercises so many different
# parts of the system all at once, that it seemed like a good one to
# include in the test suite. 
#






# $Id: tkt1443.test,v 1.1 2005/09/17 13:07:13 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Construct the sample database.
#
do_test tkt1433-1.0 {
  sqlite3 db :memory:
  execsql {
    CREATE TABLE Items(
    	itemId integer primary key,
    	 item str unique
    );
    INSERT INTO "Items" VALUES(0, 'ALL');







>
>
>
>
>
>
|







|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Expr.pRight field rather than Expr.pList and Expr.pSelect.  
#
# Such a bug could be verifed using a less elaborate test case.  But
# this test case (from the original bug poster) exercises so many different
# parts of the system all at once, that it seemed like a good one to
# include in the test suite. 
#
# NOTE:  Yes, in spite of the name of this file (tkt1443.test) this
# test is for ticket #1433 not #1443.  I mistyped the name when I was
# creating the file and I had already checked in the file by the wrong
# name be the time I noticed the error.  With CVS it is a really hassle
# to change filenames, so I'll just leave it as is.  No harm done.
#
# $Id: tkt1443.test,v 1.2 2005/09/17 13:29:24 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Construct the sample database.
#
do_test tkt1443-1.0 {
  sqlite3 db :memory:
  execsql {
    CREATE TABLE Items(
    	itemId integer primary key,
    	 item str unique
    );
    INSERT INTO "Items" VALUES(0, 'ALL');