Additional tests and some improvements to the INSERT transfer
optimization.  More testing is needed. (CVS 3661)

FossilOrigin-Name: 830985814345f71ba2def3c206e36aabe9e1ee7c
diff --git a/src/expr.c b/src/expr.c
index d0b858e..39cb065 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.278 2007/02/24 11:52:53 drh Exp $
+** $Id: expr.c,v 1.279 2007/02/24 13:53:05 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2210,7 +2210,7 @@
   }
   if( pA->pSelect || pB->pSelect ) return 0;
   if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 0;
-  if( pA->token.z ){
+  if( pA->op!=TK_COLUMN && pA->token.z ){
     if( pB->token.z==0 ) return 0;
     if( pB->token.n!=pA->token.n ) return 0;
     if( sqlite3StrNICmp((char*)pA->token.z,(char*)pB->token.z,pB->token.n)!=0 ){
diff --git a/src/insert.c b/src/insert.c
index 6823a72..84853d9 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle INSERT statements in SQLite.
 **
-** $Id: insert.c,v 1.174 2007/02/24 13:23:52 drh Exp $
+** $Id: insert.c,v 1.175 2007/02/24 13:53:05 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1297,6 +1297,16 @@
   return 1;
 }
 
+#ifdef SQLITE_TEST
+/*
+** The following global variable is incremented whenever the
+** transfer optimization is used.  This is used for testing
+** purposes only - to make sure the transfer optimization really
+** is happening when it is suppose to.
+*/
+int sqlite3_xferopt_count;
+#endif /* SQLITE_TEST */
+
 /*
 ** Attempt the transfer optimization on INSERTs of the form
 **
@@ -1464,6 +1474,9 @@
   **    *   We can conditionally do the transfer if the destination
   **        table is empty.
   */
+#ifdef SQLITE_TEST
+  sqlite3_xferopt_count++;
+#endif
   iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
   v = sqlite3GetVdbe(pParse);
   iSrc = pParse->nTab++;
diff --git a/src/test1.c b/src/test1.c
index ac0de15..108de7a 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.228 2007/02/05 14:21:48 danielk1977 Exp $
+** $Id: test1.c,v 1.229 2007/02/24 13:53:05 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -4224,6 +4224,7 @@
   extern int sqlite3_memMax;
   extern int sqlite3_like_count;
   extern int sqlite3_tsd_count;
+  extern int sqlite3_xferopt_count;
 #if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE
   extern int threadsOverrideEachOthersLocks;
 #endif
@@ -4261,6 +4262,8 @@
       (char*)&sqlite3_os_trace, TCL_LINK_INT);
   Tcl_LinkVar(interp, "sqlite3_tsd_count",
       (char*)&sqlite3_tsd_count, TCL_LINK_INT);
+  Tcl_LinkVar(interp, "sqlite3_xferopt_count",
+      (char*)&sqlite3_xferopt_count, TCL_LINK_INT);
 #ifndef SQLITE_OMIT_UTF16
   Tcl_LinkVar(interp, "unaligned_string_counter",
       (char*)&unaligned_string_counter, TCL_LINK_INT);