jcoglan edited a comment on issue #3773:
URL: https://github.com/apache/couchdb/issues/3773#issuecomment-937846761


   It's also interesting that querying the view without `keys` lists two rows 
with `q=2`:
   
   ```
   See what is in the view
   00000000  7b 22 72 6f 77 73 22 3a  5b 0d 0a 7b 22 6b 65 79  
|{"rows":[..{"key|
   00000010  22 3a 5b 22 66 69 6c 65  22 2c 22 63 68 61 c3 ae  
|":["file","cha..|
   00000020  6e 65 22 5d 2c 22 76 61  6c 75 65 22 3a 31 7d 2c  
|ne"],"value":1},|
   00000030  0d 0a 7b 22 6b 65 79 22  3a 5b 22 66 69 6c 65 22  
|..{"key":["file"|
   00000040  2c 22 63 68 61 69 cc 82  6e 65 22 5d 2c 22 76 61  
|,"chai..ne"],"va|
   00000050  6c 75 65 22 3a 31 7d 0d  0a 5d 7d 0a              |lue":1}..]}.|
   0000005c
   ```
   
   ... but only a single row with `q=1`. The row returned has key bytes `c3 ae` 
representing codepoint U+00EE. Notes its `value` is `2` indicating there are 
actually two rows stored in the view, but their keys have been considered equal 
by the `_count` function.
   
   ```
   See what is in the view
   00000000  7b 22 72 6f 77 73 22 3a  5b 0d 0a 7b 22 6b 65 79  
|{"rows":[..{"key|
   00000010  22 3a 5b 22 66 69 6c 65  22 2c 22 63 68 61 c3 ae  
|":["file","cha..|
   00000020  6e 65 22 5d 2c 22 76 61  6c 75 65 22 3a 32 7d 0d  
|ne"],"value":2}.|
   00000030  0a 5d 7d 0a                                       |.]}.|
   00000034
   ```
   
   So it does seem as though if these two rows are stored in the same shard, 
their keys are considered equal and they get merged, but not if they're 
(potentially) stored in different shards. I also tried running this example 
with the `reduce` and `group` operations removed just to see what rows we'd 
get. With `q=1` or `q=2` I get the same results; all queries return _two_ rows:
   
   ```
   See what is in the view
   00000000  7b 22 74 6f 74 61 6c 5f  72 6f 77 73 22 3a 32 2c  
|{"total_rows":2,|
   00000010  22 6f 66 66 73 65 74 22  3a 30 2c 22 72 6f 77 73  
|"offset":0,"rows|
   00000020  22 3a 5b 0d 0a 7b 22 69  64 22 3a 22 64 6f 63 31  
|":[..{"id":"doc1|
   00000030  22 2c 22 6b 65 79 22 3a  5b 22 66 69 6c 65 22 2c  
|","key":["file",|
   00000040  22 63 68 61 c3 ae 6e 65  22 5d 2c 22 76 61 6c 75  
|"cha..ne"],"valu|
   00000050  65 22 3a 6e 75 6c 6c 7d  2c 0d 0a 7b 22 69 64 22  
|e":null},..{"id"|
   00000060  3a 22 64 6f 63 32 22 2c  22 6b 65 79 22 3a 5b 22  
|:"doc2","key":["|
   00000070  66 69 6c 65 22 2c 22 63  68 61 69 cc 82 6e 65 22  
|file","chai..ne"|
   00000080  5d 2c 22 76 61 6c 75 65  22 3a 6e 75 6c 6c 7d 0d  
|],"value":null}.|
   00000090  0a 5d 7d 0a                                       |.]}.|
   00000094
   Request the view, one time for each encoding
   00000000  7b 22 74 6f 74 61 6c 5f  72 6f 77 73 22 3a 32 2c  
|{"total_rows":2,|
   00000010  22 6f 66 66 73 65 74 22  3a 30 2c 22 72 6f 77 73  
|"offset":0,"rows|
   00000020  22 3a 5b 0d 0a 7b 22 69  64 22 3a 22 64 6f 63 31  
|":[..{"id":"doc1|
   00000030  22 2c 22 6b 65 79 22 3a  5b 22 66 69 6c 65 22 2c  
|","key":["file",|
   00000040  22 63 68 61 c3 ae 6e 65  22 5d 2c 22 76 61 6c 75  
|"cha..ne"],"valu|
   00000050  65 22 3a 6e 75 6c 6c 7d  2c 0d 0a 7b 22 69 64 22  
|e":null},..{"id"|
   00000060  3a 22 64 6f 63 32 22 2c  22 6b 65 79 22 3a 5b 22  
|:"doc2","key":["|
   00000070  66 69 6c 65 22 2c 22 63  68 61 69 cc 82 6e 65 22  
|file","chai..ne"|
   00000080  5d 2c 22 76 61 6c 75 65  22 3a 6e 75 6c 6c 7d 0d  
|],"value":null}.|
   00000090  0a 5d 7d 0a                                       |.]}.|
   00000094
   00000000  7b 22 74 6f 74 61 6c 5f  72 6f 77 73 22 3a 32 2c  
|{"total_rows":2,|
   00000010  22 6f 66 66 73 65 74 22  3a 30 2c 22 72 6f 77 73  
|"offset":0,"rows|
   00000020  22 3a 5b 0d 0a 7b 22 69  64 22 3a 22 64 6f 63 31  
|":[..{"id":"doc1|
   00000030  22 2c 22 6b 65 79 22 3a  5b 22 66 69 6c 65 22 2c  
|","key":["file",|
   00000040  22 63 68 61 c3 ae 6e 65  22 5d 2c 22 76 61 6c 75  
|"cha..ne"],"valu|
   00000050  65 22 3a 6e 75 6c 6c 7d  2c 0d 0a 7b 22 69 64 22  
|e":null},..{"id"|
   00000060  3a 22 64 6f 63 32 22 2c  22 6b 65 79 22 3a 5b 22  
|:"doc2","key":["|
   00000070  66 69 6c 65 22 2c 22 63  68 61 69 cc 82 6e 65 22  
|file","chai..ne"|
   00000080  5d 2c 22 76 61 6c 75 65  22 3a 6e 75 6c 6c 7d 0d  
|],"value":null}.|
   00000090  0a 5d 7d 0a                                       |.]}.|
   00000094
   ```
   
   Something curious is going on here: both documents are stored distinctly and 
produce two distinct view rows, the `keys` param matches both rows no matter 
which encoding is used, and when `q=1` the `reduce`/`group` operation with 
`_count` considers the rows' keys equal and merges them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to