1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

For queries of the form "SELECT p, max(q) FROM t1", the value of column p

returned is the one on the same row that holds the maximum value of q.

FossilOrigin-Name: adb29232b659c5332b6841776372407fcc350b08
This commit is contained in:
drh
2012-02-02 17:35:43 +00:00
parent a451017d62
commit 7a95789c0c
7 changed files with 50 additions and 14 deletions

View File

@@ -1331,19 +1331,26 @@ arithmetic_result_is_null:
break;
}
/* Opcode: CollSeq * * P4
/* Opcode: CollSeq P1 * * P4
**
** P4 is a pointer to a CollSeq struct. If the next call to a user function
** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
** be returned. This is used by the built-in min(), max() and nullif()
** functions.
**
** If P1 is not zero, then it is a register that a subsequent min() or
** max() aggregate will set to 1 if the current row is not the minimum or
** maximum. The P1 register is initialized to 0 by this instruction.
**
** The interface used by the implementation of the aforementioned functions
** to retrieve the collation sequence set by this opcode is not available
** publicly, only to user functions defined in func.c.
*/
case OP_CollSeq: {
assert( pOp->p4type==P4_COLLSEQ );
if( pOp->p1 ){
sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
}
break;
}
@@ -5356,6 +5363,7 @@ case OP_AggStep: {
ctx.s.db = db;
ctx.isError = 0;
ctx.pColl = 0;
ctx.skipFlag = 0;
if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
assert( pOp>p->aOp );
assert( pOp[-1].p4type==P4_COLLSEQ );
@@ -5367,6 +5375,11 @@ case OP_AggStep: {
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
rc = ctx.isError;
}
if( ctx.skipFlag ){
assert( pOp[-1].opcode==OP_CollSeq );
i = pOp[-1].p1;
if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
}
sqlite3VdbeMemRelease(&ctx.s);