This is an automated email from the ASF dual-hosted git repository.
nickva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new f5e6aa5ef Fix silent row loss in Mango _id range queries
f5e6aa5ef is described below
commit f5e6aa5ef501dd372112dac371918495fe434276
Author: readyprompt <[email protected]>
AuthorDate: Sun Sep 20 15:02:00 2026 -0500
Fix silent row loss in Mango _id range queries
The silent row loss in Mango _id range queries was originally
addressed in 55ad18eeb (2014, "Fix broken comparisons on _id fields").
It regressed with f231a28a0 because selector fields <<"_id">> were
normalized to [<<"_id">>]. The failure to match caused a fall-back to
ICU collation. This failure caused the post-scan filter to silently
drop documents.
Corrected mango_selector:match/3 to correctly match the normalized
field and added a regression test.
---
src/mango/src/mango_selector.erl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl
index e53820c4a..0e017faff 100644
--- a/src/mango/src/mango_selector.erl
+++ b/src/mango/src/mango_selector.erl
@@ -556,7 +556,7 @@ match({[{Field, Cond}]}, Value, Cmp) ->
false;
bad_path ->
false;
- SubValue when Field == <<"_id">> ->
+ SubValue when Field == [<<"_id">>] ->
match(Cond, SubValue, fun mango_json:cmp_raw/2);
SubValue ->
match(Cond, SubValue, Cmp)
@@ -1712,4 +1712,9 @@ match_nor_test() ->
?assertEqual(false, match_int(SelMulti, {[{<<"x">>, 9}]})),
?assertEqual(false, match_int(SelMulti, {[]})).
+match_id_raw_collation_test() ->
+ % _id compares by byte-order, not by ICU rules
+ Sel = normalize({[{<<"_id">>, {[{<<"$gte">>, <<"Z">>}]}}]}),
+ ?assertEqual(true, match_int(Sel, {[{<<"_id">>, <<"a">>}]})).
+
-endif.