aboutsummaryrefslogtreecommitdiff
path: root/src/wherecode.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-09-30 18:03:22 +0000
committerdrh <drh@noemail.net>2020-09-30 18:03:22 +0000
commit4f65b3bbfb2205dba20740d0b31c83fbc81f8931 (patch)
tree23633c792e3cd2d80a6ee18dd288dbb15bb69dfd /src/wherecode.c
parenta957e22fa4d54628b6ee991c44cce1f129ee26cd (diff)
downloadsqlite-4f65b3bbfb2205dba20740d0b31c83fbc81f8931.tar.gz
sqlite-4f65b3bbfb2205dba20740d0b31c83fbc81f8931.zip
For the OP_SeekScan opcode, adjust the number of steps run before giving
up based on the estimated number of comparisons needed to perform a seek. FossilOrigin-Name: dc4172e6b8e1f62dc7329a3adb2223f290bc4c8055c265e88182ef432f4bcf10
Diffstat (limited to 'src/wherecode.c')
-rw-r--r--src/wherecode.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index 9dbc1d4b0..5a17130e0 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -1807,7 +1807,16 @@ Bitmask sqlite3WhereCodeOneLoopStart(
if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 ){
assert( op==OP_SeekGE );
assert( regBignull==0 );
- sqlite3VdbeAddOp1(v, OP_SeekScan, 10); VdbeCoverage(v);
+ /* TUNING: The OP_SeekScan opcode seeks to reduce the number
+ ** of expensive seek operations by replacing a single seek with
+ ** 1 or more step operations. The question is, how many steps
+ ** should we try before giving up and going with a seek. The cost
+ ** of a seek is proportional to the logarithm of the of the number
+ ** of entries in the tree, so basing the number of steps to try
+ ** on the estimated number of rows in the btree seems like a good
+ ** guess. */
+ sqlite3VdbeAddOp1(v, OP_SeekScan, (pIdx->aiRowLogEst[0]+9)/10);
+ VdbeCoverage(v);
}
sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
VdbeCoverage(v);