# Is ETS table of type ordered\_set able to do efficient range search with match spec?

**URL:** <https://erlangforums.com/t/is-ets-table-of-type-ordered-set-able-to-do-efficient-range-search-with-match-spec/2689>\
**Category:** Questions / Help\
**Tags:** erlang-otp\
**Created:** [June 13, 2023, 3:39am UTC](https://erlangforums.com/t/is-ets-table-of-type-ordered-set-able-to-do-efficient-range-search-with-match-spec/2689 "2023-06-13T03:39:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sverker](https://erlangforums.com/user_avatar/erlangforums.com/sverker/32/841_2.png) [@sverker](https://erlangforums.com/u/sverker)\
**Post date:** [June 13, 2023, 9:29am UTC](https://erlangforums.com/t/is-ets-table-of-type-ordered-set-able-to-do-efficient-range-search-with-match-spec/2689/2 "2023-06-13T09:29:16Z")

</div>

ETS is not smart enough to utilize guards like `Timestamp > Time1` to limit the search space. It will only utilize **fully bound keys** and **partially bound keys** in the head of the match spec as described at the bottom of this section:  
[https://www.erlang.org/doc/man/ets.html#table-traversal](https://www.erlang.org/doc/man/ets.html#table-traversal)

See also this recent forum thread:

> [@Variable shadowing constraint of match spec generated using ms\_transform](https://erlangforums.com/t/variable-shadowing-constraint-of-match-spec-generated-using-ms-transform/2656):
>
> Looks like that is a variable shadowing constraint of match spec that is generated using ms\_transform. For example, get\_match\_spec(Id) -\> ets:fun2ms(fun({Id, Content} = Item) -\> {Id, [mark | Content]} end). Warning: variable 'Id' shadowed in ms\_transform fun head get\_match\_spec(123). Output: [{{'$1','$2'},[],[{{'$1',[mark|'$2']}}]}] Thus ets:select\_replace can’t efficiently be used to select\_replace an item with the given Id. One way is to use guard get\_match\_spec(Id) -\> ets:fun2ms(…

---

_[View the full topic](https://erlangforums.com/t/is-ets-table-of-type-ordered-set-able-to-do-efficient-range-search-with-match-spec/2689)._
