Database / Mnesia basics Interview questions
When should you choose bag over set for a Mnesia table?
Choose bag when a single key naturally has multiple associated values that all need to coexist
as separate records — a classic one-to-many relationship you'd otherwise model with a separate join
table in a relational database.
mnesia:create_table(item_tag, [{attributes, [item_id, tag]}, {type, bag}]), mnesia:write({item_tag, 101, "sale"}), mnesia:write({item_tag, 101, "clearance"}). %% both coexist under item_id 101
set remains the right default whenever each key genuinely identifies exactly one record —
most tables fall into this category. Reach for bag specifically when you catch yourself needing
to store several distinct values under what is conceptually "the same key," rather than forcing that into a
single record with a list-valued field, which would make querying and indexing individual associated values
harder.
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...
