When SQLite is compiled using SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4, it
gets the wrong answer for the first of the two queries below:

<blockquote><verbatim>
CREATE TABLE nodes(
   local_relpath  TEXT PRIMARY KEY,
   moved_to  TEXT
);
INSERT INTO nodes VALUES('A',NULL);
INSERT INTO nodes VALUES('A/B',NULL);
INSERT INTO nodes VALUES('',NULL);
INSERT INTO nodes
INSERT INTO nodes
INSERT INTO nodes VALUES('A/B-move',NULL);
INSERT INTO nodes
INSERT INTO nodes

SELECT local_relpath, moved_to
 FROM nodes
WHERE (local_relpath = 'A/B' OR ((local_relpath > AND (local_relpath < 'A/B0')))
  AND moved_to IS NOT NULL;

.print ------------------------------------------------

SELECT local_relpath, moved_to
 FROM nodes
WHERE (+local_relpath = 'A/B' OR ((local_relpath > AND (local_relpath < 'A/B0')))
  AND moved_to IS NOT NULL;


The bug appears to have been inserted into trunk with the STAT4 changes
of check-in [a32af0abe5fa6d] which occurred just after the release of
3.8.0.  The bug first appeared in 3.8.1.

Note that it is not necessary to run
ANALYZE or to have sqlite_stat3 or sqlite_stat4 tables in the database.
The only requirement is to compile with SQLITE_ENABLE_STAT3 or
SQLITE_ENABLE_STAT4.

The extra unary "+" operator in the second queries disable the OR optimization
and enables the second query to get the correct answer regardless.

This bug was discovered in the wild by the SVN developers.