aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2022-12-21 14:13:49 +0000
committerdrh <>2022-12-21 14:13:49 +0000
commitfe83892bc12376c587b752e20de62d45ef1e7f82 (patch)
tree4f110ca2e4639c6f5b765b8e8b5078e8dd325e25 /src
parent4f0c36b327cfd244adb8d126008ebc6ac32dff1f (diff)
downloadsqlite-fe83892bc12376c587b752e20de62d45ef1e7f82.tar.gz
sqlite-fe83892bc12376c587b752e20de62d45ef1e7f82.zip
Ensure that the expression of a virtual column really is an expression and
not just a reference to another column, as a real expression is necessary for the indexed expression coverage optimization to work properly. [forum:/forumpost/07b36e3899a9ae21|Forum thread 07b36e3899a9ae21]. FossilOrigin-Name: 40549bacb3923e439627b0103bedd7da30258b69a46960040f7176e060f51f2f
Diffstat (limited to 'src')
-rw-r--r--src/build.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/build.c b/src/build.c
index 29a798e6c..415eeae70 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2004,6 +2004,13 @@ void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){
if( pCol->colFlags & COLFLAG_PRIMKEY ){
makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
}
+ if( ALWAYS(pExpr) && pExpr->op==TK_ID ){
+ /* The value of a generated column needs to be a real expression, not
+ ** just a reference to another column, in order for covering index
+ ** optimizations to work correctly. So if the value is not an expression,
+ ** turn it into one by adding a unary "+" operator. */
+ pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
+ }
sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
pExpr = 0;
goto generated_done;