Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -364,10 +364,18 @@ */ #ifndef SQLITE_TEMP_STORE # define SQLITE_TEMP_STORE 1 #endif +/* +** If all temporary storage is in-memory, then omit the external merge-sort +** logic since it is superfluous. +*/ +#if SQLITE_TEMP_STORE==3 && !defined(SQLITE_OMIT_MERGE_SORT) +# define SQLITE_OMIT_MERGE_SORT +#endif + /* ** GCC does not define the offsetof() macro so we'll have to do it ** ourselves. */ #ifndef offsetof Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -3154,10 +3154,16 @@ ** This opcode works the same as OP_OpenEphemeral. It has a ** different name to distinguish its use. Tables created using ** by this opcode will be used for automatically created transient ** indices in joins. */ +/* Opcode: OpenSorter P1 P2 * P4 * +** +** This opcode works like OP_OpenEphemeral except that it opens +** a transient index that is specifically designed to sort large +** tables using an external merge-sort algorithm. +*/ case OP_OpenSorter: case OP_OpenAutoindex: case OP_OpenEphemeral: { VdbeCursor *pCx; static const int vfsFlags =