SQLite

Check-in [f36d07a5b2]
Login

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

Overview
Comment:Simplification to the upsert logic.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | upsert
Files: files | file ages | folders
SHA3-256: f36d07a5b24cc48e3daa8b18dd34c50d9025c6c0ba019926610538b54f7b66ec
User & Date: drh 2018-04-17 18:18:05.768
Context
2018-04-17
18:50
TK_REGISTER expressions nodes are probably not constant. Make sure sqlite3ExprIsConstant() knows this. (check-in: f3d91cad92 user: drh tags: upsert)
18:18
Simplification to the upsert logic. (check-in: f36d07a5b2 user: drh tags: upsert)
18:16
Add some more simple test cases for UPSERT. And a minor fix. (check-in: 27cd3b2fb2 user: dan tags: upsert)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/insert.c.
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460



1461
1462
1463
1464
1465
1466
1467
  **   (C)  Unique index that do use OE_Replace by default.
  **
  ** The ordering of (2) and (3) is accomplished by making sure the linked
  ** list of indexes attached to a table puts all OE_Replace indexes last
  ** in the list.  See sqlite3CreateIndex() for where that happens.
  */

  /* If there is an ON CONFLICT clause without a constraint-target
  ** (In other words, one of "ON CONFLICT DO NOTHING" or
  ** "ON DUPLICATION KEY UPDATE") then change the overrideError to
  ** whichever is appropriate.
  */
  if( pUpsert ){
    if( pUpsert->pUpsertTarget==0 ){
      if( pUpsert->pUpsertSet==0 ){
        /* An ON CONFLICT DO NOTHING clause, without a constraint-target.
        ** Make all unique constraint resolution be OE_Ignore */

        overrideError = OE_Ignore;
        pUpsert = 0;
      }else{
        /* An ON DUPLICATE KEY UPDATE clause.  All unique constraints
        ** do upsert processing */
        overrideError = OE_Update;
      }
    }else if( (pUpIdx = pUpsert->pUpsertIdx)!=0 ){



      sAddr.upsertTop = sqlite3VdbeMakeLabel(v);
      sAddr.upsertBtm = sqlite3VdbeMakeLabel(v);
    }
  }

  /* If rowid is changing, make sure the new rowid does not previously
  ** exist in the table.







<
<
<
<
<


<
|
|
>
|
|
<
<
<
<
<

>
>
>







1436
1437
1438
1439
1440
1441
1442





1443
1444

1445
1446
1447
1448
1449





1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
  **   (C)  Unique index that do use OE_Replace by default.
  **
  ** The ordering of (2) and (3) is accomplished by making sure the linked
  ** list of indexes attached to a table puts all OE_Replace indexes last
  ** in the list.  See sqlite3CreateIndex() for where that happens.
  */






  if( pUpsert ){
    if( pUpsert->pUpsertTarget==0 ){

      /* An ON CONFLICT DO NOTHING clause, without a constraint-target.
      ** Make all unique constraint resolution be OE_Ignore */
      assert( pUpsert->pUpsertSet==0 );
      overrideError = OE_Ignore;
      pUpsert = 0;





    }else if( (pUpIdx = pUpsert->pUpsertIdx)!=0 ){
      /* If the constraint-target is on some column other than
      ** then ROWID, then we might need to move the UPSERT around
      ** so that it occurs in the correct order. */
      sAddr.upsertTop = sqlite3VdbeMakeLabel(v);
      sAddr.upsertBtm = sqlite3VdbeMakeLabel(v);
    }
  }

  /* If rowid is changing, make sure the new rowid does not previously
  ** exist in the table.