mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Change the code that collects samples for sqlite_stat2 so that the first sample taken is the (nRow/(2*SQLITE_INDEX_SAMPLES))th entry in the index, where nRow is the total number of index entries.
FossilOrigin-Name: cbfe6e9df39684607cbc9637e3fb3c5ee6af2515
This commit is contained in:
26
manifest
26
manifest
@@ -1,8 +1,5 @@
|
|||||||
-----BEGIN PGP SIGNED MESSAGE-----
|
C Change\sthe\scode\sthat\scollects\ssamples\sfor\ssqlite_stat2\sso\sthat\sthe\sfirst\ssample\staken\sis\sthe\s(nRow/(2*SQLITE_INDEX_SAMPLES))th\sentry\sin\sthe\sindex,\swhere\snRow\sis\sthe\stotal\snumber\sof\sindex\sentries.
|
||||||
Hash: SHA1
|
D 2009-08-20T09:11:06
|
||||||
|
|
||||||
C Incremental\scode\sand\scomment\scleanup\sin\swhere.c.\s\sThere\sis\smore\sto\sbe\sdone.
|
|
||||||
D 2009-08-20T13:45:08
|
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in 0f7761c5d1c62ae7a841e3393ffaff1fa0f5c00a
|
F Makefile.in 0f7761c5d1c62ae7a841e3393ffaff1fa0f5c00a
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@@ -103,7 +100,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
|||||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||||
F src/alter.c 8b42cace4f8e312de596807ba2685179da64fec4
|
F src/alter.c 8b42cace4f8e312de596807ba2685179da64fec4
|
||||||
F src/analyze.c b62fc66fce1f7ac0336f10189ce8a7b809c65b2d
|
F src/analyze.c e3ad83c1462c68cba458e3bdf21f00bc2069bf31
|
||||||
F src/attach.c 13995348fc5a26cdd136a50806faf292aabc173f
|
F src/attach.c 13995348fc5a26cdd136a50806faf292aabc173f
|
||||||
F src/auth.c 802a9439dfa0b8c208b10055cba400e82ef18025
|
F src/auth.c 802a9439dfa0b8c208b10055cba400e82ef18025
|
||||||
F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3
|
F src/backup.c 6f1c2d9862c8a3feb7739dfcca02c1f5352e37f3
|
||||||
@@ -227,7 +224,7 @@ F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
|
|||||||
F test/alter4.test 9386ffd1e9c7245f43eca412b2058d747509cc1f
|
F test/alter4.test 9386ffd1e9c7245f43eca412b2058d747509cc1f
|
||||||
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
||||||
F test/analyze.test ad5329098fe4de4a96852231d53e3e9e6283ad4b
|
F test/analyze.test ad5329098fe4de4a96852231d53e3e9e6283ad4b
|
||||||
F test/analyze2.test f3c0944b854fb33987dbadd1e95913365c33deb7
|
F test/analyze2.test 297d3d63f2f50976c606227040fe36605745d9dd
|
||||||
F test/async.test 8c75d31b8330f8b70cf2571b014d4476a063efdb
|
F test/async.test 8c75d31b8330f8b70cf2571b014d4476a063efdb
|
||||||
F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6
|
F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6
|
||||||
F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e
|
F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e
|
||||||
@@ -750,14 +747,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
||||||
P 167644f33c949b532655c2297aedf13f93876396
|
P 4a5d9550bdc08633535a7869d7748f56ac3e9a36
|
||||||
R fb372557659e26b35bbe68ecf447e1ca
|
R a06a46e0e6092a62dbfee6601412e863
|
||||||
U drh
|
U dan
|
||||||
Z 24339a8c1ef1b0f0335c1d9d08b33691
|
Z 2c479b2a4ff638923d236b4fdc91cdb8
|
||||||
-----BEGIN PGP SIGNATURE-----
|
|
||||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
|
||||||
|
|
||||||
iD8DBQFKjVNnoxKgR168RlERAlJzAJwNEG76YvhUi3RkLEp7KwaZArgnPQCghw3J
|
|
||||||
pSL+ypKyYegD2N/rATGSaX4=
|
|
||||||
=lyU7
|
|
||||||
-----END PGP SIGNATURE-----
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
4a5d9550bdc08633535a7869d7748f56ac3e9a36
|
cbfe6e9df39684607cbc9637e3fb3c5ee6af2515
|
@@ -124,11 +124,13 @@ static void analyzeOneTable(
|
|||||||
int regRec = iMem++; /* Register holding completed record */
|
int regRec = iMem++; /* Register holding completed record */
|
||||||
int regTemp = iMem++; /* Temporary use register */
|
int regTemp = iMem++; /* Temporary use register */
|
||||||
int regRowid = iMem++; /* Rowid for the inserted record */
|
int regRowid = iMem++; /* Rowid for the inserted record */
|
||||||
|
|
||||||
#ifdef SQLITE_ENABLE_STAT2
|
#ifdef SQLITE_ENABLE_STAT2
|
||||||
int regTemp2 = iMem++; /* Temporary use register */
|
int regTemp2 = iMem++; /* Temporary use register */
|
||||||
int regSamplerecno = iMem++; /* Next sample index record number */
|
int regSamplerecno = iMem++; /* Index of next sample to record */
|
||||||
int regRecno = iMem++; /* Register next index record number */
|
int regRecno = iMem++; /* Current sample index */
|
||||||
int regCount = iMem++; /* Total number of records in table */
|
int regLast = iMem++; /* Index of last sample to record */
|
||||||
|
int regFirst = iMem++; /* Index of first sample to record */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
v = sqlite3GetVdbe(pParse);
|
v = sqlite3GetVdbe(pParse);
|
||||||
@@ -171,26 +173,29 @@ static void analyzeOneTable(
|
|||||||
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
|
sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
|
||||||
|
|
||||||
#ifdef SQLITE_ENABLE_STAT2
|
#ifdef SQLITE_ENABLE_STAT2
|
||||||
|
|
||||||
/* If this iteration of the loop is generating code to analyze the
|
/* If this iteration of the loop is generating code to analyze the
|
||||||
** first index in the pTab->pIndex list, then register regCount has
|
** first index in the pTab->pIndex list, then register regLast has
|
||||||
** not been populated. In this case populate it now. */
|
** not been populated. In this case populate it now. */
|
||||||
if( pTab->pIndex==pIdx ){
|
if( pTab->pIndex==pIdx ){
|
||||||
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regCount);
|
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regSamplerecno);
|
||||||
|
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2-1, regTemp);
|
||||||
|
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES*2, regTemp2);
|
||||||
|
|
||||||
|
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regLast);
|
||||||
|
sqlite3VdbeAddOp2(v, OP_Null, 0, regFirst);
|
||||||
|
addr = sqlite3VdbeAddOp3(v, OP_Lt, regSamplerecno, 0, regLast);
|
||||||
|
sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regFirst);
|
||||||
|
sqlite3VdbeAddOp3(v, OP_Multiply, regLast, regTemp, regLast);
|
||||||
|
sqlite3VdbeAddOp2(v, OP_AddImm, regLast, SQLITE_INDEX_SAMPLES*2-2);
|
||||||
|
sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regLast, regLast);
|
||||||
|
sqlite3VdbeJumpHere(v, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zero the regSampleno and regRecno registers. */
|
/* Zero the regSampleno and regRecno registers. */
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, regSampleno);
|
sqlite3VdbeAddOp2(v, OP_Integer, 0, regSampleno);
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, regRecno);
|
sqlite3VdbeAddOp2(v, OP_Integer, 0, regRecno);
|
||||||
|
sqlite3VdbeAddOp2(v, OP_Copy, regFirst, regSamplerecno);
|
||||||
/* If there are less than INDEX_SAMPLES records in the index, then
|
|
||||||
** set the contents of regSampleRecno to integer value INDEX_SAMPLES.
|
|
||||||
** Otherwise, set it to zero. This is to ensure that if there are
|
|
||||||
** less than the said number of entries in the index, no samples at
|
|
||||||
** all are collected. */
|
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regSamplerecno);
|
|
||||||
sqlite3VdbeAddOp3(v, OP_Lt, regSamplerecno, sqlite3VdbeCurrentAddr(v)+2,
|
|
||||||
regCount);
|
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, regSamplerecno);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The block of memory cells initialized here is used as follows.
|
/* The block of memory cells initialized here is used as follows.
|
||||||
@@ -235,6 +240,7 @@ static void analyzeOneTable(
|
|||||||
&& regTabname+2==regSampleno
|
&& regTabname+2==regSampleno
|
||||||
&& regTabname+3==regCol
|
&& regTabname+3==regCol
|
||||||
);
|
);
|
||||||
|
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
|
||||||
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 4, regRec, "aaab", 0);
|
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 4, regRec, "aaab", 0);
|
||||||
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regRowid);
|
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regRowid);
|
||||||
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regRowid);
|
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regRowid);
|
||||||
@@ -245,7 +251,7 @@ static void analyzeOneTable(
|
|||||||
** samplerecno = samplerecno+(remaining records)/(remaining samples)
|
** samplerecno = samplerecno+(remaining records)/(remaining samples)
|
||||||
*/
|
*/
|
||||||
sqlite3VdbeAddOp2(v, OP_AddImm, regSampleno, 1);
|
sqlite3VdbeAddOp2(v, OP_AddImm, regSampleno, 1);
|
||||||
sqlite3VdbeAddOp3(v, OP_Subtract, regRecno, regCount, regTemp);
|
sqlite3VdbeAddOp3(v, OP_Subtract, regRecno, regLast, regTemp);
|
||||||
sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
|
sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
|
||||||
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regTemp2);
|
sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regTemp2);
|
||||||
sqlite3VdbeAddOp3(v, OP_Subtract, regSampleno, regTemp2, regTemp2);
|
sqlite3VdbeAddOp3(v, OP_Subtract, regSampleno, regTemp2, regTemp2);
|
||||||
|
@@ -66,17 +66,18 @@ do_test analyze2-1.1 {
|
|||||||
ANALYZE;
|
ANALYZE;
|
||||||
SELECT * FROM sqlite_stat2;
|
SELECT * FROM sqlite_stat2;
|
||||||
}
|
}
|
||||||
} [list t1 sqlite_autoindex_t1_1 0 0 \
|
} [list t1 sqlite_autoindex_t1_1 0 50 \
|
||||||
t1 sqlite_autoindex_t1_1 1 111 \
|
t1 sqlite_autoindex_t1_1 1 149 \
|
||||||
t1 sqlite_autoindex_t1_1 2 222 \
|
t1 sqlite_autoindex_t1_1 2 249 \
|
||||||
t1 sqlite_autoindex_t1_1 3 333 \
|
t1 sqlite_autoindex_t1_1 3 349 \
|
||||||
t1 sqlite_autoindex_t1_1 4 444 \
|
t1 sqlite_autoindex_t1_1 4 449 \
|
||||||
t1 sqlite_autoindex_t1_1 5 555 \
|
t1 sqlite_autoindex_t1_1 5 549 \
|
||||||
t1 sqlite_autoindex_t1_1 6 666 \
|
t1 sqlite_autoindex_t1_1 6 649 \
|
||||||
t1 sqlite_autoindex_t1_1 7 777 \
|
t1 sqlite_autoindex_t1_1 7 749 \
|
||||||
t1 sqlite_autoindex_t1_1 8 888 \
|
t1 sqlite_autoindex_t1_1 8 849 \
|
||||||
t1 sqlite_autoindex_t1_1 9 999 \
|
t1 sqlite_autoindex_t1_1 9 949 \
|
||||||
]
|
]
|
||||||
|
|
||||||
do_test analyze2-1.2 {
|
do_test analyze2-1.2 {
|
||||||
execsql {
|
execsql {
|
||||||
DELETE FROM t1 WHERe x>9;
|
DELETE FROM t1 WHERe x>9;
|
||||||
@@ -86,7 +87,7 @@ do_test analyze2-1.2 {
|
|||||||
} {t1 sqlite_autoindex_t1_1 {0 1 2 3 4 5 6 7 8 9}}
|
} {t1 sqlite_autoindex_t1_1 {0 1 2 3 4 5 6 7 8 9}}
|
||||||
do_test analyze2-1.3 {
|
do_test analyze2-1.3 {
|
||||||
execsql {
|
execsql {
|
||||||
DELETE FROM t1 WHERE x>5;
|
DELETE FROM t1 WHERE x>8;
|
||||||
ANALYZE;
|
ANALYZE;
|
||||||
SELECT * FROM sqlite_stat2;
|
SELECT * FROM sqlite_stat2;
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,6 @@ do_test analyze2-1.4 {
|
|||||||
}
|
}
|
||||||
} {}
|
} {}
|
||||||
|
|
||||||
|
|
||||||
do_test analyze2-2.1 {
|
do_test analyze2-2.1 {
|
||||||
execsql {
|
execsql {
|
||||||
BEGIN;
|
BEGIN;
|
||||||
@@ -162,7 +162,7 @@ do_test analyze2-3.1 {
|
|||||||
WHERE idx = 't1_x'
|
WHERE idx = 't1_x'
|
||||||
GROUP BY tbl,idx
|
GROUP BY tbl,idx
|
||||||
}
|
}
|
||||||
} {t1 t1_x {0 222 444 666 888 bba ddc ffe hhg jjj}}
|
} {t1 t1_x {100 299 499 699 899 ajj cjj ejj gjj ijj}}
|
||||||
do_test analyze2-3.2 {
|
do_test analyze2-3.2 {
|
||||||
execsql {
|
execsql {
|
||||||
SELECT tbl,idx,group_concat(sample,' ')
|
SELECT tbl,idx,group_concat(sample,' ')
|
||||||
@@ -170,7 +170,7 @@ do_test analyze2-3.2 {
|
|||||||
WHERE idx = 't1_y'
|
WHERE idx = 't1_y'
|
||||||
GROUP BY tbl,idx
|
GROUP BY tbl,idx
|
||||||
}
|
}
|
||||||
} {t1 t1_y {0 222 444 666 888 bba ddc ffe hhg jjj}}
|
} {t1 t1_y {100 299 499 699 899 ajj cjj ejj gjj ijj}}
|
||||||
|
|
||||||
do_test analyze2-3.3 {
|
do_test analyze2-3.3 {
|
||||||
eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 'a' AND 'b'"
|
eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 'a' AND 'b'"
|
||||||
@@ -185,7 +185,7 @@ do_test analyze2-3.6 {
|
|||||||
eqp "SELECT * FROM t1 WHERE x<444 AND y>'h'"
|
eqp "SELECT * FROM t1 WHERE x<444 AND y>'h'"
|
||||||
} {0 0 {TABLE t1 WITH INDEX t1_y}}
|
} {0 0 {TABLE t1 WITH INDEX t1_y}}
|
||||||
do_test analyze2-3.7 {
|
do_test analyze2-3.7 {
|
||||||
eqp "SELECT * FROM t1 WHERE x<221 AND y>'h'"
|
eqp "SELECT * FROM t1 WHERE x<221 AND y>'g'"
|
||||||
} {0 0 {TABLE t1 WITH INDEX t1_x}}
|
} {0 0 {TABLE t1 WITH INDEX t1_x}}
|
||||||
|
|
||||||
do_test analyze2-4.1 {
|
do_test analyze2-4.1 {
|
||||||
@@ -210,7 +210,7 @@ do_test analyze2-4.2 {
|
|||||||
WHERE idx = 't3a'
|
WHERE idx = 't3a'
|
||||||
GROUP BY tbl,idx
|
GROUP BY tbl,idx
|
||||||
}
|
}
|
||||||
} {t3 t3a {AAA bbb CCC ddd EEE fff GGG hhh III jjj}}
|
} {t3 t3a {AfA bEj CEj dEj EEj fEj GEj hEj IEj jEj}}
|
||||||
do_test analyze2-4.3 {
|
do_test analyze2-4.3 {
|
||||||
execsql {
|
execsql {
|
||||||
SELECT tbl,idx,group_concat(sample,' ')
|
SELECT tbl,idx,group_concat(sample,' ')
|
||||||
@@ -218,7 +218,7 @@ do_test analyze2-4.3 {
|
|||||||
WHERE idx = 't3b'
|
WHERE idx = 't3b'
|
||||||
GROUP BY tbl,idx
|
GROUP BY tbl,idx
|
||||||
}
|
}
|
||||||
} {t3 t3b {AAA CCC EEE GGG III bbb ddd fff hhh jjj}}
|
} {t3 t3b {AbA CIj EIj GIj IIj bIj dIj fIj hIj jIj}}
|
||||||
|
|
||||||
do_test analyze2-4.4 {
|
do_test analyze2-4.4 {
|
||||||
eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'"
|
eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'"
|
||||||
@@ -253,7 +253,7 @@ do_test analyze2-5.2 {
|
|||||||
WHERE tbl = 't4'
|
WHERE tbl = 't4'
|
||||||
GROUP BY tbl,idx
|
GROUP BY tbl,idx
|
||||||
}
|
}
|
||||||
} {t4 t4x {aaa bbb ccc ddd eee fff ggg hhh iii jjj}}
|
} {t4 t4x {afa bej cej dej eej fej gej hej iej jej}}
|
||||||
do_test analyze2-5.3 {
|
do_test analyze2-5.3 {
|
||||||
eqp "SELECT * FROM t4 WHERE x>'ccc'"
|
eqp "SELECT * FROM t4 WHERE x>'ccc'"
|
||||||
} {0 0 {TABLE t4 WITH INDEX t4x}}
|
} {0 0 {TABLE t4 WITH INDEX t4x}}
|
||||||
|
Reference in New Issue
Block a user