/ Check-in [c39fd9b8]
Login

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

Overview
Comment:Fix problems in the est_count pragma for indexes and WITHOUT ROWID tables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | est_count_pragma
Files: files | file ages | folders
SHA1: c39fd9b8f11b3f1df489df1df4197fe4a670732c
User & Date: drh 2016-10-21 15:36:51
Context
2016-10-21
17:25
Add the btree_sample(INDEX,LOCATION,LIMIT) pragma. check-in: affc2ef5 user: drh tags: est_count_pragma
15:36
Fix problems in the est_count pragma for indexes and WITHOUT ROWID tables. check-in: c39fd9b8 user: drh tags: est_count_pragma
2016-10-20
22:02
Experimental est_count pragma. check-in: 340822af user: drh tags: est_count_pragma
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

  1386   1386     **
  1387   1387     ** Seek in <table-or-index> through the first <fraction> of rows and
  1388   1388     ** estimate the total number of rows based on the path back up to the
  1389   1389     ** root.
  1390   1390     */
  1391   1391     case PragTyp_EST_COUNT: {
  1392   1392       Index *pIdx;
  1393         -    Table *pTab;
         1393  +    Table *pTab = 0;
  1394   1394       Pgno iRoot = 0;
  1395   1395       const char *zName = 0;
  1396   1396       int regResult;
  1397   1397       double r;
  1398   1398       static const char *azCol[] = { "est" };
  1399   1399       if( (pIdx = sqlite3FindIndex(db, zRight, zDb))!=0 ){
  1400   1400         iRoot = pIdx->tnum;
  1401   1401         zName = pIdx->zName;
  1402   1402       }else if( (pTab = sqlite3FindTable(db, zRight, zDb))!=0 ){
  1403         -      iRoot = pTab->tnum;
  1404   1403         zName = pTab->zName;
         1404  +      if( HasRowid(pTab) ){
         1405  +        iRoot = pTab->tnum;
         1406  +      }else{
         1407  +        pIdx = sqlite3PrimaryKeyIndex(pTab);
         1408  +        iRoot = pIdx->tnum;
         1409  +      }
  1405   1410       }else{
  1406   1411         break;
  1407   1412       }
  1408   1413       sqlite3TableLock(pParse, iDb, iRoot, 0, zName);
  1409   1414       regResult = ++pParse->nMem;
  1410   1415       setAllColumnNames(v, 1, azCol);
  1411   1416       if( pValues->nId>=2 ){
................................................................................
  1415   1420         r = 0.5;
  1416   1421       }
  1417   1422       if( r<0.0 ) r = 0.0;
  1418   1423       if( r>1.0 ) r = 1.0;
  1419   1424       sqlite3CodeVerifySchema(pParse, iDb);
  1420   1425       pParse->nTab++;
  1421   1426       sqlite3VdbeAddOp4Int(v, OP_OpenRead, 0, iRoot, iDb, 1);
         1427  +    if( pIdx ) sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  1422   1428       sqlite3VdbeAddOp3(v, OP_EstRowCnt, 0, regResult, (int)(r*1000000000));
  1423   1429       sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
  1424   1430     }
  1425   1431     break;
  1426   1432   
  1427   1433   #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
  1428   1434   # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100