-C Merge\slatest\strunk\senhancements\sand\sfixes\sinto\sthe\sexperimental\nflex-search\sbranch.
-D 2025-06-12T13:40:29.659
+C Preliminary\scode\sgeneration\sfor\sflex-search.\s\sAdd\sa\sno-op\sIfUseIndex\sopcode\nas\sa\splaceholder.
+D 2025-06-12T19:02:54.531
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F src/utf.c 7267c3fb9e2467020507601af3354c2446c61f444387e094c779dccd5ca62165
F src/util.c 36fb1150062957280777655976f3f9a75db236cb8207a0770ceae8d5ec17fcd3
F src/vacuum.c 1bacdd0a81d2b5dc1c508fbf0d938c89fa78dd8d5b46ec92686d44030d4f4789
-F src/vdbe.c 8a79078298fdc81f09201fac5b454adb97ee8bf30c6cf412a856a17dd144656d
+F src/vdbe.c c6e9d572514901c879ea16e286bbfa1674f3bebd9284e36f34b96c1116938e37
F src/vdbe.h 93761ed7c6b8bc19524912fd9b9b587d41bf4f1d0ade650a00dadc10518d8958
F src/vdbeInt.h 0bc581a9763be385e3af715e8c0a503ba8422c2b7074922faf4bb0d6ae31b15e
F src/vdbeapi.c 613a6f29efacd6ed83e886b6e52db0fe52ba80a596b0a137608db1948bad90a9
F src/wal.c b0f848cfba8dd057f77073493cdd542f9125b4cf87941f53e9d0db21604155c8
F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
-F src/where.c e20d6cf7de2be13fa9f41ba5e499e183319e4cc56202999146085303a5c4eb63
+F src/where.c 1a663cfc00974dec3e37e378f407ffc5a6ce0c06506b8b7ea27c1fc592746f0e
F src/whereInt.h b0c5487551dc7821426cac213fd5c194a558cab9dfd4e130d71f7afa6416463c
-F src/wherecode.c b608a9e2e71893bfd2617f354fda0201be521844a0330a53fdc0c490cd80c3a6
+F src/wherecode.c e1e64cd05bbc0381c1c08c354853ea6d3d7cb468641e86ee5e803168d114df0d
F src/whereexpr.c 2415c8eee5ff89a8b709d7d83d71c1ff986cd720d0520057e1d8a5371339012a
F src/window.c d01227141f622f24fbe36ca105fbe6ef023f9fd98f1ccd65da95f88886565db5
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/autoinc.test 9df9930966dbe92c55ef37a4d89112cfd537be0d0596d397177c12db9e581be0
F test/autoindex1.test 65931519206bbec71948b11e125af0656435a0937973fe5fed70d776a712911f
F test/autoindex2.test 12ef578928102baaa0dc23ad397601a2f4ecb0df
-F test/autoindex3.test ca502c8050166ac6107a7b4fe4e951f4d3270a23a958af02b14f1b962b83c4b6
+F test/autoindex3.test 4d0a7a412622eb70a8901d8dbac6dc806f71ec8b80c1a0ea0593c4218e95e8dc
F test/autoindex4.test 3c2105e9172920e26f950ba3c5823e4972190e022c1e6f260ba476b0af24c593
F test/autoindex5.test 3fb938cbf4e7f3896563ce04e2a24b0bc653fc6245b4bf3268cd7b20f441d87f
F test/autovacuum.test 00671369bbf96c6a49989a9425f5b78b94075d6a4b031e5e00000c2c32f365df
F test/corruptL.test 652fc8ac0763a6fd3eb28b951d481924167b2d9936083bcc68253b2274a0c8fe
F test/corruptM.test 7d574320e08c1b36caa3e47262061f186367d593a7e305d35f15289cc2c3e067
F test/corruptN.test a034bb217bebd8d007625dfb078e76ec3d53515052dbceb68bd47b2c27674d5c
-F test/cost.test cc434a026b1e9d0d98137a147e24e5daf1b1ad09e9ff7da63b34c83ddd136d92
+F test/cost.test 8babd06a35d68f67032b44603c55e95271dd58511d6f50f167c9a8012fba8f80
F test/count.test cd4bd531066e8d77ef8fe1e3fc8253d042072e117ccab214b290cf83f1602249
F test/countofview.test 4088e461a10ee33e69803c177a69aa1d7bba81a9ffc2df66d76465a22ca7fdfc
F test/coveridxscan.test f35c7208dedc4f98e471c569df64c0f95a49f6e072d8dc7c8f99bdee2697de1b
F test/lemon-test01.y 70110eff607ab137ccc851edb2bc7e14a6d4f246b5d2d25f82a60b69d87a9ff2
F test/like.test 0036f8fe548fceabd1496361bfa262f35cf5ed17c794bd15e22e9f3de12e0eb0
F test/like2.test d3be15fefee3e02fc88942a9b98f26c5339bbdef7783c90023c092c4955fe3d3
-F test/like3.test 3c9be7a0122908d8ead6aa25e47c2b9787eea88e8062926078ea7b3e95c71d99
+F test/like3.test fa69e88f4a66aefa005fcc6c8b3b7e5531e12cad9b24bebb6241d6e5e5e54117
F test/limit.test 350f5d03c29e7dff9a2cde016f84f8d368d40bcd02fa2b2a52fa10c4bf3cbfaf
F test/limit2.test 621188fc3e5c3b8d2ef9827e05fa8313792ae563579073136efd25cb65325f1b
F test/literal.test a65dca9fef86e51b8e45544268e37abbd4bb94ba35fd65f6fdcab2f288cd8f79
F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
F test/tkt4018.test 18dbc6617f7a4b90e938d1bd6d26ad18daafaf08
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
-F test/tpch01.test 4479008f85f6f8f25f7ab2cb305d665752b4727fa28a8df3d8e0ad46520c62ff
+F test/tpch01.test 35b799a0c75693eb581ed0f58ce9d4ebe6e397f8b90945b2307a973c5fe5f880
F test/trace.test a659a9862957f4789e37a92b3bf6d2caf5c86b02cdeefc41e850ae53acf6992a
F test/trace2.test f5cb67ad3bc09e0c58e8cca78dfd0b5639259983
F test/trace3.test 2deeac66359c9f007f0fc9fb6336994a5d68fc1a65129f322a9e9546fd537d0a
F test/whereK.test 0270ab7f04ba5436fb9156d31d642a1c82727f4c4bfe5ba90d435c78cf44684a
F test/whereL.test cb115604cc9bd61acbc99a1f1df0eb1ea7a7875a77fef25ba9282f01d10283e1
F test/whereM.test 0dbc9998783458ddcf3cc078ca7c2951d8b2677d472ecf0028f449ed327c0250
-F test/whereN.test 63a3584b71acfb6963416de82f26c6b1644abc5ca6080c76546b9246734c8803
+F test/whereN.test 025327fc8d756a881dbd7ff20b3180adff8fb1576d0b60ee0b3d764519af78c2
F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb0e837a7
F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3
F test/wherelimit.test afb46397c6d7e964e6e294ba3569864a0c570fe3807afc634236c2b752372f31
F test/wherelimit2.test b9e4bfe7b4d7c2f85f99cf2bd2c51369378d04b1f3d1b60557423752003bfd90
-F test/wherelimit3.test 22d73e046870cf8bbe15573eda6b432b07ebe64a88711f9f849c6b3667c1fae6
+F test/wherelimit3.test b856e699769cb904af7a3e7b2bd32e28f828902acb13517956fcfc81377f0826
F test/widetab1.test c296a98e123762de79917350e45fa33fdf88577a2571eb3a64c8bf7e44ef74d1
F test/win32heap.test 1ec2ce646aee491ec23bfcdfd005b33c79f13bf91467966f374a76ffe7c7e85f
F test/win32lock.test e56d7a9b6cf9d5f3867c2dd19ff36c5326881e4038c6867610ecb3a9868ea4eb
F test/windowpushd.test c420e2265f0e09a0e798d0513a660d71b51602088d81b3dbd038918ee1339dcc
F test/with1.test 1ee171d7c306ab8b0771f3511d870f56c735607729836585bbceb1fc2f47e0b1
F test/with2.test 181674a6cc86a601ca2ac052741cdfad5b529e07e870435d2f6cdb92d589ff17
-F test/with3.test e30369ea27aa27eb1bda4c5e510c8a9f782c8afd2ab99d1a02b8a7f25a5d3e65
+F test/with3.test a39c0003d6e6d8bfff3461f66a1d53edab04715e309a303e17b2065837ef9f25
F test/with4.test 257be66c0c67fee1defbbac0f685c3465e2cad037f21ce65f23f86084f198205
F test/with5.test 6248213c41fab36290b5b73aa3f937309dfba337004d9d8434c3fabc8c7d4be8
F test/with6.test 281e4861b5e517f6c3c2f08517a520c1e2ee7c11966545d3901f258a4fe8ef76
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P e93048425bb7183efc047d0f6b39f214491fee869b8ed8006c6ec6eb0e3ec417 a95d126e1330e1b83f42b51f97c4c216622cf38062f3b5d72ccb76313187e850
-R 8746ac21dac213bf45ceade3f4ad3e82
+P 51c89c886f1846e297d249c85d18b047c76ba352ed998e48220e96a6a567b4a8
+R 5d5f07366627e69538d51ee50b1e88c9
U drh
-Z be1dd962742be330d7e4cccb4f2618fb
+Z 57fa0baa0107ffc7b174660d67d1252c
# Remove this line to create a well-formed Fossil manifest.
-51c89c886f1846e297d249c85d18b047c76ba352ed998e48220e96a6a567b4a8
+521948c64fc7a043e891e4dc3255bd59a76332c58b34d81057eecdf2fef31a63
break;
}
+/* Opcode: IfUseIndex P1 P2 P3 P4 *
+**
+** This opcode decides whether it will be faster to use the index
+** in cursor P1 or to do a full table scan on the original table.
+** If the index on cursor P1 should be used, a jump is made to P2.
+** (That is the usual case). If it seems like it might be faster to
+** do a full table scan, then fall through.
+**
+** The P3 and P4 arguments define a key in the same format as OP_SeekGT
+** and similar. That key is the last key in the range of index entries
+** that match the join condition. This opcode works by estimating the
+** number of rows in the index P1 between the current row and the last
+** row that matches P3,P4. If the number of rows that match is a significant
+** fraction of the total number of rows in the index, then it might be
+** faster to do a scan of the original table, and so this opcode falls.
+** If the estimated number of matching rows is small compared to the
+** total number of rows in the index, then the jump to P2 is taken
+** and cursor P1 is unchanged.
+*/
+case OP_IfUseIndex: { /* jump */
+ /**** Temporary Hack:
+ ***** Take the jump if Tuning(0) is 0. Fall through if non-zero.
+ ****/
+ if( Tuning(0) ) goto jump_to_p2;
+ break;
+}
+
+
/* Opcode: Savepoint P1 * * P4 *
**
** Open, release or rollback the savepoint named by parameter P4, depending
** with the same key.
*/
if( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ) ){
- eqOnly = 1;
+#ifdef SQLITE_DEBUG
+ VdbeOp *pNext = &pOp[1];
+ if( pNext->opcode==OP_IfUseIndex ) pNext = &p->aOp[pNext->p2];
assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
- assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
- assert( pOp->opcode==OP_SeekGE || pOp[1].opcode==OP_IdxLT );
- assert( pOp->opcode==OP_SeekLE || pOp[1].opcode==OP_IdxGT );
- assert( pOp[1].p1==pOp[0].p1 );
- assert( pOp[1].p2==pOp[0].p2 );
- assert( pOp[1].p3==pOp[0].p3 );
- assert( pOp[1].p4.i==pOp[0].p4.i );
+ assert( pNext->opcode==OP_IdxLT || pNext->opcode==OP_IdxGT );
+ assert( pOp->opcode==OP_SeekGE || pNext->opcode==OP_IdxLT );
+ assert( pOp->opcode==OP_SeekLE || pNext->opcode==OP_IdxGT );
+ assert( pNext->p1==pOp[0].p1 );
+ assert( pNext->p2==pOp[0].p2 );
+ assert( pNext->p3==pOp[0].p3 );
+ assert( pNext->p4.i==pOp[0].p4.i );
+#endif /* SQLITE_DEBUG */
+ eqOnly = 1;
}
nField = pOp->p4.i;
VdbeBranchTaken(res!=0,2);
if( res ){
goto jump_to_p2;
- }else if( eqOnly ){
+ }else if( eqOnly && pOp[1].opcode!=OP_IfUseIndex ){
assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
pOp++; /* Skip the OP_IdxLt or OP_IdxGT that follows */
}
wherePartIdxExpr(
pParse, pIx, pIx->pPartIdxWhere, 0, iIndexCur, pTabItem
);
- }else if( pIx->aiRowLogEst[pLoop->u.btree.nEq]>65 ){
+ }else if( pIx->aiRowLogEst[pLoop->u.btree.nEq]>65
+ && 0==(pLoop->wsFlags & (WHERE_AUTO_INDEX
+ |WHERE_IDX_ONLY
+ |WHERE_EXPRIDX))
+ && 0!=(pLoop->wsFlags & (WHERE_BOTH_LIMIT|WHERE_CONSTRAINT))
+ ){
pLoop->wsFlags |= WHERE_FLEX_SEARCH;
}
}
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
str.printfFlags = SQLITE_PRINTF_INTERNAL;
-#if 0
+#if 1
if( (flags & WHERE_FLEX_SEARCH)!=0 && isSearch ){
sqlite3_str_appendf(&str, "FLEX-SEARCH %S", pItem);
}else
if( zStartAff ) sqlite3DbNNFreeNN(db, zStartAff);
if( zEndAff ) sqlite3DbNNFreeNN(db, zEndAff);
+ if( pLoop->wsFlags & WHERE_FLEX_SEARCH ){
+ int jIfIdx;
+ /*** First flex-search block ***/
+ jIfIdx = sqlite3VdbeAddOp4Int(v, OP_IfUseIndex, iIdxCur, 0,
+ regBase, nConstraint);
+ /*** Other stuff here ***/
+ sqlite3VdbeJumpHere(v, jIfIdx);
+ }
+
/* Top of the loop body */
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
assert( pLevel->p5==0 );
}
if( omitTable ) pIdx = 0;
+
+ /*** Insert flex-scan block 2 here ****/
+ /*** Fix-up pLevel->op and similar ****/
+
}else
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
select count(*) from u, v where u.b = v.b and v.e > 34;
} {
QUERY PLAN
- |--SEARCH v USING INDEX ve (e>?)
+ |--FLEX-SEARCH v USING INDEX ve (e>?)
|--BLOOM FILTER ON u (b=?)
`--SEARCH u USING AUTOMATIC COVERING INDEX (b=?)
}
QUERY PLAN
|--CO-ROUTINE children
| |--SETUP
- | | `--SEARCH t2 USING INDEX x1 (pid=? AND rx=?)
+ | | `--FLEX-SEARCH t2 USING INDEX x1 (pid=? AND rx=?)
| `--RECURSIVE STEP
| |--SCAN children
- | `--SEARCH t2 USING INDEX x1 (pid=? AND rx=?)
+ | `--FLEX-SEARCH t2 USING INDEX x1 (pid=? AND rx=?)
`--SCAN children
}
SELECT * FROM t2 WHERE x BETWEEN ? AND ? ORDER BY rowid;
} {
QUERY PLAN
- |--SEARCH t2 USING INDEX t2i1 (x>? AND x<?)
+ |--FLEX-SEARCH t2 USING INDEX t2i1 (x>? AND x<?)
`--USE TEMP B-TREE FOR ORDER BY
}
SELECT * FROM t2 WHERE path LIKE 'a%';
} {
QUERY PLAN
- `--SEARCH t2 USING INDEX t2path (path>? AND path<?)
+ `--FLEX-SEARCH t2 USING INDEX t2path (path>? AND path<?)
}
do_eqp_test like3-6.220 {
SELECT * FROM t2 WHERE path LIKE 'a%' ESCAPE '\';
} {
QUERY PLAN
- `--SEARCH t2 USING INDEX t2path (path>? AND path<?)
+ `--FLEX-SEARCH t2 USING INDEX t2path (path>? AND path<?)
}
db eval {PRAGMA case_sensitive_like=ON}
do_eqp_test like3-6.230 {
SELECT * FROM t2 WHERE path LIKE 'a%';
} {
QUERY PLAN
- `--SEARCH t2 USING INDEX t2path2 (path>? AND path<?)
+ `--FLEX-SEARCH t2 USING INDEX t2path2 (path>? AND path<?)
}
do_eqp_test like3-6.240 {
SELECT * FROM t2 WHERE path LIKE 'a%' ESCAPE '\';
} {
QUERY PLAN
- `--SEARCH t2 USING INDEX t2path2 (path>? AND path<?)
+ `--FLEX-SEARCH t2 USING INDEX t2path2 (path>? AND path<?)
}
}
revenue desc;
} {
QUERY PLAN
- |--SEARCH orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE<?)
+ |--FLEX-SEARCH orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE<?)
|--SEARCH customer USING INDEX cpki (C_CUSTKEY=?)
|--SEARCH nation USING INDEX npki (N_NATIONKEY=?)
|--SEARCH lineitem USING INDEX lpki (L_ORDERKEY=?)
|--CO-ROUTINE (subquery-xxxxxx)
| |--SEARCH DS USING COVERING INDEX ds1 (name=?)
| |--SEARCH R USING COVERING INDEX rule2 (dsid=?)
- | |--SEARCH V USING INDEX v1 (rid=?)
+ | |--FLEX-SEARCH V USING INDEX v1 (rid=?)
| `--USE TEMP B-TREE FOR ORDER BY
`--SCAN (subquery-xxxxxx)
}
SELECT * FROM t1 WHERE a>=100 AND a<300 ORDER BY b LIMIT 5;
} {
QUERY PLAN
- |--SEARCH t1 USING INDEX t1a (a>? AND a<?)
+ |--FLEX-SEARCH t1 USING INDEX t1a (a>? AND a<?)
`--USE TEMP B-TREE FOR ORDER BY
}
ifcapable stat4 {
SELECT * FROM t1 WHERE a>=100 AND a<300 ORDER BY b LIMIT $::N;
} {
QUERY PLAN
- |--SEARCH t1 USING INDEX t1a (a>? AND a<?)
+ |--FLEX-SEARCH t1 USING INDEX t1a (a>? AND a<?)
`--USE TEMP B-TREE FOR ORDER BY
}
| `--RECURSIVE STEP
| `--SCAN cnt
|--SCAN cnt
- `--SEARCH y1 USING INDEX y1a (a=?)
+ `--FLEX-SEARCH y1 USING INDEX y1a (a=?)
}]
do_eqp_test 3.1.3 {