anchor.diff:  %% refactored to explicitly understand key order at some future point.
   fix_subquery_order_compare(Qa, Qb) ->
       {startkey, Astartkey} = lists:keyfind(startkey, 1, Qa?SQL_SELECT.'WHERE'),
  -    {endkey, Aendkey} = lists:keyfind(endkey, 1, Qa?SQL_SELECT.'WHERE'),
  +    {endkey, Aendkey}     = lists:keyfind(endkey, 1, Qa?SQL_SELECT.'WHERE'),
       {startkey, Bstartkey} = lists:keyfind(startkey, 1, Qb?SQL_SELECT.'WHERE'),
  -    case Astartkey < Aendkey of
  +    {endkey, Bendkey}     = lists:keyfind(endkey, 1, Qb?SQL_SELECT.'WHERE'),
  +
  +    fix_subquery_order_compare(Astartkey, Aendkey, Bstartkey, Bendkey).
  +
  +%%
  +fix_subquery_order_compare(Astartkey, Aendkey, Bstartkey, Bendkey) ->
  +    if
  +        (Astartkey == Aendkey) ->
  +            (Astartkey =< Bstartkey orelse Aendkey =< Bendkey);
  +        (Bstartkey == Bendkey) ->
  +            not (Astartkey =< Bstartkey orelse Aendkey =< Bendkey);
  +        (Astartkey =< Aendkey) ->
  +            Astartkey =< Bstartkey;
           true ->
  -            Astartkey =< Bstartkey;
  -        false ->
               Bstartkey =< Astartkey
       end.
   
  
positive.code:             {error, E};
          Where2 ->
              Mod = riak_ql_ddl:make_module_name(Table),
              SubQueries1 =
                  [Q1?SQL_SELECT{
                         is_executable = true,
                         type          = timeseries,
                         'WHERE'       = fix_start_order(X, Mod, LK),
                         local_key     = LK,
                         partition_key = PK} || X <- Where2],
              SubQueries2 = fix_subquery_order(SubQueries1),
              {ok, SubQueries2}
      end.
  
  
negative.code:             %% timestamp field.
              W1 = lists:keystore(startkey, 1, W, {startkey, EndKey0}),
              W2 = lists:keystore(endkey, 1, W1, {endkey, StartKey0}),
              W1 = lists:keystore(startkey, 1, W, {startkey, EndKey0}),
              W2 = lists:keystore(endkey, 1, W1, {endkey, StartKey0}),
              %% start inclusive defaults true, end inclusive defaults false
              W3 = lists:keystore(start_inclusive, 1, W2,
                                  {start_inclusive, proplists:get_value(end_inclusive, W, false)}),
              _W4 = lists:keystore(end_inclusive, 1, W3,
                                   {end_inclusive, proplists:get_value(start_inclusive, W2, true)})
      end.
  
  %%
  