Database / Mnesia intermediate to advanced Interview questions
What is the difference between mnesia:dirty_all_keys/1 and mnesia:all_keys/1?
Both return every primary key in a table, but they differ in the same way other dirty/transactional pairs
do: mnesia:all_keys/1 must run inside a transaction (or another activity context) and takes the
appropriate lock, giving you a result consistent with the rest of that transaction's view of the data.
mnesia:dirty_all_keys/1 reads directly with no transaction or locking.
%% transactional mnesia:transaction(fun() -> mnesia:all_keys(person) end). %% dirty mnesia:dirty_all_keys(person).
The dirty version is faster and simpler to call, but the key list it returns could be stale by the time you act on it if concurrent writers are actively adding/removing records at the same moment — acceptable for a rough count or a best-effort listing, but not for logic that depends on the key list being exactly consistent with other reads happening in the same transaction.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
