Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Eliminate the OP_SortMakeRec and OP_SortCallback opcodes. Sort using the standard record format. (CVS 1426) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
25643a0137d395572f16cfec3ab3327d |
User & Date: | drh 2004-05-21 03:01:59 |
Context
2004-05-21
| ||
10:08 | Further work on the new API. All the functions to execute queries are there now. (CVS 1427) check-in: fc94575d user: danielk1977 tags: trunk | |
03:01 | Eliminate the OP_SortMakeRec and OP_SortCallback opcodes. Sort using the standard record format. (CVS 1426) check-in: 25643a01 user: drh tags: trunk | |
02:14 | Most sorting problems are fixed. Dead code has been removed. 3 test failures remain but will be fixed by the new function API once it gets implemented. (CVS 1425) check-in: 3b55095e user: drh tags: trunk | |
Changes
Changes to src/select.c.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 ... 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 ... 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** 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 $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. ................................................................................ } /* Send the data to the callback function. */ case SRT_Callback: case SRT_Sorter: { if( pOrderBy ){ sqlite3VdbeAddOp(v, OP_SortMakeRec, nColumn, 0); pushOntoSorter(pParse, v, pOrderBy); }else{ assert( eDest==SRT_Callback ); sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); } break; } ................................................................................ sqlite3VdbeAddOp(v, OP_Pop, 1, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, addr); } if( p->iLimit>=0 ){ 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); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, iParm, 0); break; } ................................................................................ } case SRT_Mem: { assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); sqlite3VdbeAddOp(v, OP_Goto, 0, end1); break; } case SRT_Subroutine: { int i; sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); for(i=0; i<nColumn; i++){ sqlite3VdbeAddOp(v, OP_Column, -1-i, i); } sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); sqlite3VdbeAddOp(v, OP_Pop, 2, 0); break; } default: { /* Do nothing */ break; } |
| | < < < < > > > > | > |
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 ... 562 563 564 565 566 567 568 569 570 571 572 573 574 575 ... 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** ** $Id: select.c,v 1.174 2004/05/21 03:01:59 drh Exp $ */ #include "sqliteInt.h" /* ** Allocate a new Select structure and return a pointer to that ** structure. ................................................................................ } /* Send the data to the callback function. */ case SRT_Callback: case SRT_Sorter: { if( pOrderBy ){ sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); pushOntoSorter(pParse, v, pOrderBy); }else{ assert( eDest==SRT_Callback ); sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); } break; } ................................................................................ sqlite3VdbeAddOp(v, OP_Pop, 1, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, addr); } if( p->iLimit>=0 ){ sqlite3VdbeAddOp(v, OP_MemIncr, p->iLimit, end2); } switch( eDest ){ case SRT_Table: case SRT_TempTable: { sqlite3VdbeAddOp(v, OP_NewRecno, iParm, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); sqlite3VdbeAddOp(v, OP_PutIntKey, iParm, 0); break; } ................................................................................ } case SRT_Mem: { assert( nColumn==1 ); sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1); sqlite3VdbeAddOp(v, OP_Goto, 0, end1); break; } case SRT_Callback: case SRT_Subroutine: { int i; sqlite3VdbeAddOp(v, OP_Integer, p->pEList->nExpr, 0); sqlite3VdbeAddOp(v, OP_Pull, 1, 0); for(i=0; i<nColumn; i++){ sqlite3VdbeAddOp(v, OP_Column, -1-i, i); } if( eDest==SRT_Callback ){ sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0); }else{ sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm); } sqlite3VdbeAddOp(v, OP_Pop, 2, 0); break; } default: { /* Do nothing */ break; } |
Changes to src/vdbe.c.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 .... 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 .... 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 |
** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** 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 $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* ................................................................................ assert( pNos->flags & MEM_Dyn ); pSorter->nData = pNos->n; pSorter->pData = pNos->z; pTos -= 2; 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 ** mergesort. The P3 argument is a pointer to a KeyInfo structure ** that describes the keys to be sorted. */ case OP_Sort: { ................................................................................ sqliteFree(pSorter); }else{ pc = pOp->p2 - 1; } 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. */ case OP_SortReset: { sqlite3VdbeSorterReset(p); break; |
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 .... 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 .... 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 |
** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** 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.312 2004/05/21 03:01:59 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* ................................................................................ assert( pNos->flags & MEM_Dyn ); pSorter->nData = pNos->n; pSorter->pData = pNos->z; pTos -= 2; break; } /* Opcode: Sort * * P3 ** ** Sort all elements on the sorter. The algorithm is a ** mergesort. The P3 argument is a pointer to a KeyInfo structure ** that describes the keys to be sorted. */ case OP_Sort: { ................................................................................ sqliteFree(pSorter); }else{ pc = pOp->p2 - 1; } break; } /* Opcode: SortReset * * * ** ** Remove any elements that remain on the sorter. */ case OP_SortReset: { sqlite3VdbeSorterReset(p); break; |
Changes to test/where.test.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the use of indices in WHERE clases. # # $Id: where.test,v 1.20 2004/05/21 02:14:25 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data # do_test where-1.0 { ................................................................................ # for the SQL and appends a "nosort" to the result if the program contains the # SortCallback opcode. If the program does not contain the SortCallback # opcode it appends "sort" # proc cksort {sql} { set data [execsql $sql] set prog [execsql "EXPLAIN $sql"] if {[regexp SortCallback $prog]} {set x sort} {set x nosort} lappend data $x return $data } # Check out the logic that attempts to implement the ORDER BY clause # using an index rather than by sorting. # do_test where-6.1 { |
|
|
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the use of indices in WHERE clases. # # $Id: where.test,v 1.21 2004/05/21 03:01:59 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data # do_test where-1.0 { ................................................................................ # for the SQL and appends a "nosort" to the result if the program contains the # SortCallback opcode. If the program does not contain the SortCallback # opcode it appends "sort" # proc cksort {sql} { set data [execsql $sql] set prog [execsql "EXPLAIN $sql"] if {[regexp Sort $prog]} {set x sort} {set x nosort} lappend data $x return $data } # Check out the logic that attempts to implement the ORDER BY clause # using an index rather than by sorting. # do_test where-6.1 { |