Merge changes to the query planner that strive to ensure that any index
usage that is a proper subset of some other index usage always has a slightly
higher cost.
Use OP_Copy instead of OP_SCopy when moving results out of a subquery,
to prevent the subquery results from changing out from under the outer
query. Fix for ticket [1e64dd782a126f48d78].
Add a big introductory comment to vdbesort.c explaining its operation at a
high level. Also adjust some symbolic names and fix other comment issues in
that file.
dan [Tue, 1 Apr 2014 18:41:51 +0000 (18:41 +0000)]
When sorting data for a CREATE INDEX statement in single-threaded mode, assume that keys are delivered to the sorter in primary key order. Also fix various comments that had fallen out of date.
dan [Tue, 1 Apr 2014 15:38:44 +0000 (15:38 +0000)]
Even if compile time option SQLITE_MAX_WORKER_THREADS is set to one or greater, set the default number of worker threads to zero. Distribute data more evenly between threads in sqlite3VdbeSorterWrite() to improve performance when sorting large amounts of data. Add new test file sort2.test.
drh [Fri, 28 Mar 2014 03:12:48 +0000 (03:12 +0000)]
Enhance the sqlite3VdbeRecordCompare() routines so that if they encounter
database corruption, they will set the UnpackedRecord.isCorrupt field and
return 0. The sqlite3BtreeMovetoUnpacked() routine detects this and returns
SQLITE_CORRUPT, causing the corruption to be reported back to the top-level.
dan [Thu, 27 Mar 2014 19:25:02 +0000 (19:25 +0000)]
Instead of allocating a single large buffer at the beginning of each sort operation, start with a small buffer and extend it using realloc() as required.
drh [Thu, 27 Mar 2014 18:36:34 +0000 (18:36 +0000)]
Minor cleanup of the code in the query planner that computes the costs
estimates for the various plans. There are no changes to the costs at this
time. But the code is slightly more readable now and that might facilitate
future enhancements.
dan [Thu, 27 Mar 2014 17:23:41 +0000 (17:23 +0000)]
Use xFetch() to access temporary files in vdbesort.c. Use a single large allocation instead of many small allocations when accumulating records in vdbesort.c. This is an interim commit - it allocates a buffer the size of the page-cache every time data is sorted.
drh [Tue, 25 Mar 2014 11:00:21 +0000 (11:00 +0000)]
Detect when a VdbeCursor is still pointing at a valid row but that row has
moved, and invalidated the return from prior sqlite3BtreeDataFetch() or
sqlite3BtreeKeyFetch() calls.
drh [Sat, 22 Mar 2014 02:19:53 +0000 (02:19 +0000)]
Clear the sort-order flags on the KeyInfo object associated with the
OP_Compare/OP_Jump of the block-sort logic, in order to make the OP_Jump
fully testable.
drh [Sat, 22 Mar 2014 00:27:14 +0000 (00:27 +0000)]
Fix the ORDER BY optimization logic so that it will do a block-sort on
a partial DESC ORDER BY. This enhancement uncovered a memory leak in
pushUntoSorter() which is also fixed.
drh [Fri, 21 Mar 2014 19:56:09 +0000 (19:56 +0000)]
Change the names of SRT_DistTable and SRT_Table used by CTE to more
meaningful SRT_DistFifo and SRT_Fifo, respectively. Simplify the
IgnorableOrderby() macro in the process.
drh [Thu, 20 Mar 2014 19:04:56 +0000 (19:04 +0000)]
Remove a testcase() that is now always true due to the "x IN (?)" optimization.
Add an ALWAYS() around a conditional in the parser that cannot be false.
drh [Thu, 20 Mar 2014 17:03:30 +0000 (17:03 +0000)]
The "x IN (?)" optimization in check-ins [2ff3b25f40] and [e68b427afb] is
incorrect, as demonstrated by the in4-5.1 test case in this check-in.
The "COLLATE binary" that was being added to the RHS of IN was overriding
the implicit collating sequence of the LHS. This change defines the EP_Generic
expression node property that blocks all affinity or collating sequence
information in the expression subtree and adds that property to the expression
taken from RHS of the IN operator.
drh [Thu, 20 Mar 2014 14:56:47 +0000 (14:56 +0000)]
Previous check-in is not quite correct. "x IN (?)" is not exactly the same
as "x==?" do to collation and affinity issues. The correct converstion should
be to "x==(+? COLLATE binary)". The current check-in fixes this problem and
provides test cases. Ticket [e39d032577df69]
drh [Thu, 20 Mar 2014 13:26:47 +0000 (13:26 +0000)]
Convert expressions of the form "X IN (?)" with exactly one value on the
RHS of the IN into equality tests: "X=?". Add test cases to verify that
statements work correctly on this corner case.
Fix for ticket [e39d032577df6942].
dan [Thu, 20 Mar 2014 08:59:47 +0000 (08:59 +0000)]
Add an experimental fix to avoid attempting to mmap memory from an offset that is not a multiple of the system page size on systems with page sizes larger than 32KB.
drh [Wed, 19 Mar 2014 23:24:49 +0000 (23:24 +0000)]
Fix query planner weights associated with choosing block-sorting. Fix
block sorting of tables with collating functions. Fix various test cases.
All "veryquick" tests are now passing, though more tests need to be added.
drh [Wed, 19 Mar 2014 16:56:58 +0000 (16:56 +0000)]
Fix a problem in the block-sort logic that can arise if the VDBE opcode
array is resized while the block-sort logic is being coded. "make test"
now runs to completion, though there are still 17 failures.
drh [Tue, 18 Mar 2014 20:33:42 +0000 (20:33 +0000)]
Make the partial-ORDER-BY information in the query planner available to the
SELECT code generator. Still doesn't make a difference in the generated code.
drh [Tue, 18 Mar 2014 18:59:07 +0000 (18:59 +0000)]
Adjust the query planner to keep track of the number of ORDER BY terms
satisfied. Still doesn't do anything with this information. Some tests
fail after this check-in, but all failures are believed to be benign. The
failures will be addressed at a later stage.