From: drh <> Date: Sat, 16 May 2026 16:02:08 +0000 (+0000) Subject: Improved comment on sqlite3ExprCanReturnSubtype() as well as one very X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=d3265d1473e871c4bffad5a90d535ed59d90a426;p=thirdparty%2Fsqlite.git Improved comment on sqlite3ExprCanReturnSubtype() as well as one very minor efficiency improvement. FossilOrigin-Name: b57d6b76b0f9f4f154997af83f14d545bf2b6b8f7194746835e4c34885db227a --- diff --git a/manifest b/manifest index 90b3bb748f..8aa8093793 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\susing\san\sindex\son\sa\sCASE\sexpression\sthat\smay\sreturn\sa\svalue\swith\sa\ssubtype,\savoid\sdiscarding\sany\ssubtype. -D 2026-05-15T19:44:24.882 +C Improved\scomment\son\ssqlite3ExprCanReturnSubtype()\sas\swell\sas\sone\svery\nminor\sefficiency\simprovement. +D 2026-05-16T16:02:08.141 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -687,7 +687,7 @@ F src/date.c 61e92f1f7e2e88e1cd91e91dc69eb2b2854e7877254470f9fabd776bfac922b8 F src/dbpage.c 98c716bc5c0c70af4e7934bfcddd707f14e78b5d4cf1e0602a07b485e1af2e74 F src/dbstat.c 73362c0df0f40ad5523a6f5501224959d0976757b511299bf892313e79d14f5c F src/delete.c 59eeca3fb88c29329afc41bb803ee568b120d9dd7470b5f38ab55cc38390b451 -F src/expr.c bacfbcd6b349bb836be3e09651923138614fe341b16cddc5b4dcce569cc11657 +F src/expr.c c7af3a4d0836d31ea5ce3afa769c371d04a5e6a31b5b28d08cc712acbe8c891e F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 931f74cec1dc8038a0217ef340c91ce147dd1bbed08dc40c47ee0ec6edfffb08 F src/func.c e8525e6c5493149680b0ebd3352e7f004ee7283181f24809b603329afe911443 @@ -2205,11 +2205,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 614f8cbc374c7a2d39826706f16ab1c17e75abb420a70be356c7eefa95b271a5 -R 7f712de5bacc1146fd2700d6cc08652f -T *branch * index-on-case-expr-subtype -T *sym-index-on-case-expr-subtype * -T -sym-trunk * -U dan -Z 8202b1d00ea8af94563d96cd91a8fa5d +P 69c9a82cbaea7b6faa6a357dd884b1e0d2bc684d847efb31a2d64c75fabf5428 +R 2a2f348cdea2758e17a1878550fc52a0 +U drh +Z e0cf26d7b2dbc3e008636c0b83266f18 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index aa8d3b6cab..3de14ecf50 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -69c9a82cbaea7b6faa6a357dd884b1e0d2bc684d847efb31a2d64c75fabf5428 +b57d6b76b0f9f4f154997af83f14d545bf2b6b8f7194746835e4c34885db227a diff --git a/src/expr.c b/src/expr.c index 2e52638f8b..ff8295beaa 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4685,21 +4685,27 @@ static int exprCodeInlineFunction( } /* -** Expression Node callback for sqlite3ExprCanReturnSubtype(). +** Expression Node callback for sqlite3ExprCanReturnSubtype(). If +** pExpr is able to return a subtype, set pWalker->eCode and abort +** the search. If pExpr can never return a subtype, prune search. ** -** Only a function call is able to return a subtype. So if the node -** is not a function call, return WRC_Prune immediately. +** The only expressions that can return a subtype are: ** -** A function call is able to return a subtype if it has the -** SQLITE_RESULT_SUBTYPE property. +** 1. A function +** 2. The no-op "+" operator +** 3. A CASE...END expression +** 4. A CAST() expression +** 5. A "expr COLLATE colseq" expression. ** -** Assume that every function is able to pass-through a subtype from -** one of its argument (using sqlite3_result_value()). Most functions -** are not this way, but we don't have a mechanism to distinguish those -** that are from those that are not, so assume they all work this way. -** That means that if one of its arguments is another function and that -** other function is able to return a subtype, then this function is -** able to return a subtype. +** For any other kind of expression, prune the search. +** +** For case 1, the expression can yield a subtype if the function has +** the SQLITE_RESULT_SUBTYPE property. Functions can also return +** a subtype (via sqlite3_result_value()) if any of the arguments can +** return a subtype. +** +** In all cases 1 through 5, the expression might also return a subtype +** if any operand can return a subtype. */ static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ int n; @@ -4719,7 +4725,7 @@ static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ pWalker->eCode = 1; - return WRC_Prune; + return WRC_Abort; } return WRC_Continue; }