anchor.diff:  -spec expand_where(filter(), #key_v1{}, integer()) ->
           [where_props()] | {error, any()}.
   expand_where(Where, PartitionKey, MaxSubQueries) ->
  -    case find_quanta_function_in_key(PartitionKey) of
  -        [{[QField], QSize, QUnit}] ->
  -            hash_timestamp_to_quanta(QField, QSize, QUnit, MaxSubQueries, Where);
  -        [] ->
  +    case find_quantum_field_index_in_key(PartitionKey) of
  +        {QField, QSize, QUnit, QIndex} ->
  +            hash_timestamp_to_quanta(QField, QSize, QUnit, QIndex, MaxSubQueries, Where);
  +        notfound ->
               [Where]
       end.
   
  -%%
  -find_quanta_function_in_key(#key_v1{ ast = PKAST }) ->
  -    [{X, Y, Z} || #hash_fn_v1{mod = riak_ql_quanta, fn = quantum,
  -                              args = [#param_v1{name = X}, Y, Z]} <- PKAST].
  -
  -%%
  -hash_timestamp_to_quanta(QField, QSize, QUnit, MaxSubQueries, Where) ->
  +%% Return the parameters for the quantum function and it's index in the
  +%% partition key fields.
  +-spec find_quantum_field_index_in_key(#key_v1{}) ->
  +    {QName::binary(), QSize::integer(), QUnit::atom(), QIndex::integer()}.
  +find_quantum_field_index_in_key(#key_v1{ ast = PKAST }) ->
  +    find_quantum_field_index_in_key2(PKAST, 1).
  +
  +%%
  +find_quantum_field_index_in_key2([], _) ->
  +    notfound;
  +find_quantum_field_index_in_key2([#hash_fn_v1{ mod = riak_ql_quanta,
  +                                               fn = quantum,
  +                                               args = [#param_v1{name = [X]}, Y, Z] }|_], Index) ->
  +    {X,Y,Z,Index};
  +find_quantum_field_index_in_key2([_|Tail], Index) ->
  +    find_quantum_field_index_in_key2(Tail, Index+1).
  +
  +%%
  +hash_timestamp_to_quanta(QField, QSize, QUnit, QIndex, MaxSubQueries, Where) ->
       GetMaxMinFun = fun({startkey, List}, {_S, E}) ->
  -                           {element(3, lists:last(List)), E};
  +                           {element(3, lists:nth(QIndex, List)), E};
                         ({endkey,   List}, {S, _E}) ->
  -                           {S, element(3, lists:last(List))};
  +                           {S, element(3, lists:nth(QIndex, List))};
                         (_, {S, E})  ->
                              {S, E}
                      end,
  
positive.code:         compile(DDL, Q, 100)
      ).
  
  -endif.
  
negative.code:         {true, NewW} -> NewW
      end.
  
  %%
  quantum_field_name(DDL) ->
      case find_quantum_fields(DDL) of
          [QFieldName] ->
              QFieldName;
          [] ->
              no_quanta
      end.
  
  %%
  find_quantum_fields(#ddl_v1{ partition_key = #key_v1{ ast = PKAST } }) ->
      [quantum_fn_to_field_name(QuantumFunc) || #hash_fn_v1{ } = QuantumFunc <- PKAST].
  
  %%
  quantum_fn_to_field_name(#hash_fn_v1{ mod = riak_ql_quanta,
                                        fn = quantum,
                                        args = [#param_v1{name = [Name]}|_ ] }) ->
      Name.
  
  check_if_timeseries(#ddl_v1{table = T, partition_key = PK, local_key = LK0} = DDL,
                      [W]) ->
  