Database / Mnesia intermediate to advanced Interview questions
Why would you use qlc:q with mnesia:table/1 instead of mnesia:select/2?
select/2 is a single-table, match-specification-based query — excellent for filtering one
table efficiently, but it can't express a relationship spanning multiple tables in one query. QLC's
comprehension syntax reads much closer to how you'd describe the query in plain language (join these two
tables, filter, sort), and it can combine several mnesia:table/1 sources in one expression.
%% Multi-table join with QLC Q = qlc:q([{P#person.name, T#tag.tag} || P <- mnesia:table(person), T <- mnesia:table(item_tag), P#person.id =:= T#item_tag.item_id]), qlc:e(Q).
The tradeoff is that QLC's flexibility comes with more overhead than a tightly targeted
select/2 call on a single table — for a simple single-table filter, plain
select/2 (or even match_object/1) is usually the leaner, faster choice; QLC earns its
keep specifically once the query genuinely needs to correlate data across more than one table.
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...
