Database / Mnesia intermediate to advanced Interview questions
What is mnesia:all_keys/1 used for?
mnesia:all_keys(Table) returns every primary key currently stored in a table, run inside a
transaction (or a dirty context via mnesia:dirty_all_keys/1) — a quick way to enumerate a
table's contents by key without writing a match specification.
mnesia:transaction(fun() -> mnesia:all_keys(person) end). %% -> {atomic, [1, 2, 3, 4]}
It's convenient for small-to-moderate tables (iterating configuration, listing registered sessions), but it
does mean scanning the whole table's key space, so on a very large table a more targeted
select/2 query with an actual filter condition is usually a better fit than pulling every key and
filtering client-side afterward.
More Related questions...