/ Check-in [de826c31]
Login

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

Overview
Comment:Omit non-primary-key columns from the STAT4 samples for WITHOUT ROWID tables. Indexes, both rowid and without-rowid, still hold an exact copy of the index entry.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | stat4-without-rowid
Files: files | file ages | folders
SHA1: de826c31589258f0906f87d65796944103e36d5b
User & Date: drh 2014-06-30 13:56:34
Context
2014-06-30
15:23
Fix where.c so that the primary key values appended to every index entry on a WITHOUT ROWID table may be used when useful. check-in: 6624a61d user: dan tags: stat4-without-rowid
13:56
Omit non-primary-key columns from the STAT4 samples for WITHOUT ROWID tables. Indexes, both rowid and without-rowid, still hold an exact copy of the index entry. check-in: de826c31 user: drh tags: stat4-without-rowid
13:32
Generate complete samples for sqlite_stat4 on WITHOUT ROWID tables. Ticket [b2fa5424e6fcb15b5] check-in: 8cb43edd user: drh tags: stat4-without-rowid
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1162   1162         int regLt = regStat1+1;
  1163   1163         int regDLt = regStat1+2;
  1164   1164         int regSample = regStat1+3;
  1165   1165         int regCol = regStat1+4;
  1166   1166         int regSampleRowid = regCol + nCol;
  1167   1167         int addrNext;
  1168   1168         int addrIsNull;
         1169  +      int nSampleCol;
  1169   1170         u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
  1170   1171   
  1171   1172         pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
  1172   1173   
  1173   1174         addrNext = sqlite3VdbeCurrentAddr(v);
  1174   1175         callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
  1175   1176         addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
................................................................................
  1182   1183         ** the previous loop.  Thus the not-found jump of seekOp will never
  1183   1184         ** be taken */
  1184   1185         VdbeCoverageNeverTaken(v);
  1185   1186   #ifdef SQLITE_ENABLE_STAT3
  1186   1187         sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, 
  1187   1188                                         pIdx->aiColumn[0], regSample);
  1188   1189   #else
  1189         -      i = HasRowid(pTab) ? nCol-1 : pIdx->nColumn-1;
  1190         -      for(; i>=0; i--){
         1190  +      if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
         1191  +        nSampleCol = pIdx->nKeyCol;
         1192  +      }else{
         1193  +        nSampleCol = pIdx->nColumn;
         1194  +      }
         1195  +      for(i=nSampleCol-1; i>=0; i--){
  1191   1196           i16 iCol = pIdx->aiColumn[i];
  1192   1197           sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
  1193   1198         }
  1194         -      sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, pIdx->nColumn, regSample);
         1199  +      sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nSampleCol, regSample);
  1195   1200   #endif
  1196   1201         sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
  1197   1202         sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
  1198   1203         sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
  1199   1204         sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
  1200   1205         sqlite3VdbeJumpHere(v, addrIsNull);
  1201   1206       }