Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -1689,10 +1689,11 @@ FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), FUNCTION(hex, 1, 0, 0, hexFunc ), FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), + FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), VFUNCTION(random, 0, 0, 0, randomFunc ), VFUNCTION(randomblob, 1, 0, 0, randomBlob ), FUNCTION(nullif, 2, 0, 1, nullifFunc ), FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), Index: src/resolve.c ================================================================== --- src/resolve.c +++ src/resolve.c @@ -709,11 +709,12 @@ }else{ /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to ** likelihood(X, 0.0625). ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for ** likelihood(X,0.0625). */ - pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */ + /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */ + pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938; } } } #ifndef SQLITE_OMIT_AUTHORIZATION if( pDef ){ Index: test/func3.test ================================================================== --- test/func3.test +++ test/func3.test @@ -147,10 +147,34 @@ # EVIDENCE-OF: R-22887-63324 The unlikely(X) function is a no-op that # the code generator optimizes away so that it consumes no CPU cycles at # run-time (that is, during calls to sqlite3_step()). # -do_test func3-5.40 { +do_test func3-5.39 { db eval {EXPLAIN SELECT unlikely(min(1.0+'2.0',4*11))} } [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] + +do_execsql_test func3-5.40 { + SELECT likely(9223372036854775807); +} {9223372036854775807} +do_execsql_test func3-5.41 { + SELECT likely(-9223372036854775808); +} {-9223372036854775808} +do_execsql_test func3-5.42 { + SELECT likely(14.125); +} {14.125} +do_execsql_test func3-5.43 { + SELECT likely(NULL); +} {{}} +do_execsql_test func3-5.44 { + SELECT likely('test-string'); +} {test-string} +do_execsql_test func3-5.45 { + SELECT quote(likely(x'010203000405')); +} {X'010203000405'} +do_test func3-5.49 { + db eval {EXPLAIN SELECT likely(min(1.0+'2.0',4*11))} +} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] + + finish_test Index: test/whereG.test ================================================================== --- test/whereG.test +++ test/whereG.test @@ -7,11 +7,11 @@ # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # -# Test cases for query planning decisions and the unlikely() and +# Test cases for query planning decisions and the likely(), unlikely(), and # likelihood() functions. set testdir [file dirname \$argv0] source \$testdir/tester.tcl set testprefix whereG @@ -197,10 +197,13 @@ SELECT * FROM t1 WHERE a>? } {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?)}} do_eqp_test 5.1.3 { SELECT * FROM t1 WHERE likelihood(a>?, 0.9) } {0 0 0 {SCAN TABLE t1}} +do_eqp_test 5.1.4 { + SELECT * FROM t1 WHERE likely(a>?) +} {0 0 0 {SCAN TABLE t1}} do_test 5.2 { for {set i 0} {\$i < 100} {incr i} { execsql { INSERT INTO t1 VALUES('abc', \$i, \$i); } } @@ -211,15 +214,20 @@ SELECT * FROM t1 WHERE likelihood(b>?, 0.01) } {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (ANY(a) AND b>?)}} do_eqp_test 5.2.3 { SELECT * FROM t1 WHERE likelihood(b>?, 0.9) } {0 0 0 {SCAN TABLE t1}} +do_eqp_test 5.2.4 { + SELECT * FROM t1 WHERE likely(b>?) +} {0 0 0 {SCAN TABLE t1}} do_eqp_test 5.3.1 { SELECT * FROM t1 WHERE a=? } {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}} do_eqp_test 5.3.2 { SELECT * FROM t1 WHERE likelihood(a=?, 0.9) } {0 0 0 {SCAN TABLE t1}} +do_eqp_test 5.3.3 { + SELECT * FROM t1 WHERE likely(a=?) +} {0 0 0 {SCAN TABLE t1}} finish_test -