This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch mango-usable-flag in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit cab17f2f4f82347c1d81c8d61d8d4b5b6637dc51 Author: Robert Newson <[email protected]> AuthorDate: Wed Sep 24 11:20:35 2025 +0100 add usable prop to allow index exclusion --- src/mango/src/mango_idx.erl | 20 +++++++++++++++++++- src/mango/src/mango_opts.erl | 13 +++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/mango/src/mango_idx.erl b/src/mango/src/mango_idx.erl index d08442876..1798620a7 100644 --- a/src/mango/src/mango_idx.erl +++ b/src/mango/src/mango_idx.erl @@ -61,9 +61,10 @@ list(Db) -> Trace :: trace(). get_usable_indexes(Db, Selector, Opts, Kind) -> ExistingIndexes = list(Db), - GlobalIndexes = mango_cursor:remove_indexes_with_partial_filter_selector( + GlobalIndexes0 = mango_cursor:remove_indexes_with_partial_filter_selector( ExistingIndexes ), + GlobalIndexes = filter_usable_indexes(GlobalIndexes0), UserSpecifiedIndex = mango_cursor:maybe_filter_indexes_by_ddoc(ExistingIndexes, Opts), UsableIndexes0 = lists:usort(GlobalIndexes ++ UserSpecifiedIndex), PartitionIndexes = filter_partition_indexes(UsableIndexes0, Opts), @@ -444,6 +445,19 @@ get_idx_partitioned(Db, DDocProps) -> Default end. +get_idx_usable(_Db, DDocProps) -> + case couch_util:get_value(<<"options">>, DDocProps) of + {DesignOpts} -> + case couch_util:get_value(<<"usable">>, DesignOpts) of + U when is_boolean(U) -> + U; + undefined -> + true + end; + undefined -> + true + end. + is_opts_partitioned(Opts) -> case couch_util:get_value(partition, Opts, <<>>) of <<>> -> @@ -463,6 +477,10 @@ filter_partition_indexes(Indexes, Opts) -> Filt = fun(Idx) -> type(Idx) == <<"special">> orelse PFilt(Idx) end, lists:filter(Filt, Indexes). +filter_usable_indexes(Indexes) -> + UFilt = fun(#idx{} = Idx) -> proplists:get_value(<<"usable">>, Idx#idx.opts) == true end, + lists:filter(UFilt, Indexes). + filter_opts([]) -> []; filter_opts([{user_ctx, _} | Rest]) -> diff --git a/src/mango/src/mango_opts.erl b/src/mango/src/mango_opts.erl index c846bce14..8379ebe4a 100644 --- a/src/mango/src/mango_opts.erl +++ b/src/mango/src/mango_opts.erl @@ -75,6 +75,12 @@ validate_idx_create({Props}) -> {optional, true}, {default, db_default}, {validator, fun validate_partitioned/1} + ]}, + {<<"usable">>, [ + {tag, usable}, + {optional, true}, + {default, true}, + {validator, fun validate_usable/1} ]} ], validate(Props, Opts). @@ -311,6 +317,13 @@ validate_partitioned(db_default) -> validate_partitioned(Else) -> ?MANGO_ERROR({invalid_partitioned_value, Else}). +validate_usable(true) -> + {ok, true}; +validate_usable(false) -> + {ok, false}; +validate_usable(Else) -> + ?MANGO_ERROR({invalid_usable_value, Else}). + validate_partition(<<>>) -> {ok, <<>>}; validate_partition(Partition) ->
