aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2022-10-13 12:47:33 +0000
committerdrh <>2022-10-13 12:47:33 +0000
commite995d2c226e2b65c5e40cd238415bdfeb0936e8c (patch)
tree9b2219f327bd1fb7af389ed14bdcd52f32e2e45d /src
parent1ffb6be1195c592e6c85d57603984b1f36bfde62 (diff)
downloadsqlite-e995d2c226e2b65c5e40cd238415bdfeb0936e8c.tar.gz
sqlite-e995d2c226e2b65c5e40cd238415bdfeb0936e8c.zip
Proposed optimization to the IS NULL and NOT NULL operators that avoids
loading the entire content of larges strings and BLOBs. Response to [forum:/info/3c08d4715dc05b00|forum post 3c08d4715dc05b00]. FossilOrigin-Name: 45f171565442f9fd6574fb93ae7abe83c168b20be68af42531bc55571450d3ab
Diffstat (limited to 'src')
-rw-r--r--src/expr.c2
-rw-r--r--src/pragma.c4
-rw-r--r--src/vdbe.h1
-rw-r--r--src/vdbeaux.c16
4 files changed, 20 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c
index baa0fe647..bceb5efb0 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -5241,6 +5241,7 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
+ sqlite3VdbeTypeofColumn(v, r1);
sqlite3VdbeAddOp2(v, op, r1, dest);
VdbeCoverageIf(v, op==TK_ISNULL);
VdbeCoverageIf(v, op==TK_NOTNULL);
@@ -5415,6 +5416,7 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
case TK_ISNULL:
case TK_NOTNULL: {
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
+ sqlite3VdbeTypeofColumn(v, r1);
sqlite3VdbeAddOp2(v, op, r1, dest);
testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
diff --git a/src/pragma.c b/src/pragma.c
index 7976f83c6..7aea3dd2c 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -1791,9 +1791,7 @@ void sqlite3Pragma(
|| pTab->iPKey==mxCol) ) mxCol--;
if( mxCol>=0 ){
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3);
- if( sqlite3VdbeGetLastOp(v)->opcode==OP_Column ){
- sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
- }
+ sqlite3VdbeTypeofColumn(v, 3);
}
if( !isQuick ){
diff --git a/src/vdbe.h b/src/vdbe.h
index eb1445f1d..a244468b5 100644
--- a/src/vdbe.h
+++ b/src/vdbe.h
@@ -228,6 +228,7 @@ void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
+void sqlite3VdbeTypeofColumn(Vdbe*, int);
void sqlite3VdbeJumpHere(Vdbe*, int addr);
void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr);
int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 8785e3b56..275ba6f77 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -1156,6 +1156,22 @@ void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
}
/*
+** If the previous opcode is an OP_Column that delivers results
+** into register iDest, then add the OPFLAG_TYPEOF flag to that
+** opcode.
+*/
+void sqlite3VdbeTypeofColumn(Vdbe *p, int iDest){
+ if( p->nOp>0 ){
+ VdbeOp *pOp = &p->aOp[p->nOp-1];
+ if( pOp->opcode==OP_Column && pOp->p3==iDest ){
+ pOp->p5 |= OPFLAG_TYPEOFARG;
+ }
+ }else{
+ assert( p->db->mallocFailed );
+ }
+}
+
+/*
** Change the P2 operand of instruction addr so that it points to
** the address of the next instruction to be coded.
*/