[erlang-questions] Deleting millions of rows in mnesia

Chandru chandrashekhar.mullaparthi@REDACTED
Fri Mar 2 11:03:23 CET 2007


On 02/03/07, Ulf Wiger <ulf@REDACTED> wrote:
> Den 2007-03-02 07:29:01 skrev Bengt Kleberg <bengt.kleberg@REDACTED>:
>
> > On 2007-03-02 00:44, Anders Nygren wrote:
> >> Hi
> >> I have a mnesia table that collects some data during one month, and then
> >> it should be cleared, in order to collect data for the next month.
> >> The table could be up to 10 million rows.
> >>
> >> What is the best way to clear the table?
> >> - mnesia:clear_table/1
> >> - delete and recreate the table
> >

<snip>

> Semantically, there's a difference in that if you
> call mnesia:delete_table(Tab), mnesia:create_table(Tab, Opts),
> there is no possibility of rollback(*), and the table will
> actually disappear for a while, which may or may not be
> difficult to handle for other parts of the application.

What I would do in such a case is two have two identical tables with
different names, say A and B. You have some other config which
indicates which is the "active" table. Any process which needs to
access this table reads the config to figure out whether it should
access A or B. When the time comes for the active table to be purged,
change the config to point to the standby table. Then take all the
time you need to empty the old table.

Chandru



More information about the erlang-questions mailing list