nickva commented on code in PR #6080:
URL: https://github.com/apache/couchdb/pull/6080#discussion_r4198675919


##########
src/mango/src/mango_selector.erl:
##########
@@ -299,9 +321,16 @@ norm_negations({[{<<"$or">>, Args}]}) ->
 norm_negations({[{<<"$elemMatch">>, Arg}]}) ->
     {[{<<"$elemMatch">>, norm_negations(Arg)}]};
 norm_negations({[{<<"$allMatch">>, Arg}]}) ->
-    {[{<<"$allMatch">>, norm_negations(Arg)}]};
+    Out = norm_negations(Arg),
+    {[{<<"$allMatch">>, Out}]};
 norm_negations({[{<<"$keyMapMatch">>, Arg}]}) ->
     {[{<<"$keyMapMatch">>, norm_negations(Arg)}]};
+% Sometimes a top-level key will be a doc field because it
+% can't be pushed down through its corresponding operator,
+% e.g. {x: {$allMatch: S}}. Negation inside the $allMatch
+% should still be normalized.
+norm_negations({[{Field, Cond}]}) when is_list(Field) ->

Review Comment:
   An example of a filtered replication which change results based on the pr.
   
   A mitigating factor for a continuous replication might be that I think 
replication id would change so old checkpoints won't be found it would be 
rewound. A completed replication obviously won't be re-run automatically.
   
   A similar setup might affect partial index selector 
https://docs.couchdb.org/en/stable/ddocs/mango.html#find-partial-indexes
   
   ```sh
   #!/bin/sh
   
   http DELETE $DB/src
   http DELETE $DB/tgt
   
   http PUT $DB/src
   http PUT $DB/tgt
   http PUT $DB/src/doc1 name=a thingers:='[{"type":"veg"},{"type":"fruit"}]'
   http PUT $DB/src/doc2 name=b thingers:='[{"type":"veg"},{"type":"rock"}]'
   
   # thingers are all neither tools nor rocks
   http PUT $DB/_replicator
   http POST $DB/_replicate source=${DB}/src target=${DB}/tgt  
selector:='{"thingers": {"$allMatch": {"$nor": [{"type":"tool"}, 
{"type":"rock"}]}}}'
   
   http $DB/tgt/_all_docs
   
   ### before VDU mango PR
   
   # {
   #     "offset": 0,
   #     "rows": [],
   #     "total_rows": 0
   # }
   
   ### after VDU mango PR
   
   # {
   #     "offset": 0,
   #     "rows": [
   #         {
   #             "id": "doc1",
   #             "key": "doc1",
   #             "value": {
   #                 "rev": "1-3d2d5bea046d1cc1e3ffb40b2de8411e"
   #             }
   #         }
   #     ],
   #     "total_rows": 1
   # }
   ```



-- 
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