SQLite

Check-in [e25939fb25]
Login

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

Overview
Comment:Fix a problem with CASTs and the new CSE mechanism. (CVS 4950)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e25939fb25ec8bde8500a672ca5be3cbb514ac3a
User & Date: drh 2008-04-01 12:24:11.000
Context
2008-04-01
15:06
Add the testcase() macro. Additional CSE test coverage. (CVS 4951) (check-in: 492490f9c8 user: drh tags: trunk)
12:24
Fix a problem with CASTs and the new CSE mechanism. (CVS 4950) (check-in: e25939fb25 user: drh tags: trunk)
05:07
Fix the CSE mechanism so that it takes into account column affinity changes that might be imposed by comparison operators. (CVS 4949) (check-in: 91cc646e2b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/expr.c.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.362 2008/04/01 05:07:15 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.363 2008/04/01 12:24:11 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
2200
2201
2202
2203
2204
2205
2206

2207
2208
2209
2210
2211
2212
2213
      to_op = aff - SQLITE_AFF_TEXT + OP_ToText;
      assert( to_op==OP_ToText    || aff!=SQLITE_AFF_TEXT    );
      assert( to_op==OP_ToBlob    || aff!=SQLITE_AFF_NONE    );
      assert( to_op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC );
      assert( to_op==OP_ToInt     || aff!=SQLITE_AFF_INTEGER );
      assert( to_op==OP_ToReal    || aff!=SQLITE_AFF_REAL    );
      sqlite3VdbeAddOp1(v, to_op, inReg);

      break;
    }
#endif /* SQLITE_OMIT_CAST */
    case TK_LT:
    case TK_LE:
    case TK_GT:
    case TK_GE:







>







2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
      to_op = aff - SQLITE_AFF_TEXT + OP_ToText;
      assert( to_op==OP_ToText    || aff!=SQLITE_AFF_TEXT    );
      assert( to_op==OP_ToBlob    || aff!=SQLITE_AFF_NONE    );
      assert( to_op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC );
      assert( to_op==OP_ToInt     || aff!=SQLITE_AFF_INTEGER );
      assert( to_op==OP_ToReal    || aff!=SQLITE_AFF_REAL    );
      sqlite3VdbeAddOp1(v, to_op, inReg);
      sqlite3ExprCacheAffinityChange(pParse, inReg, 1);
      break;
    }
#endif /* SQLITE_OMIT_CAST */
    case TK_LT:
    case TK_LE:
    case TK_GT:
    case TK_GE:
Changes to test/cse.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
#
# Test cases designed to exercise and verify the logic for
# factoring constant expressions out of loops and for
# common subexpression eliminations.
#
# $Id: cse.test,v 1.2 2008/04/01 03:27:39 drh Exp $
#

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

do_test cse-1.1 {
  execsql {







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
#
# Test cases designed to exercise and verify the logic for
# factoring constant expressions out of loops and for
# common subexpression eliminations.
#
# $Id: cse.test,v 1.3 2008/04/01 12:24:11 drh Exp $
#

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

do_test cse-1.1 {
  execsql {
60
61
62
63
64
65
66













67
68
69
70
71
72
73
  }
} {1 -1 -2 0 1 0 2 1 1 1 2 -2 -3 0 1 0 4 4 1 2}
do_test cse-1.8 {
  execsql {
    SELECT a, a%a, a==a, a!=a, a<a, a<=a, a IS NULL, a NOT NULL, a FROM t1
  }
} {1 0 1 0 0 1 0 1 1 2 0 1 0 0 1 0 1 2}














# Overflow the column cache.  Create queries involving more and more
# columns until the cache overflows.  Verify correct operation throughout.
#
do_test cse-2.1 {
  execsql {
    CREATE TABLE t2(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,







>
>
>
>
>
>
>
>
>
>
>
>
>







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
  }
} {1 -1 -2 0 1 0 2 1 1 1 2 -2 -3 0 1 0 4 4 1 2}
do_test cse-1.8 {
  execsql {
    SELECT a, a%a, a==a, a!=a, a<a, a<=a, a IS NULL, a NOT NULL, a FROM t1
  }
} {1 0 1 0 0 1 0 1 1 2 0 1 0 0 1 0 1 2}
do_test cse-1.9 {
  execsql {
    SELECT NOT b, ~b, NOT NOT b, b FROM t1
  }
} {0 -12 1 11 0 -22 1 21}
do_test cse-1.10 {
  explain {
    SELECT CAST(b AS integer), typeof(b), CAST(b AS text), typeof(b) FROM t1
  }
  execsql {
    SELECT CAST(b AS integer), typeof(b), CAST(b AS text), typeof(b) FROM t1
  }
} {11 integer 11 integer 21 integer 21 integer}

# Overflow the column cache.  Create queries involving more and more
# columns until the cache overflows.  Verify correct operation throughout.
#
do_test cse-2.1 {
  execsql {
    CREATE TABLE t2(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,