/ Check-in [8b44d6fb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove the SQLITE_OMIT_MERGE_SORT compile-time option and its related code. The merge sorter is now a required component.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8b44d6fb159e85267095e846cded2764c3bcb895
User & Date: drh 2013-03-24 22:56:49
Context
2013-03-25
11:38
In fts3, when filtering lists for hits in a specific column, edit the list in place in the same way as it is for NEAR filtering. Fix for [38b1ae018f]. check-in: f85f9103 user: dan tags: trunk
2013-03-24
22:56
Remove the SQLITE_OMIT_MERGE_SORT compile-time option and its related code. The merge sorter is now a required component. check-in: 8b44d6fb user: drh tags: trunk
2013-03-21
21:20
Many spelling fixes in comments. No changes to code. check-in: 6f6e2d50 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  2388   2388     int iIdx = pParse->nTab++;     /* Btree cursor used for pIndex */
  2389   2389     int iSorter;                   /* Cursor opened by OpenSorter (if in use) */
  2390   2390     int addr1;                     /* Address of top of loop */
  2391   2391     int addr2;                     /* Address to jump to for next iteration */
  2392   2392     int tnum;                      /* Root page of index */
  2393   2393     Vdbe *v;                       /* Generate code into this virtual machine */
  2394   2394     KeyInfo *pKey;                 /* KeyInfo for index */
  2395         -#ifdef SQLITE_OMIT_MERGE_SORT
  2396         -  int regIdxKey;                 /* Registers containing the index key */
  2397         -#endif
  2398   2395     int regRecord;                 /* Register holding assemblied index record */
  2399   2396     sqlite3 *db = pParse->db;      /* The database connection */
  2400   2397     int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
  2401   2398   
  2402   2399   #ifndef SQLITE_OMIT_AUTHORIZATION
  2403   2400     if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
  2404   2401         db->aDb[iDb].zName ) ){
................................................................................
  2418   2415       sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
  2419   2416     }
  2420   2417     pKey = sqlite3IndexKeyinfo(pParse, pIndex);
  2421   2418     sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb, 
  2422   2419                       (char *)pKey, P4_KEYINFO_HANDOFF);
  2423   2420     sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
  2424   2421   
  2425         -#ifndef SQLITE_OMIT_MERGE_SORT
  2426   2422     /* Open the sorter cursor if we are to use one. */
  2427   2423     iSorter = pParse->nTab++;
  2428   2424     sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
  2429         -#else
  2430         -  iSorter = iTab;
  2431         -#endif
  2432   2425   
  2433   2426     /* Open the table. Loop through all rows of the table, inserting index
  2434   2427     ** records into the sorter. */
  2435   2428     sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  2436   2429     addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
  2437   2430     regRecord = sqlite3GetTempReg(pParse);
  2438   2431   
  2439         -#ifndef SQLITE_OMIT_MERGE_SORT
  2440   2432     sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
  2441   2433     sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
  2442   2434     sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
  2443   2435     sqlite3VdbeJumpHere(v, addr1);
  2444   2436     addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
  2445   2437     if( pIndex->onError!=OE_None ){
  2446   2438       int j2 = sqlite3VdbeCurrentAddr(v) + 3;
................................................................................
  2452   2444       );
  2453   2445     }else{
  2454   2446       addr2 = sqlite3VdbeCurrentAddr(v);
  2455   2447     }
  2456   2448     sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
  2457   2449     sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
  2458   2450     sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  2459         -#else
  2460         -  regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
  2461         -  addr2 = addr1 + 1;
  2462         -  if( pIndex->onError!=OE_None ){
  2463         -    const int regRowid = regIdxKey + pIndex->nColumn;
  2464         -    const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
  2465         -    void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
  2466         -
  2467         -    /* The registers accessed by the OP_IsUnique opcode were allocated
  2468         -    ** using sqlite3GetTempRange() inside of the sqlite3GenerateIndexKey()
  2469         -    ** call above. Just before that function was freed they were released
  2470         -    ** (made available to the compiler for reuse) using 
  2471         -    ** sqlite3ReleaseTempRange(). So in some ways having the OP_IsUnique
  2472         -    ** opcode use the values stored within seems dangerous. However, since
  2473         -    ** we can be sure that no other temp registers have been allocated
  2474         -    ** since sqlite3ReleaseTempRange() was called, it is safe to do so.
  2475         -    */
  2476         -    sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32);
  2477         -    sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
  2478         -        "indexed columns are not unique", P4_STATIC);
  2479         -  }
  2480         -  sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
  2481         -  sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  2482         -#endif
  2483   2451     sqlite3ReleaseTempReg(pParse, regRecord);
  2484   2452     sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
  2485   2453     sqlite3VdbeJumpHere(v, addr1);
  2486   2454   
  2487   2455     sqlite3VdbeAddOp1(v, OP_Close, iTab);
  2488   2456     sqlite3VdbeAddOp1(v, OP_Close, iIdx);
  2489   2457     sqlite3VdbeAddOp1(v, OP_Close, iSorter);

Changes to src/ctime.c.

   259    259   #endif
   260    260   #ifdef SQLITE_OMIT_LOOKASIDE
   261    261     "OMIT_LOOKASIDE",
   262    262   #endif
   263    263   #ifdef SQLITE_OMIT_MEMORYDB
   264    264     "OMIT_MEMORYDB",
   265    265   #endif
   266         -#ifdef SQLITE_OMIT_MERGE_SORT
   267         -  "OMIT_MERGE_SORT",
   268         -#endif
   269    266   #ifdef SQLITE_OMIT_OR_OPTIMIZATION
   270    267     "OMIT_OR_OPTIMIZATION",
   271    268   #endif
   272    269   #ifdef SQLITE_OMIT_PAGER_PRAGMAS
   273    270     "OMIT_PAGER_PRAGMAS",
   274    271   #endif
   275    272   #ifdef SQLITE_OMIT_PRAGMA

Changes to src/test_config.c.

   391    391   
   392    392   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   393    393     Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "1", TCL_GLOBAL_ONLY);
   394    394   #else
   395    395     Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "0", TCL_GLOBAL_ONLY);
   396    396   #endif
   397    397   
   398         -#ifdef SQLITE_OMIT_MERGE_SORT
   399         -  Tcl_SetVar2(interp, "sqlite_options", "mergesort", "0", TCL_GLOBAL_ONLY);
   400         -#else
   401         -  Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY);
   402         -#endif
          398  +Tcl_SetVar2(interp, "sqlite_options", "mergesort", "1", TCL_GLOBAL_ONLY);
   403    399   
   404    400   #ifdef SQLITE_OMIT_OR_OPTIMIZATION
   405    401     Tcl_SetVar2(interp, "sqlite_options", "or_opt", "0", TCL_GLOBAL_ONLY);
   406    402   #else
   407    403     Tcl_SetVar2(interp, "sqlite_options", "or_opt", "1", TCL_GLOBAL_ONLY);
   408    404   #endif
   409    405   

Changes to src/vdbe.c.

   148    148   ** converts an MEM_Ephem string into an MEM_Dyn string.
   149    149   */
   150    150   #define Deephemeralize(P) \
   151    151      if( ((P)->flags&MEM_Ephem)!=0 \
   152    152          && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
   153    153   
   154    154   /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
   155         -#ifdef SQLITE_OMIT_MERGE_SORT
   156         -# define isSorter(x) 0
   157         -#else
   158    155   # define isSorter(x) ((x)->pSorter!=0)
   159         -#endif
   160    156   
   161    157   /*
   162    158   ** Argument pMem points at a register that will be passed to a
   163    159   ** user-defined function or returned to the user as the result of a query.
   164    160   ** This routine sets the pMem->type variable used by the sqlite3_value_*() 
   165    161   ** routines.
   166    162   */
................................................................................
  3317   3313   ** This opcode works like OP_OpenEphemeral except that it opens
  3318   3314   ** a transient index that is specifically designed to sort large
  3319   3315   ** tables using an external merge-sort algorithm.
  3320   3316   */
  3321   3317   case OP_SorterOpen: {
  3322   3318     VdbeCursor *pCx;
  3323   3319   
  3324         -#ifndef SQLITE_OMIT_MERGE_SORT
  3325   3320     pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
  3326   3321     if( pCx==0 ) goto no_mem;
  3327   3322     pCx->pKeyInfo = pOp->p4.pKeyInfo;
  3328   3323     pCx->pKeyInfo->enc = ENC(p->db);
  3329   3324     pCx->isSorter = 1;
  3330   3325     rc = sqlite3VdbeSorterInit(db, pCx);
  3331         -#else
  3332         -  pOp->opcode = OP_OpenEphemeral;
  3333         -  pc--;
  3334         -#endif
  3335   3326     break;
  3336   3327   }
  3337   3328   
  3338   3329   /* Opcode: OpenPseudo P1 P2 P3 * P5
  3339   3330   **
  3340   3331   ** Open a new cursor that points to a fake table that contains a single
  3341   3332   ** row of data.  The content of that one row in the content of memory
................................................................................
  4210   4201   /* Opcode: SorterData P1 P2 * * *
  4211   4202   **
  4212   4203   ** Write into register P2 the current sorter data for sorter cursor P1.
  4213   4204   */
  4214   4205   case OP_SorterData: {
  4215   4206     VdbeCursor *pC;
  4216   4207   
  4217         -#ifndef SQLITE_OMIT_MERGE_SORT
  4218   4208     pOut = &aMem[pOp->p2];
  4219   4209     pC = p->apCsr[pOp->p1];
  4220   4210     assert( pC->isSorter );
  4221   4211     rc = sqlite3VdbeSorterRowkey(pC, pOut);
  4222         -#else
  4223         -  pOp->opcode = OP_RowKey;
  4224         -  pc--;
  4225         -#endif
  4226   4212     break;
  4227   4213   }
  4228   4214   
  4229   4215   /* Opcode: RowData P1 P2 * * *
  4230   4216   **
  4231   4217   ** Write into register P2 the complete row data for cursor P1.
  4232   4218   ** There is no interpretation of the data.  
................................................................................
  4417   4403   ** then rewinding that index and playing it back from beginning to
  4418   4404   ** end.  We use the OP_Sort opcode instead of OP_Rewind to do the
  4419   4405   ** rewinding so that the global variable will be incremented and
  4420   4406   ** regression tests can determine whether or not the optimizer is
  4421   4407   ** correctly optimizing out sorts.
  4422   4408   */
  4423   4409   case OP_SorterSort:    /* jump */
  4424         -#ifdef SQLITE_OMIT_MERGE_SORT
  4425         -  pOp->opcode = OP_Sort;
  4426         -#endif
  4427   4410   case OP_Sort: {        /* jump */
  4428   4411   #ifdef SQLITE_TEST
  4429   4412     sqlite3_sort_count++;
  4430   4413     sqlite3_search_count--;
  4431   4414   #endif
  4432   4415     p->aCounter[SQLITE_STMTSTATUS_SORT-1]++;
  4433   4416     /* Fall through into OP_Rewind */
................................................................................
  4498   4481   ** P4 is always of type P4_ADVANCE. The function pointer points to
  4499   4482   ** sqlite3BtreePrevious().
  4500   4483   **
  4501   4484   ** If P5 is positive and the jump is taken, then event counter
  4502   4485   ** number P5-1 in the prepared statement is incremented.
  4503   4486   */
  4504   4487   case OP_SorterNext:    /* jump */
  4505         -#ifdef SQLITE_OMIT_MERGE_SORT
  4506         -  pOp->opcode = OP_Next;
  4507         -#endif
  4508   4488   case OP_Prev:          /* jump */
  4509   4489   case OP_Next: {        /* jump */
  4510   4490     VdbeCursor *pC;
  4511   4491     int res;
  4512   4492   
  4513   4493     CHECK_FOR_INTERRUPT;
  4514   4494     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
................................................................................
  4551   4531   ** P3 is a flag that provides a hint to the b-tree layer that this
  4552   4532   ** insert is likely to be an append.
  4553   4533   **
  4554   4534   ** This instruction only works for indices.  The equivalent instruction
  4555   4535   ** for tables is OP_Insert.
  4556   4536   */
  4557   4537   case OP_SorterInsert:       /* in2 */
  4558         -#ifdef SQLITE_OMIT_MERGE_SORT
  4559         -  pOp->opcode = OP_IdxInsert;
  4560         -#endif
  4561   4538   case OP_IdxInsert: {        /* in2 */
  4562   4539     VdbeCursor *pC;
  4563   4540     BtCursor *pCrsr;
  4564   4541     int nKey;
  4565   4542     const char *zKey;
  4566   4543   
  4567   4544     assert( pOp->p1>=0 && pOp->p1<p->nCursor );

Changes to src/vdbeInt.h.

   425    425   int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
   426    426   int sqlite3VdbeCloseStatement(Vdbe *, int);
   427    427   void sqlite3VdbeFrameDelete(VdbeFrame*);
   428    428   int sqlite3VdbeFrameRestore(VdbeFrame *);
   429    429   void sqlite3VdbeMemStoreType(Mem *pMem);
   430    430   int sqlite3VdbeTransferError(Vdbe *p);
   431    431   
   432         -#ifdef SQLITE_OMIT_MERGE_SORT
   433         -# define sqlite3VdbeSorterInit(Y,Z)      SQLITE_OK
   434         -# define sqlite3VdbeSorterWrite(X,Y,Z)   SQLITE_OK
   435         -# define sqlite3VdbeSorterClose(Y,Z)
   436         -# define sqlite3VdbeSorterRowkey(Y,Z)    SQLITE_OK
   437         -# define sqlite3VdbeSorterRewind(X,Y,Z)  SQLITE_OK
   438         -# define sqlite3VdbeSorterNext(X,Y,Z)    SQLITE_OK
   439         -# define sqlite3VdbeSorterCompare(X,Y,Z) SQLITE_OK
   440         -#else
   441    432   int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
   442    433   void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
   443    434   int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
   444    435   int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
   445    436   int sqlite3VdbeSorterRewind(sqlite3 *, const VdbeCursor *, int *);
   446    437   int sqlite3VdbeSorterWrite(sqlite3 *, const VdbeCursor *, Mem *);
   447    438   int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int *);
   448         -#endif
   449    439   
   450    440   #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
   451    441     void sqlite3VdbeEnter(Vdbe*);
   452    442     void sqlite3VdbeLeave(Vdbe*);
   453    443   #else
   454    444   # define sqlite3VdbeEnter(X)
   455    445   # define sqlite3VdbeLeave(X)

Changes to src/vdbesort.c.

    14     14   ** example, by CREATE INDEX statements on tables too large to fit in main
    15     15   ** memory).
    16     16   */
    17     17   
    18     18   #include "sqliteInt.h"
    19     19   #include "vdbeInt.h"
    20     20   
    21         -#ifndef SQLITE_OMIT_MERGE_SORT
    22     21   
    23     22   typedef struct VdbeSorterIter VdbeSorterIter;
    24     23   typedef struct SorterRecord SorterRecord;
    25     24   typedef struct FileWriter FileWriter;
    26     25   
    27     26   /*
    28     27   ** NOTES ON DATA STRUCTURE USED FOR N-WAY MERGES:
................................................................................
  1033   1032     VdbeSorter *pSorter = pCsr->pSorter;
  1034   1033     void *pKey; int nKey;           /* Sorter key to compare pVal with */
  1035   1034   
  1036   1035     pKey = vdbeSorterRowkey(pSorter, &nKey);
  1037   1036     vdbeSorterCompare(pCsr, 1, pVal->z, pVal->n, pKey, nKey, pRes);
  1038   1037     return SQLITE_OK;
  1039   1038   }
  1040         -
  1041         -#endif /* #ifndef SQLITE_OMIT_MERGE_SORT */