/ Check-in [f3c09a0c]
Login

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

Overview
Comment:Remove incorrect ALWAYS macro associated with empty IN() sets. Ticket #3602. (CVS 6202)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f3c09a0cb8bfc1a112c31b556d8921d5c75c5eef
User & Date: danielk1977 2009-01-24 09:56:15
Context
2009-01-24
11:30
Fix some minor compiler warnings. Added sqlite3Isalpha() for use in the soundex() function. (CVS 6203) check-in: bfc71edc user: drh tags: trunk
09:56
Remove incorrect ALWAYS macro associated with empty IN() sets. Ticket #3602. (CVS 6202) check-in: f3c09a0c user: danielk1977 tags: trunk
2009-01-23
16:45
Optimization: When loading a new page into the cache, avoid redundant memset() calls to zero it. (CVS 6201) check-in: 9c0b9f88 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/where.c.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
....
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is responsible 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.364 2009/01/14 00:55:10 drh Exp $
*/
#include "sqliteInt.h"

/*
** Trace output macros
*/
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
................................................................................
      if( pTerm==0 ) break;
      wsFlags |= WHERE_COLUMN_EQ;
      if( pTerm->eOperator & WO_IN ){
        Expr *pExpr = pTerm->pExpr;
        wsFlags |= WHERE_COLUMN_IN;
        if( pExpr->pSelect!=0 ){
          inMultiplier *= 25;
        }else if( ALWAYS(pExpr->pList) ){
          inMultiplier *= pExpr->pList->nExpr + 1;
        }
      }
    }
    nRow = pProbe->aiRowEst[i] * inMultiplier;
    cost = nRow * estLog(inMultiplier);
    nEq = i;







|







 







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
....
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is responsible 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.365 2009/01/24 09:56:15 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** Trace output macros
*/
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
................................................................................
      if( pTerm==0 ) break;
      wsFlags |= WHERE_COLUMN_EQ;
      if( pTerm->eOperator & WO_IN ){
        Expr *pExpr = pTerm->pExpr;
        wsFlags |= WHERE_COLUMN_IN;
        if( pExpr->pSelect!=0 ){
          inMultiplier *= 25;
        }else if( pExpr->pList ){
          inMultiplier *= pExpr->pList->nExpr + 1;
        }
      }
    }
    nRow = pProbe->aiRowEst[i] * inMultiplier;
    cost = nRow * estLog(inMultiplier);
    nEq = i;

Changes to test/in4.test.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
85
86
87
88
89
90
91
92
93









94
95
96
97
98
99
100
...
110
111
112
113
114
115
116






117






























118
119
#
#    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.
#
#***********************************************************************
#
# $Id: in4.test,v 1.2 2008/11/24 15:32:00 shane Exp $

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

do_test in4-1.1 {
  execsql {
    CREATE TABLE t1(a, b);
................................................................................
  execsql { SELECT b FROM t2 WHERE a IN ('1', '2') }
} {one two}

do_test in4-2.8 {
  execsql { SELECT b FROM t2 WHERE a IN ('', '0.0.0', '2') }
} {two}

# add test case from the mailing list 
# (11/7/08 sqlite crash with "WHERE x in ()" query)









do_test in4-3.1 {
  execsql {
    DROP TABLE IF EXISTS t1;
    DROP TABLE IF EXISTS t2;
    CREATE TABLE t1(x, id);
    CREATE TABLE t2(x, id);
    INSERT INTO t1 VALUES(NULL, NULL);
................................................................................
  }
} {}
do_test in4-3.2 {
  execsql {
    SELECT x FROM t1 WHERE id IN () AND x IN (SELECT x FROM t2 WHERE id=1)
  }
} {}





































finish_test








|







 







|
<
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
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
#
#    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.
#
#***********************************************************************
#
# $Id: in4.test,v 1.3 2009/01/24 09:56:15 danielk1977 Exp $

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

do_test in4-1.1 {
  execsql {
    CREATE TABLE t1(a, b);
................................................................................
  execsql { SELECT b FROM t2 WHERE a IN ('1', '2') }
} {one two}

do_test in4-2.8 {
  execsql { SELECT b FROM t2 WHERE a IN ('', '0.0.0', '2') }
} {two}

# The following block of tests test expressions of the form:

#
#    <expr> IN ()
#
# i.e. IN expressions with a literal empty set. 
# 
# This has led to crashes on more than one occasion. Test case in4-3.2 
# was added in reponse to a bug reported on the mailing list on 11/7/2008.
# See also tickets #3602 and #185.
#
do_test in4-3.1 {
  execsql {
    DROP TABLE IF EXISTS t1;
    DROP TABLE IF EXISTS t2;
    CREATE TABLE t1(x, id);
    CREATE TABLE t2(x, id);
    INSERT INTO t1 VALUES(NULL, NULL);
................................................................................
  }
} {}
do_test in4-3.2 {
  execsql {
    SELECT x FROM t1 WHERE id IN () AND x IN (SELECT x FROM t2 WHERE id=1)
  }
} {}
do_test in4-3.3 {
  execsql {
    CREATE TABLE t3(x, y, z);
    CREATE INDEX t3i1 ON t3(x, y);
    INSERT INTO t3 VALUES(1, 1, 1);
    INSERT INTO t3 VALUES(10, 10, 10);
  }
  execsql { SELECT * FROM t3 WHERE x IN () }
} {}
do_test in4-3.4 {
  execsql { SELECT * FROM t3 WHERE x = 10 AND y IN () }
} {}
do_test in4-3.5 {
  execsql { SELECT * FROM t3 WHERE x IN () AND y = 10 }
} {}
do_test in4-3.6 {
  execsql { SELECT * FROM t3 WHERE x IN () OR x = 10 }
} {10 10 10}
do_test in4-3.7 {
  execsql { SELECT * FROM t3 WHERE y IN () }
} {}
do_test in4-3.8 {
  execsql { SELECT x IN() AS a FROM t3 WHERE a }
} {}
do_test in4-3.9 {
  execsql { SELECT x IN() AS a FROM t3 WHERE NOT a }
} {0 0}
do_test in4-3.10 {
  execsql { SELECT * FROM t3 WHERE oid IN () }
} {}
do_test in4-3.11 {
  execsql { SELECT * FROM t3 WHERE x IN (1, 2) OR y IN ()}
} {1 1 1}
do_test in4-3.12 {
  execsql { SELECT * FROM t3 WHERE x IN (1, 2) AND y IN ()}
} {}

finish_test