ETS retrieve all objects before deleting the table

Frank Muller frank.muller.erl@REDACTED
Tue Jan 18 10:08:27 CET 2022


Sorry for being unclear.

Mikael: yes, it’s plain ETS ordered_set table.
Fred: I’m used to match spec and as I you’ve shown, it’s pretty easy to
extract the keys. But it’s still slow: ~90millisec for 1M integer keys on
my laptop.

I’m looking for non-documented ways or tricks not found in the doc :-)

Any other tip?

/Frank


> Hi Frank
>
> For the select/2 and match_object/2 choices you should be able to use a
> match_spec such as the following:
>
> { {'$1', '$2'}, [], {'$1'} }
>
> The first element matches your two element ETS object, the third returns
> the first element only, assuming that's the key.
>
> Cheers,
> Fred
>
> On 18/01/2022 07:46, Frank Muller wrote:
> > Hi Mikael,
> >
> > I  tried them all before posting here.
> >
> >  From fastest to slowest:
> > 1. select/2 (stable numbers)
> > 2. match_object/2
> > 3. first/1 + next/2
> > 4. tab2list
> >
> > Is there a way to only retrieve keys from an ETS table?
> > /Frank
> >
> >
> >     On Mon, Jan 17, 2022 at 10:02 PM Frank Muller
> >     <frank.muller.erl@REDACTED <mailto:frank.muller.erl@REDACTED>>
> wrote:
> >      >
> >      > Hey guys,
> >      >
> >      > Is there a way (documented or not) to retrieve all objects from
> an ordered_set table?
> >      >
> >      > I’d like to retrieve all objects before deleting the table.
> >      > What’s the most efficient way to do it?
> >      >
> >      > My table contains roughly ~1 million objects.
> >      > Objects are tuple: {non_neg_integer(), pos_integer()}
> >
> >     ets:tab2list/1, or possibly ets:match_object/2 or ets:select/2 (I
> >     haven't benchmarked them).
> >     They are all documented.
> >
> >     ($subject mentions ETS, so I assume this is about plain ETS and not
> >     Mnesia ram_copies or something like that.)
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20220118/d8bd4e1f/attachment.htm>


More information about the erlang-questions mailing list