/ Check-in [badd24d9]
Login

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

Overview
Comment:Fix a couple of problems in code related to sqlite_stat4.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sqlite_stat4
Files: files | file ages | folders
SHA1: badd24d987240db5528b37d1c177431617079f9b
User & Date: dan 2013-08-05 05:34:30
Context
2013-08-05
18:00
Use N separate cursors when scanning an index with N columns to collect sqlite_stat4 data. This fixes a problem with collecting incorrect nEq values from multi-column indexes. check-in: 3a71afe6 user: dan tags: sqlite_stat4
05:34
Fix a couple of problems in code related to sqlite_stat4. check-in: badd24d9 user: dan tags: sqlite_stat4
2013-08-03
20:24
Begin adding experimental sqlite_stat4 table. This commit is buggy. check-in: 2beea303 user: dan tags: sqlite_stat4
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

367
368
369
370
371
372
373




374
375
376



377
378
379
380
381
382
383
....
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
  ){
    doInsert = 1;
  }
  if( !doInsert ) return;

  /* Fill in the new Stat4Sample object. */
  if( p->nSample==p->mxSample ){




    assert( p->nSample - iMin - 1 >= 0 );
    memmove(&p->a[iMin], &p->a[iMin+1], sizeof(p->a[0])*(p->nSample-iMin-1));
    pSample = &p->a[p->nSample-1];



  }else{
    pSample = &p->a[p->nSample++];
  }
  pSample->iRowid = rowid;
  pSample->iHash = h;
  pSample->isPSample = isPSample;
  pSample->nSumEq = nSumEq;
................................................................................
  }else{
    pIndex = 0;
  }
  z = argv[2];

  if( pIndex ){
    int bUnordered = 0;
    decodeIntArray((char*)z, pIndex->nColumn, pIndex->aiRowEst, &bUnordered);
    if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
    pIndex->bUnordered = bUnordered;
  }else{
    decodeIntArray((char*)z, 1, &pTable->nRowEst, 0);
  }

  return 0;







>
>
>
>

|

>
>
>







 







|







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
....
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
  ){
    doInsert = 1;
  }
  if( !doInsert ) return;

  /* Fill in the new Stat4Sample object. */
  if( p->nSample==p->mxSample ){
    struct Stat4Sample *pMin = &p->a[iMin];
    tRowcnt *anEq = pMin->anEq;
    tRowcnt *anDLt = pMin->anDLt;
    tRowcnt *anLt = pMin->anLt;
    assert( p->nSample - iMin - 1 >= 0 );
    memmove(pMin, &pMin[1], sizeof(p->a[0])*(p->nSample-iMin-1));
    pSample = &p->a[p->nSample-1];
    pSample->anEq = anEq;
    pSample->anDLt = anDLt;
    pSample->anLt = anLt;
  }else{
    pSample = &p->a[p->nSample++];
  }
  pSample->iRowid = rowid;
  pSample->iHash = h;
  pSample->isPSample = isPSample;
  pSample->nSumEq = nSumEq;
................................................................................
  }else{
    pIndex = 0;
  }
  z = argv[2];

  if( pIndex ){
    int bUnordered = 0;
    decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, &bUnordered);
    if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
    pIndex->bUnordered = bUnordered;
  }else{
    decodeIntArray((char*)z, 1, &pTable->nRowEst, 0);
  }

  return 0;

Changes to test/analyze9.test.

40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
do_execsql_test 1.1 {
  ANALYZE;
} {}

do_execsql_test 1.2 {
  SELECT tbl,idx,nEq,nLt,nDLt,s(sample) FROM sqlite_stat4;
} {

  t1 i1 {1 1} {1 1} {1 1} ...(1)(1) 
  t1 i1 {1 1} {2 2} {2 2} ...(2)(2) 
  t1 i1 {1 1} {3 3} {3 3} ...(3)(3)
  t1 i1 {1 1} {4 4} {4 4} ...(4)(4)
}


finish_test








>









40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
do_execsql_test 1.1 {
  ANALYZE;
} {}

do_execsql_test 1.2 {
  SELECT tbl,idx,nEq,nLt,nDLt,s(sample) FROM sqlite_stat4;
} {
  t1 i1 {1 1} {0 0} {0 0} ...(0)(0) 
  t1 i1 {1 1} {1 1} {1 1} ...(1)(1) 
  t1 i1 {1 1} {2 2} {2 2} ...(2)(2) 
  t1 i1 {1 1} {3 3} {3 3} ...(3)(3)
  t1 i1 {1 1} {4 4} {4 4} ...(4)(4)
}


finish_test

Changes to test/table.test.

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Dropping sqlite_statN tables is OK.
#
do_test table-5.2.1 {
  db eval {
    ANALYZE;
    DROP TABLE IF EXISTS sqlite_stat1;
    DROP TABLE IF EXISTS sqlite_stat2;
    DROP TABLE IF EXISTS sqlite_stat3;
    SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_stat*';
  }
} {}

# Make sure an EXPLAIN does not really create a new table
#
do_test table-5.3 {







|







263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Dropping sqlite_statN tables is OK.
#
do_test table-5.2.1 {
  db eval {
    ANALYZE;
    DROP TABLE IF EXISTS sqlite_stat1;
    DROP TABLE IF EXISTS sqlite_stat2;
    DROP TABLE IF EXISTS sqlite_stat4;
    SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_stat*';
  }
} {}

# Make sure an EXPLAIN does not really create a new table
#
do_test table-5.3 {