/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

890
891
892
893
894
895
896
897
898
899




900
901
902
903
904
905
906
*/
Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
  sqlite3 *db = pParse->db;
  if( pLeft==0  ){
    return pRight;
  }else if( pRight==0 ){
    return pLeft;
  }else if( pParse->nErr || IN_RENAME_OBJECT ){
    return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
  }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){




    sqlite3ExprDelete(db, pLeft);
    sqlite3ExprDelete(db, pRight);
    return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
  }else{
    return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
  }
}







<
<

>
>
>
>







890
891
892
893
894
895
896


897
898
899
900
901
902
903
904
905
906
907
908
*/
Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
  sqlite3 *db = pParse->db;
  if( pLeft==0  ){
    return pRight;
  }else if( pRight==0 ){
    return pLeft;


  }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){
    if( IN_RENAME_OBJECT ){
      sqlite3RenameExprUnmap(pParse, pLeft);
      sqlite3RenameExprUnmap(pParse, pRight);
    }
    sqlite3ExprDelete(db, pLeft);
    sqlite3ExprDelete(db, pRight);
    return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
  }else{
    return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
  }
}

Changes to test/altertab2.test.

338
339
340
341
342
343
344




345
346
347
348

349









350
  INSERT INTO t3 VALUES(4, 5, 6);
}

do_execsql_test 8.4 {
  CREATE TABLE t4(a, b);
  CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2;
}




do_execsql_test 8.5 {
  ALTER TABLE t4 RENAME a TO c;
  SELECT sql FROM sqlite_master WHERE name = 'v4'
} {{CREATE VIEW v4 AS SELECT * FROM t4 WHERE (c=1 AND 0) OR b=2}}











finish_test







>
>
>
>



|
>

>
>
>
>
>
>
>
>
>

338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
  INSERT INTO t3 VALUES(4, 5, 6);
}

do_execsql_test 8.4 {
  CREATE TABLE t4(a, b);
  CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2;
}

# Do not rename branches of an expression tree that is optimized out by
# the AND optimization.
#
do_execsql_test 8.5 {
  ALTER TABLE t4 RENAME a TO c;
  SELECT sql FROM sqlite_master WHERE name = 'v4'
} {{CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2}}
#                "a" is not renamed to "c" ---^

# 2019-06-10 https://www.sqlite.org/src/info/533010b8cacebe82
reset_db
do_execsql_test 8.6 {
  CREATE TABLE t0(c0);
  CREATE INDEX i0 ON t0(LIKELIHOOD(1,2) AND 0);
  ALTER TABLE t0 RENAME TO t1;
  SELECT sql FROM sqlite_master WHERE name='i0';
} {{CREATE INDEX i0 ON "t1"(LIKELIHOOD(1,2) AND 0)}}

finish_test