couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Samuel Newson <>
Subject Re: question about "complex" range queries
Date Wed, 02 Apr 2014 23:06:15 GMT
No, only the key. If you have 10 rows with identical keys, you’ll find that they are in document
_id order.


On 2 Apr 2014, at 23:57, wrote:

> Thanks Robert. Let me clarify. Is the value included in the sort? I have 10 entries all
with identical keys. The behavior I am seeing indicates the contents of the emitted value
is included in the sort criteria and if so can I count on this? Bottom line I am trying to
sort on 2 fields, one is a key and the other is the beginning of the value. I also don't want
to sort the results in a list due to performance constraints
> Thanks
> On Apr 2, 2014, at 5:45 PM, Robert Samuel Newson <> wrote:
>> A view is a single dimension index, ordered by the full key in accordance with the
rules enumerated here:
>> For example;
>> 9 sorts after false
>> 999 sorts after 9
>> "foo" sorts after 999
>> ["foo"] sorts after "foo"
>> ["foo", "bar"] sorts after ["foo"]
>> B.
>> On 2 Apr 2014, at 23:29, wrote:
>>> I have a quick question related to this. What exactly is sorted? My test cases
indicated the key AND the entire value is sorted as if it was one big string. 
>>> Thanks
>>> Rian
>>> On Apr 2, 2014, at 2:31 AM, Nick North <> wrote:
>>>> It doesn't work quite like this. There is a single order across all
>>>> possible keys, including both simple and complex keys, as described
>>>> here<>.
>>>> In the case of keys that are lists, the two lists are compared element by
>>>> element and the sort order is the sort order of the first unequal elements.
>>>> In your example, if a key has its first element between a1 and a2 (and a1
>>>> and a2 are different), then the second element will not be inspected at
>>>> all, so it does not matter whether it is between b1 and b2 or not. In fact
>>>> the second element will only be inspected if the first element is either
>>>> or a2.
>>>> This is usually the behaviour we want. For example, dates are often
>>>> represented as lists of [year, month, day]. Then you can pull out all the
>>>> documents in a date range by specifying start date and end date as startkey
>>>> and endkey. For example, if these are [2012, 4, 5] and [2014, 8, 3]
>>>> respectively, we want to include [2013, 3, 6] in the output even though its
>>>> second element does not lie between the second elements of the keys.
>>>> Nick
>>>> On 2 April 2014 03:56, Schroiff, Klaus <>
>>>>> Hi,
>>>>> Let's assume that I have the following view function:
>>>>> function(doc) { emit([a, b], whatever) } }
>>>>> In the query I'm running something like
>>>>> startkey=[a1, b1] & endkey=[a2,b2]
>>>>> Thus there're TWO explicit ranges here - a1->a2 and b1->b2.
>>>>> What is the expected result ?
>>>>> My understanding:
>>>>> The query is executed in two phases
>>>>> In the first phase, the index is filtered for qualifying results where
>>>>> first key ranges from a1 to a2
>>>>> In the second phase, these filtered results are filtered once more
>>>>> according to the range of the second emitted key from b1 to b2.
>>>>> Thus essentially an "AND" operation.
>>>>> The filtering is performed using lexicographical rules.
>>>>> Is that correct ? The doc about complex keys is a bit slim.
>>>>> Thanks
>>>>> Klaus

View raw message