/ Check-in [f9769d70]
Login

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

Overview
Comment:Fix sqlite3_analyzer so that it works with WITHOUT ROWID tables. Fix index generation for secondary indices that include fields from the PRIMARY KEY.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | omit-rowid
Files: files | file ages | folders
SHA1: f9769d701c65770f4b8488f541c59e508393e6c2
User & Date: drh 2013-11-01 20:30:36
Context
2013-11-01
22:02
Size KeyInfo objects so that IdxInserts always compare the correct number of fields. check-in: 302a8139 user: drh tags: omit-rowid
20:30
Fix sqlite3_analyzer so that it works with WITHOUT ROWID tables. Fix index generation for secondary indices that include fields from the PRIMARY KEY. check-in: f9769d70 user: drh tags: omit-rowid
18:14
Additional UPDATE test cases for WITHOUT ROWID. check-in: 65384ae0 user: drh tags: omit-rowid
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1652   1652         continue;
  1653   1653       }
  1654   1654       for(i=n=0; i<nPk; i++){
  1655   1655         if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
  1656   1656       }
  1657   1657       if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
  1658   1658       for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
  1659         -      if( !hasColumn(pIdx->aiColumn, j, pPk->aiColumn[i]) ){
  1660         -        assert( j<pPk->nColumn );
         1659  +      if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ){
  1661   1660           pIdx->aiColumn[j] = pPk->aiColumn[i];
  1662   1661           pIdx->azColl[j] = pPk->azColl[i];
  1663   1662           j++;
  1664   1663         }
  1665   1664       }
  1666   1665       assert( pIdx->nColumn==j );
  1667   1666       assert( pIdx->nKeyCol+n==j );
................................................................................
  2995   2994       }
  2996   2995       pIndex->azColl[i] = zColl;
  2997   2996       requestedSortOrder = pListItem->sortOrder & sortOrderMask;
  2998   2997       pIndex->aSortOrder[i] = (u8)requestedSortOrder;
  2999   2998       if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
  3000   2999     }
  3001   3000     if( pPk ){
  3002         -    for(j=0; j<pPk->nKeyCol; j++, i++){
  3003         -      pIndex->aiColumn[i] = pPk->aiColumn[j];
  3004         -      pIndex->azColl[i] = pPk->azColl[j];
  3005         -      pIndex->aSortOrder[i] = pPk->aSortOrder[j];
         3001  +    for(j=0; j<pPk->nKeyCol; j++){
         3002  +      int x = pPk->aiColumn[j];
         3003  +      if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
         3004  +        pIndex->nColumn--; 
         3005  +      }else{
         3006  +        pIndex->aiColumn[i] = x;
         3007  +        pIndex->azColl[i] = pPk->azColl[j];
         3008  +        pIndex->aSortOrder[i] = pPk->aSortOrder[j];
         3009  +        i++;
         3010  +      }
  3006   3011       }
         3012  +    assert( i==pIndex->nColumn );
  3007   3013     }else{
  3008   3014       pIndex->aiColumn[i] = -1;
  3009   3015       pIndex->azColl[i] = "BINARY";
  3010   3016     }
  3011   3017     sqlite3DefaultRowEst(pIndex);
  3012   3018     if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
  3013   3019   

Changes to src/insert.c.

  1520   1520             sqlite3VdbeAddOp3(v, OP_Eq, regOldData+1+x, addrUniqueOk, regIdx+x);
  1521   1521           }
  1522   1522         }else{
  1523   1523           /* For a UNIQUE index on a WITHOUT ROWID table, conflict only if the
  1524   1524           ** PRIMARY KEY value of the match is different from the old PRIMARY KEY
  1525   1525           ** value from before the update. */
  1526   1526           int addrConflict = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
  1527         -        assert( pIdx->nKeyCol + pPk->nKeyCol == pIdx->nColumn );
  1528   1527           for(i=0; i<pPk->nKeyCol-1; i++){
  1529   1528             sqlite3VdbeAddOp3(v, OP_Ne,
  1530   1529                              regOldData+pPk->aiColumn[i]+1, addrConflict, regR+i);
  1531   1530           }
  1532   1531           sqlite3VdbeAddOp3(v, OP_Eq,
  1533   1532                             regOldData+pPk->aiColumn[i]+1, addrUniqueOk, regR+i);
  1534   1533         }

Changes to tool/spaceanal.tcl.

   567    567   if {$nindex>0} {
   568    568     subreport {All tables and indices} 1 0
   569    569   }
   570    570   subreport {All tables} {NOT is_index} 0
   571    571   if {$nindex>0} {
   572    572     subreport {All indices} {is_index} 0
   573    573   }
   574         -foreach tbl [mem eval {SELECT name FROM space_used WHERE NOT is_index
          574  +foreach tbl [mem eval {SELECT DISTINCT tblname name FROM space_used
   575    575                          ORDER BY name}] {
   576    576     set qn [quote $tbl]
   577    577     set name [string toupper $tbl]
   578    578     set n [mem eval {SELECT count(*) FROM space_used WHERE tblname=$tbl}]
   579    579     if {$n>1} {
   580    580       set idxlist [mem eval "SELECT name FROM space_used
   581    581                               WHERE tblname='$qn' AND is_index