1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Eliminate the OP_SortMakeRec and OP_SortCallback opcodes. Sort using the

standard record format. (CVS 1426)

FossilOrigin-Name: 25643a0137d395572f16cfec3ab3327d913138ba
This commit is contained in:
drh
2004-05-21 03:01:58 +00:00
parent 736c22b803
commit ce665cf60e
5 changed files with 20 additions and 83 deletions

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.173 2004/05/21 02:14:25 drh Exp $
** $Id: select.c,v 1.174 2004/05/21 03:01:59 drh Exp $
*/
#include "sqliteInt.h"
@@ -486,7 +486,7 @@ static int selectInnerLoop(
case SRT_Callback:
case SRT_Sorter: {
if( pOrderBy ){
sqlite3VdbeAddOp(v, OP_SortMakeRec, nColumn, 0);
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
pushOntoSorter(pParse, v, pOrderBy);
}else{
assert( eDest==SRT_Callback );
@@ -566,10 +566,6 @@ static void generateSortTail(
sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, end2);
}
switch( eDest ){
case SRT_Callback: {
sqlite3VdbeAddOp(v, OP_SortCallback, nColumn, 0);
break;
}
case SRT_Table:
case SRT_TempTable: {
sqlite3VdbeAddOp(v, OP_NewRecno, iParm, 0);
@@ -593,6 +589,7 @@ static void generateSortTail(
sqlite3VdbeAddOp(v, OP_Goto, 0, end1);
break;
}
case SRT_Callback:
case SRT_Subroutine: {
int i;
sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0);
@@ -600,7 +597,11 @@ static void generateSortTail(
for(i=0; i<nColumn; i++){
sqlite3VdbeAddOp(v, OP_Column, -1-i, i);
}
sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
if( eDest==SRT_Callback ){
sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0);
}else{
sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
}
sqlite3VdbeAddOp(v, OP_Pop, 2, 0);
break;
}

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.311 2004/05/21 02:14:25 drh Exp $
** $Id: vdbe.c,v 1.312 2004/05/21 03:01:59 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -4192,51 +4192,6 @@ case OP_SortPut: {
break;
}
/* Opcode: SortMakeRec P1 * *
**
** The top P1 elements are the arguments to a callback. Form these
** elements into a single data entry that can be stored on a sorter
** using SortPut and later fed to a callback using SortCallback.
*/
case OP_SortMakeRec: {
char *z;
char **azArg;
int nByte;
int nField;
int i;
Mem *pRec;
nField = pOp->p1;
pRec = &pTos[1-nField];
assert( pRec>=p->aStack );
nByte = 0;
for(i=0; i<nField; i++, pRec++){
if( (pRec->flags & MEM_Null)==0 ){
Stringify(pRec);
nByte += pRec->n;
}
}
nByte += sizeof(char*)*(nField+1);
azArg = sqliteMallocRaw( nByte );
if( azArg==0 ) goto no_mem;
z = (char*)&azArg[nField+1];
for(pRec=&pTos[1-nField], i=0; i<nField; i++, pRec++){
if( pRec->flags & MEM_Null ){
azArg[i] = 0;
}else{
azArg[i] = z;
memcpy(z, pRec->z, pRec->n);
z += pRec->n;
}
}
popStack(&pTos, nField);
pTos++;
pTos->n = nByte;
pTos->z = (char*)azArg;
pTos->flags = MEM_Str | MEM_Dyn;
break;
}
/* Opcode: Sort * * P3
**
** Sort all elements on the sorter. The algorithm is a
@@ -4300,25 +4255,6 @@ case OP_SortNext: {
break;
}
/* Opcode: SortCallback P1 * *
**
** The top of the stack contains a callback record built using
** the SortMakeRec operation with the same P1 value as this
** instruction. Pop this record from the stack and invoke the
** callback on it.
*/
case OP_SortCallback: {
assert( pTos>=p->aStack );
assert( pTos->flags & MEM_Str );
p->nCallback++;
p->pc = pc+1;
p->azResColumn = (char**)pTos->z;
assert( p->nResColumn==pOp->p1 );
p->popStack = 1;
p->pTos = pTos;
return SQLITE_ROW;
}
/* Opcode: SortReset * * *
**
** Remove any elements that remain on the sorter.