SQLite

Check-in [c39fd9b8f1]
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
Timelines: family | ancestors | descendants | both | est_count_pragma
Files: files | file ages | folders
SHA1: c39fd9b8f11b3f1df489df1df4197fe4a670732c
User & Date: drh 2016-10-21 15:36:51.551
Context
2016-10-21
17:25
Add the btree_sample(INDEX,LOCATION,LIMIT) pragma. (check-in: affc2ef5ee user: drh tags: est_count_pragma)
15:36
Fix problems in the est_count pragma for indexes and WITHOUT ROWID tables. (check-in: c39fd9b8f1 user: drh tags: est_count_pragma)
2016-10-20
22:02
Experimental est_count pragma. (check-in: 340822afbe user: drh tags: est_count_pragma)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pragma.c.
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402


1403


1404

1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
  **
  ** Seek in <table-or-index> through the first <fraction> of rows and
  ** estimate the total number of rows based on the path back up to the
  ** root.
  */
  case PragTyp_EST_COUNT: {
    Index *pIdx;
    Table *pTab;
    Pgno iRoot = 0;
    const char *zName = 0;
    int regResult;
    double r;
    static const char *azCol[] = { "est" };
    if( (pIdx = sqlite3FindIndex(db, zRight, zDb))!=0 ){
      iRoot = pIdx->tnum;
      zName = pIdx->zName;
    }else if( (pTab = sqlite3FindTable(db, zRight, zDb))!=0 ){


      iRoot = pTab->tnum;


      zName = pTab->zName;

    }else{
      break;
    }
    sqlite3TableLock(pParse, iDb, iRoot, 0, zName);
    regResult = ++pParse->nMem;
    setAllColumnNames(v, 1, azCol);
    if( pValues->nId>=2 ){
      const char *z = pValues->a[1].zName;
      sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
    }else{
      r = 0.5;
    }
    if( r<0.0 ) r = 0.0;
    if( r>1.0 ) r = 1.0;
    sqlite3CodeVerifySchema(pParse, iDb);
    pParse->nTab++;
    sqlite3VdbeAddOp4Int(v, OP_OpenRead, 0, iRoot, iDb, 1);

    sqlite3VdbeAddOp3(v, OP_EstRowCnt, 0, regResult, (int)(r*1000000000));
    sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
  }
  break;

#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100







|









>
>
|
>
>
|
>

















>







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

#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100