SQLite

Check-in [11ee8ea43f]
Login

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

Overview
Comment:Make sure rowid comparisons against NULL work correctly. Ticket #2404. (CVS 4050)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 11ee8ea43f20f6146f4e4fcd9299468b3a99f998
User & Date: drh 2007-06-08 08:39:02.000
Context
2007-06-08
08:43
Additional test cases for comparisons against NULL in the WHERE clause and elsewhere in a SELECT. (CVS 4051) (check-in: 72612a0373 user: drh tags: trunk)
08:39
Make sure rowid comparisons against NULL work correctly. Ticket #2404. (CVS 4050) (check-in: 11ee8ea43f user: drh tags: trunk)
00:20
Fix the query optimizer so that it correctly handles constant expressions in the ON clause of a LEFT JOIN. Ticket #2403. (CVS 4049) (check-in: 46fdd19548 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.251 2007/06/08 00:20:48 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.252 2007/06/08 08:39:02 drh Exp $
*/
#include "sqliteInt.h"

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
*/
#define BMS  (sizeof(Bitmask)*8)
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
      start = sqlite3VdbeCurrentAddr(v);
      pLevel->op = bRev ? OP_Prev : OP_Next;
      pLevel->p1 = iCur;
      pLevel->p2 = start;
      if( testOp!=OP_Noop ){
        sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
        sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
        sqlite3VdbeAddOp(v, testOp, SQLITE_AFF_NUMERIC, brk);
      }
    }else if( pLevel->flags & WHERE_COLUMN_RANGE ){
      /* Case 3: The WHERE clause term that refers to the right-most
      **         column of the index is an inequality.  For example, if
      **         the index is on (x,y,z) and the WHERE clause is of the
      **         form "x=5 AND y<10" then this case is used.  Only the
      **         right-most column can be an inequality - the rest must







|







2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
      start = sqlite3VdbeCurrentAddr(v);
      pLevel->op = bRev ? OP_Prev : OP_Next;
      pLevel->p1 = iCur;
      pLevel->p2 = start;
      if( testOp!=OP_Noop ){
        sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
        sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
        sqlite3VdbeAddOp(v, testOp, SQLITE_AFF_NUMERIC|0x100, brk);
      }
    }else if( pLevel->flags & WHERE_COLUMN_RANGE ){
      /* Case 3: The WHERE clause term that refers to the right-most
      **         column of the index is an inequality.  For example, if
      **         the index is on (x,y,z) and the WHERE clause is of the
      **         form "x=5 AND y<10" then this case is used.  Only the
      **         right-most column can be an inequality - the rest must
Added test/where5.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# 2007 June 8
#
# 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.  The
# focus of this file is testing NULL comparisons in the WHERE clause.
# See ticket #2404.
#
# $Id: where5.test,v 1.1 2007/06/08 08:39:02 drh Exp $

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

# Build some test data
#
do_test where5-1.0 {
  execsql {
    CREATE TABLE t1(x TEXT);
    CREATE TABLE t2(x INTEGER);
    CREATE TABLE t3(x INTEGER PRIMARY KEY);
    INSERT INTO t1 VALUES(-1);
    INSERT INTO t1 VALUES(0);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t2 SELECT * FROM t1;
    INSERT INTO t3 SELECT * FROM t2;
  }
  execsql {
    SELECT * FROM t1 WHERE x<0
  }
} {-1}
do_test where5-1.1 {
  execsql {
    SELECT * FROM t1 WHERE x<=0
  }
} {-1 0}
do_test where5-1.2 {
  execsql {
    SELECT * FROM t1 WHERE x=0
  }
} {0}
do_test where5-1.3 {
  execsql {
    SELECT * FROM t1 WHERE x>=0
  }
} {0 1}
do_test where5-1.4 {
  execsql {
    SELECT * FROM t1 WHERE x>0
  }
} {1}
do_test where5-1.5 {
  execsql {
    SELECT * FROM t1 WHERE x<>0
  }
} {-1 1}
do_test where5-1.6 {
  execsql {
    SELECT * FROM t1 WHERE x<NULL
  }
} {}
do_test where5-1.7 {
  execsql {
    SELECT * FROM t1 WHERE x<=NULL
  }
} {}
do_test where5-1.8 {
  execsql {
    SELECT * FROM t1 WHERE x=NULL
  }
} {}
do_test where5-1.9 {
  execsql {
    SELECT * FROM t1 WHERE x>=NULL
  }
} {}
do_test where5-1.10 {
  execsql {
    SELECT * FROM t1 WHERE x>NULL
  }
} {}
do_test where5-1.11 {
  execsql {
    SELECT * FROM t1 WHERE x!=NULL
  }
} {}

do_test where5-2.0 {
  execsql {
    SELECT * FROM t2 WHERE x<0
  }
} {-1}
do_test where5-2.1 {
  execsql {
    SELECT * FROM t2 WHERE x<=0
  }
} {-1 0}
do_test where5-2.2 {
  execsql {
    SELECT * FROM t2 WHERE x=0
  }
} {0}
do_test where5-2.3 {
  execsql {
    SELECT * FROM t2 WHERE x>=0
  }
} {0 1}
do_test where5-2.4 {
  execsql {
    SELECT * FROM t2 WHERE x>0
  }
} {1}
do_test where5-2.5 {
  execsql {
    SELECT * FROM t2 WHERE x<>0
  }
} {-1 1}
do_test where5-2.6 {
  execsql {
    SELECT * FROM t2 WHERE x<NULL
  }
} {}
do_test where5-2.7 {
  execsql {
    SELECT * FROM t2 WHERE x<=NULL
  }
} {}
do_test where5-2.8 {
  execsql {
    SELECT * FROM t2 WHERE x=NULL
  }
} {}
do_test where5-2.9 {
  execsql {
    SELECT * FROM t2 WHERE x>=NULL
  }
} {}
do_test where5-2.10 {
  execsql {
    SELECT * FROM t2 WHERE x>NULL
  }
} {}
do_test where5-2.11 {
  execsql {
    SELECT * FROM t2 WHERE x!=NULL
  }
} {}

do_test where5-3.0 {
  execsql {
    SELECT * FROM t3 WHERE x<0
  }
} {-1}
do_test where5-3.1 {
  execsql {
    SELECT * FROM t3 WHERE x<=0
  }
} {-1 0}
do_test where5-3.2 {
  execsql {
    SELECT * FROM t3 WHERE x=0
  }
} {0}
do_test where5-3.3 {
  execsql {
    SELECT * FROM t3 WHERE x>=0
  }
} {0 1}
do_test where5-3.4 {
  execsql {
    SELECT * FROM t3 WHERE x>0
  }
} {1}
do_test where5-3.5 {
  execsql {
    SELECT * FROM t3 WHERE x<>0
  }
} {-1 1}
do_test where5-3.6 {
  execsql {
    SELECT * FROM t3 WHERE x<NULL
  }
} {}
do_test where5-3.7 {
  execsql {
    SELECT * FROM t3 WHERE x<=NULL
  }
} {}
do_test where5-3.8 {
  execsql {
    SELECT * FROM t3 WHERE x=NULL
  }
} {}
do_test where5-3.9 {
  execsql {
    SELECT * FROM t3 WHERE x>=NULL
  }
} {}
do_test where5-3.10 {
  execsql {
    SELECT * FROM t3 WHERE x>NULL
  }
} {}
do_test where5-3.11 {
  execsql {
    SELECT * FROM t3 WHERE x!=NULL
  }
} {}


finish_test