SQLite

Ticket Change Details
Login
Overview

Artifact ID: 1ef35260c9e915837167ad06e6debaeee6d5433d
Ticket: d06a25c84454a372be4e4c970c3c4d4363197219
Incorrect result from a UNION with an ORDER BY
User & Date: drh 2016-02-09 14:12:17
Changes

  1. icomment:
    The problem was two co-routines using the same temporary registers and
    expecting those temporary registers to be preserved across a Yield.  The
    solution is to ensure that every co-routine has its own set of temporary
    registers that are not shared with the main thread or other co-routines.
    
    In the demonstration query shown in the problem description, each SELECT
    statement is evaluated by a separate co-routine that includes an ORDER BY.
    The main thread handles the UNION by running each co-routine long enough
    to generate a single row, then choosing the smaller of the two
    rows to output and running the corresponding co-routine to generate the
    next row for that SELECT.  Each co-routine evaluates its query as a nested
    loop with t0 being the outer loop and t1 being the inner loop.  The t0.a
    and t0.b values are stored in temporary registers in the outer loop, and
    those value are expected to remain intact even though a Yield occurs after
    each iteration of the inner loop.  Prior to the fix of
    check-in [ca72be8618e5d466] both co-routines were using the same temporary
    registers for their t0.a and t0.b values, which means that running one
    co-routine would disrupt the other.  After check-in [ca72be8618e5d466] the
    two co-routines use different temporary registers for holding t0.a and
    t0.b so they no longer interfere with one another.
    
  2. login: "drh"
  3. mimetype: "text/x-fossil-wiki"
  4. priority changed to: "Immediate"
  5. resolution changed to: "Fixed"
  6. status changed to: "Fixed"
  7. subsystem changed to: "Code_Generator"