/ Check-in [d6bb7c42]
Login

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

Overview
Comment:Fix a segfault that could occur if an indexed expression was used in a comparison operation within the result-set of a SELECT statement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d6bb7c42ff6309ce168ccdcf03b4cdabfccfc9e2a911d254ac7dc4fea4aa2bc1
User & Date: dan 2017-04-11 11:52:25
Context
2017-04-11
12:20
Add an ALWAYS() around an unreachable condition in sqlite3VdbeMemGrow(). check-in: 0f3eb61f user: drh tags: trunk
11:52
Fix a segfault that could occur if an indexed expression was used in a comparison operation within the result-set of a SELECT statement. check-in: d6bb7c42 user: dan tags: trunk
01:30
When evaluating a query that uses an index on an expression, try to use the expression values read directly from the index rather than reevaluating the expression. check-in: a47efb7c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

    54     54     if( op==TK_REGISTER ) op = pExpr->op2;
    55     55   #ifndef SQLITE_OMIT_CAST
    56     56     if( op==TK_CAST ){
    57     57       assert( !ExprHasProperty(pExpr, EP_IntValue) );
    58     58       return sqlite3AffinityType(pExpr->u.zToken, 0);
    59     59     }
    60     60   #endif
    61         -  if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
           61  +  if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
    62     62       return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
    63     63     }
    64     64     if( op==TK_SELECT_COLUMN ){
    65     65       assert( pExpr->pLeft->flags&EP_xIsSelect );
    66     66       return sqlite3ExprAffinity(
    67     67           pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
    68     68       );

Added test/indexexpr2.test.

            1  +# 2017 April 11
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +set testprefix indexexpr2
           17  +
           18  +do_execsql_test 1 {
           19  +  CREATE TABLE t1(a, b);
           20  +  INSERT INTO t1 VALUES(1, 'one');
           21  +  INSERT INTO t1 VALUES(2, 'two');
           22  +  INSERT INTO t1 VALUES(3, 'three');
           23  +
           24  +  CREATE INDEX i1 ON t1(b || 'x');
           25  +}
           26  +
           27  +do_execsql_test 1.1 {
           28  +  SELECT 'TWOX' == (b || 'x') FROM t1 WHERE (b || 'x')>'onex'
           29  +} {0 0}
           30  +
           31  +do_execsql_test 1.2 {
           32  +  SELECT 'TWOX' == (b || 'x') COLLATE nocase  FROM t1 WHERE (b || 'x')>'onex'
           33  +} {0 1}
           34  +
           35  +finish_test
           36  +