I have a schema something like this:

-record(sale, {
  id,
  price,
  tax,
  sku,
  datetime
})

-record(refund, {
  id,
  sale_id,
  datetime
})

There are about 600,000 records in the sale table and about 20,000 in the refund table.

I need to fold over the data in the sales table, grouping each sku with the amount received (price) and the amount refunded (by checking #refund.sale_id).

Is there an efficient way to do this with Mnesia, that avoid the N+1 query problem where for each sale in the fold operation, I need to make a second call the mnesia to see if a refund exists? Some way of doing a naive join?

有帮助吗?

解决方案

Is your sale table ordered_set? If yes, you can do merge join as usual. First get all refund and sort them by sale_id. Then just fold over sale and accumulate into dict or ets by sku key.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top