aboutsummaryrefslogtreecommitdiff
path: root/src/wherecode.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2019-08-02 19:40:01 +0000
committerdan <dan@noemail.net>2019-08-02 19:40:01 +0000
commit0bf6549cd184c58dc4b8867405c40bfda5ba75b1 (patch)
tree24ffbe3367ab8bcf0c19007a792a3639ea19897f /src/wherecode.c
parentd744ee0b50e64348a0ba605eb8270cd2363e8dd3 (diff)
parentddd7421c9170317294e69a4287deda996a3cd3dc (diff)
downloadsqlite-0bf6549cd184c58dc4b8867405c40bfda5ba75b1.tar.gz
sqlite-0bf6549cd184c58dc4b8867405c40bfda5ba75b1.zip
If a query like "SELECT min(a), b FROM t1" visits no rows where "a" is not null, extract a value for "b" from one of the rows where "a" is null. Fix for ticket [41866dc37].
FossilOrigin-Name: faaaae4940b5f4f70e4988ad5b45582410b381ace0031e6abcde0b9217c06796
Diffstat (limited to 'src/wherecode.c')
-rw-r--r--src/wherecode.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index a62544845..6152f7c35 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -1694,6 +1694,25 @@ Bitmask sqlite3WhereCodeOneLoopStart(
VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
+
+ if( bSeekPastNull && (pLoop->wsFlags & WHERE_TOP_LIMIT)==0 ){
+ /* If bSeekPastNull is set only to skip past the NULL values for
+ ** a query like "SELECT min(a), b FROM t1", then add code so that
+ ** if there are no rows with (a IS NOT NULL), then do the seek
+ ** without jumping past NULLs instead. This allows the code in
+ ** select.c to pick a value for "b" in the above query. */
+ assert( startEq==0 && (op==OP_SeekGT || op==OP_SeekLT) );
+ assert( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 && pWInfo->nOBSat>0 );
+ sqlite3VdbeChangeP2(v, -1, sqlite3VdbeCurrentAddr(v)+1);
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+2);
+
+ op = aStartOp[(start_constraints<<2) + (1<<1) + bRev];
+ assert( op!=0 );
+ sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
+ VdbeCoverage(v);
+ VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
+ VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
+ }
}
/* Load the value for the inequality constraint at the end of the