SQLite

Check-in [2c62ffcb86]
Login

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

Overview
Comment:The XFER optimization works if the target table lacks an integer primary key and is not empty as long as it has no indices. It always has and continues to work if the target table was empty. (CVS 3779)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2c62ffcb865655e8b91aaf81601548ea540c6088
User & Date: drh 2007-03-31 13:00:26.000
Context
2007-03-31
15:02
Improved test coverage for printf.c. (CVS 3780) (check-in: c2badb208f user: drh tags: trunk)
13:00
The XFER optimization works if the target table lacks an integer primary key and is not empty as long as it has no indices. It always has and continues to work if the target table was empty. (CVS 3779) (check-in: 2c62ffcb86 user: drh tags: trunk)
10:00
More coverage for pager.c. (CVS 3778) (check-in: 665b119a24 user: danielk1977 tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/insert.c.
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
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 C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.181 2007/03/29 13:35:36 drh Exp $
** $Id: insert.c,v 1.182 2007/03/31 13:00:26 drh Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510





1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532


1533

1534
1535
1536
1537
1538
1539
1540
1500
1501
1502
1503
1504
1505
1506




1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544







-
-
-
-
+
+
+
+
+














-

+






+
+

+







#endif
  iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
  v = sqlite3GetVdbe(pParse);
  iSrc = pParse->nTab++;
  iDest = pParse->nTab++;
  counterMem = autoIncBegin(pParse, iDbDest, pDest);
  sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
  if( pDest->iPKey<0 ){
    /* The tables do not have an INTEGER PRIMARY KEY so that
    ** transfer optimization is only allowed if the destination
    ** table is initially empty
  if( pDest->iPKey<0 && pDest->pIndex!=0 ){
    /* If tables do not have an INTEGER PRIMARY KEY and there
    ** are indices to be copied and the destination is not empty,
    ** we have to disallow the transfer optimization because the
    ** the rowids might change which will mess up indexing.
    */
    addr1 = sqlite3VdbeAddOp(v, OP_Rewind, iDest, 0);
    emptyDestTest = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
    sqlite3VdbeJumpHere(v, addr1);
  }else{
    emptyDestTest = 0;
  }
  sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
  emptySrcTest = sqlite3VdbeAddOp(v, OP_Rewind, iSrc, 0);
  if( pDest->pIndex!=0 ){
    sqlite3VdbeAddOp(v, OP_Rowid, iSrc, 0);
    memRowid = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_MemStore, memRowid, pDest->iPKey>=0);
  }
  addr1 = sqlite3VdbeAddOp(v, OP_Rowid, iSrc, 0);
  if( pDest->iPKey>=0 ){
    addr1 = sqlite3VdbeAddOp(v, OP_Rowid, iSrc, 0);
    sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
    addr2 = sqlite3VdbeAddOp(v, OP_NotExists, iDest, 0);
    sqlite3VdbeOp3(v, OP_Halt, SQLITE_CONSTRAINT, onError, 
                      "PRIMARY KEY must be unique", P3_STATIC);
    sqlite3VdbeJumpHere(v, addr2);
    autoIncStep(pParse, counterMem);
  }else if( pDest->pIndex==0 ){
    addr1 = sqlite3VdbeAddOp(v, OP_NewRowid, iDest, 0);
  }else{
    addr1 = sqlite3VdbeAddOp(v, OP_Rowid, iSrc, 0);
    assert( pDest->autoInc==0 );
  }
  sqlite3VdbeAddOp(v, OP_RowData, iSrc, 0);
  sqlite3VdbeOp3(v, OP_Insert, iDest,
                    OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND,
                    pDest->zName, 0);
  sqlite3VdbeAddOp(v, OP_Next, iSrc, addr1);