/ Check-in [04bd5cb7]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:The ALTER TABLE command should not attempt to rename objects that are contained within an expression tree that has been optimized out because it is the other branch of an "AND false" expression. Ticket [533010b8cacebe82]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 04bd5cb73287f926f1ecf578998fa6ce1379474e86918c692eae5778d0817cef
User & Date: drh 2019-06-11 02:43:22
Context
2019-06-11
10:43
Add the new sqlite3ExprUnmapAndDelete() function and use it in place of separate calls to sqlite3RenameExprUnmap() and sqlite3ExprDelete(). check-in: 36ea13e0 user: drh tags: trunk
02:43
The ALTER TABLE command should not attempt to rename objects that are contained within an expression tree that has been optimized out because it is the other branch of an "AND false" expression. Ticket [533010b8cacebe82] check-in: 04bd5cb7 user: drh tags: trunk
01:56
Fix repeated test numbers in the altertab2.test file. check-in: e82f235e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   890    890   */
   891    891   Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
   892    892     sqlite3 *db = pParse->db;
   893    893     if( pLeft==0  ){
   894    894       return pRight;
   895    895     }else if( pRight==0 ){
   896    896       return pLeft;
   897         -  }else if( pParse->nErr || IN_RENAME_OBJECT ){
   898         -    return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
   899    897     }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
          898  +    if( IN_RENAME_OBJECT ){
          899  +      sqlite3RenameExprUnmap(pParse, pLeft);
          900  +      sqlite3RenameExprUnmap(pParse, pRight);
          901  +    }
   900    902       sqlite3ExprDelete(db, pLeft);
   901    903       sqlite3ExprDelete(db, pRight);
   902    904       return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
   903    905     }else{
   904    906       return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
   905    907     }
   906    908   }

Changes to test/altertab2.test.

   338    338     INSERT INTO t3 VALUES(4, 5, 6);
   339    339   }
   340    340   
   341    341   do_execsql_test 8.4 {
   342    342     CREATE TABLE t4(a, b);
   343    343     CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2;
   344    344   }
          345  +
          346  +# Do not rename branches of an expression tree that is optimized out by
          347  +# the AND optimization.
          348  +#
   345    349   do_execsql_test 8.5 {
   346    350     ALTER TABLE t4 RENAME a TO c;
   347    351     SELECT sql FROM sqlite_master WHERE name = 'v4'
   348         -} {{CREATE VIEW v4 AS SELECT * FROM t4 WHERE (c=1 AND 0) OR b=2}}
          352  +} {{CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2}}
          353  +#                "a" is not renamed to "c" ---^
          354  +
          355  +# 2019-06-10 https://www.sqlite.org/src/info/533010b8cacebe82
          356  +reset_db
          357  +do_execsql_test 8.6 {
          358  +  CREATE TABLE t0(c0);
          359  +  CREATE INDEX i0 ON t0(LIKELIHOOD(1,2) AND 0);
          360  +  ALTER TABLE t0 RENAME TO t1;
          361  +  SELECT sql FROM sqlite_master WHERE name='i0';
          362  +} {{CREATE INDEX i0 ON "t1"(LIKELIHOOD(1,2) AND 0)}}
   349    363   
   350    364   finish_test