Ruby on Rails Thursday, December 2, 2010

Fearless Fool wrote in post #965610:
> This question may be so obvious that even Marnen won't answer it... :)

I can't resist a challenge like that. :D

>
> I need to store a set of relatively complex objects in the db -- in my
> case, these are discrete cumulative distribution functions: they take a
> long time to construct, but I want the lookup to be fast. Since the
> lookup is essentially a binary search, a B-Tree or some variant would be
> a sensible data structure.
>
> I have choices: (a) I store entire YAML'd B-Trees, (b) I store simple
> data structure (e.g. arrays of numeric pairs) and spend time
> constructing a B-Tree from it, or (c) choose another approach that
> someone on this list points out.

How about C? Nested sets are generally a great way of storing arbitrary
trees in SQL databases for easy retrieval. The awesome_nested_set
plugin makes this easy to do in Rails.

If you're unfamiliar with nested sets, I recommend
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html as a
good overview.

Or do I misunderstand? What's the nature of the tree you'd like to
store?

>
> Can this forum offer any advice on size / speed tradeoffs for YAML'd
> objects? If unpacking a YAML'd object is fast, then (a), storing the
> entire B-Tree is probably the best approach. If slow, then perhaps I'm
> better off with (b), storing a minimal data structure and reconstructing
> the B-Tree when I need it.

Speed may not be your immediate concern with YAML: the big problem with
that approach is that it bypasses the structure of the database and
makes the data very difficult to query. It's a decent last resort, but
it *is* a last resort.

>
> Thoughts?
>
> - ff

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment