-C Merge\schanges\sfrom\strunk.
-D 2016-03-04T18:45:12.274
+C Simplify\sthe\scomputation\sof\sIndex.aAvgEq.
+D 2016-03-04T19:55:02.239
F Makefile.in ead489fe5d3313b8a2a8d5f3710173a4b50dd2e0
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc d68db8ddac21ea2576ea5b446f12cf9ebe897a03
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c 1bb0709b3048e24217b80ec6bd78a3e99a47c01b
-F src/analyze.c dac2f49d4a622091df1964a9ec9de1d2cd0584bb
+F src/analyze.c a89554ee91a8b17b8a745770ddcb4e85a1e27a69
F src/attach.c a3724c64de1099d85e30751213d285752aed9505
F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
F src/backup.c f60f0aa55d25d853ffde53d0b0370a7bb7ee41ce
F test/shrink.test 1b4330b1fd9e818c04726d45cb28db73087535ce
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
F test/skipscan1.test d37a75b4be4eb9dedeb69b4f38b1d0a74b5021d7
-F test/skipscan2.test 9fb533b9b66d33d5036fa86bbad1c1ae20861a3f
+F test/skipscan2.test 4cf572db43ca6b2f3b8162295e984c3555e4abeb
F test/skipscan3.test ec5bab3f81c7038b43450e7b3062e04a198bdbb5
F test/skipscan5.test 67817a4b6857c47e0e33ba3e506da6f23ef68de2
F test/skipscan6.test 5866039d03a56f5bd0b3d172a012074a1d90a15b
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 21bfd47c4245846b12aeeb7cf0212529e300b878 cb9302cca423de41305719a49208daa392ec09da
-R 636b0403188c11b543ab3d2b973ee377
+P 5294c977d9b15a4f29028782ef253329bd739fc0
+R 0d9736ab8ee345d5b31279fe6ba1cf6e
U drh
-Z 61c960fff1efcb39fcf10879f7f27e05
+Z 7c24b575cc7f48aed8f15dbed80ebac8
-5294c977d9b15a4f29028782ef253329bd739fc0
\ No newline at end of file
+c448873006cda294cdaf6b61e75a07f121ba34ea
\ No newline at end of file
*/
static void initAvgEq(Index *pIdx){
if( pIdx ){
- IndexSample *aSample = pIdx->aSample;
- IndexSample *pFinal = &aSample[pIdx->nSample-1];
- int iCol;
- int nCol = 1;
- if( pIdx->nSampleCol>1 ){
+ int nSample = pIdx->nSample; /* Number of samples */
+ int nCol = pIdx->nSampleCol; /* Number of columns sampled */
+ IndexSample *aSample = pIdx->aSample; /* The samples */
+ IndexSample *pFinal = &aSample[nSample-1]; /* The last sample */
+ int iCol; /* Loop counter of columns */
+ if( nCol>1 ){
/* If this is stat4 data, then calculate aAvgEq[] values for all
** sample columns except the last. The last is always set to 1, as
** once the trailing PK fields are considered all index keys are
** unique. */
- nCol = pIdx->nSampleCol-1;
+ nCol--;
pIdx->aAvgEq[nCol] = 1;
}
for(iCol=0; iCol<nCol; iCol++){
- int nSample = pIdx->nSample;
int i; /* Used to iterate through samples */
+ u32 nDSample = 0; /* Number of distinct samples less than pFinal*/
tRowcnt sumEq = 0; /* Sum of the nEq values */
- tRowcnt avgEq = 0;
+ tRowcnt avgEq; /* Average repeats for unsampled entries */
tRowcnt nRow; /* Number of rows in index */
- i64 nSum100 = 0; /* Number of terms contributing to sumEq */
- i64 nDist100; /* Number of distinct values in index */
+ tRowcnt prevLt = 0; /* Number of values less than previous sample */
+ tRowcnt thisLt; /* Number of values less than current sample */
if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
- nRow = pFinal->anLt[iCol];
- nDist100 = (i64)100 * pFinal->anDLt[iCol];
- nSample--;
+ nRow = pFinal->anLt[iCol] + pFinal->anEq[iCol];
}else{
nRow = pIdx->aiRowEst[0];
- nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
}
pIdx->nRowEst0 = nRow;
-
- /* Set nSum to the number of distinct (iCol+1) field prefixes that
- ** occur in the stat4 table for this index. Set sumEq to the sum of
- ** the nEq values for column iCol for the same set (adding the value
- ** only once where there exist duplicate prefixes). */
- for(i=0; i<nSample; i++){
- if( i==(pIdx->nSample-1)
- || aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
- ){
+ for(i=0; (thisLt = aSample[i].anLt[iCol])<pFinal->anLt[iCol]; i++){
+ if( i==0 || thisLt!=prevLt ){
sumEq += aSample[i].anEq[iCol];
- nSum100 += 100;
+ nDSample++;
}
+ prevLt = thisLt;
}
-
- if( nDist100>nSum100 ){
- avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
+ if( pFinal->anDLt[iCol] > nDSample ){
+ avgEq = (pFinal->anLt[iCol] - sumEq)/(pFinal->anDLt[iCol] - nDSample);
+ }else{
+ avgEq = 1;
}
if( avgEq==0 ) avgEq = 1;
pIdx->aAvgEq[iCol] = avgEq;
INSERT INTO people VALUES('Robert','student',159);
INSERT INTO people VALUES('Sally','student',166);
INSERT INTO people VALUES('Tom','student',171);
-/*
- INSERT INTO people VALUES('Ursula','student',170);
- INSERT INTO people VALUES('Vance','student',179);
- INSERT INTO people VALUES('Willma','student',175);
- INSERT INTO people VALUES('Xavier','teacher',185);
- INSERT INTO people VALUES('Yvonne','student',149);
- INSERT INTO people VALUES('Zach','student',170);
-*/
}
# Without ANALYZE, a skip-scan is not used
INSERT INTO people VALUES('Ursula','student',170);
ANALYZE;
SELECT stat FROM sqlite_stat1 WHERE idx='people_idx1';
-} {{21 18 3}}
+} {{21 13 2}}
db cache flush
do_execsql_test skipscan2-1.9 {
SELECT name FROM people WHERE height<=161 ORDER BY +name;
do_execsql_test skipscan2-2.5eqp {
EXPLAIN QUERY PLAN
SELECT name FROM peoplew WHERE height<=161 ORDER BY +name;
-} {/*INDEX peoplew_idx1 */}
+} {/*INDEX peoplew_idx1*/}
# A skip-scan on a PK index of a WITHOUT ROWID table.
#