Forum: Ruby on Rails [OT] Comments wanted on use of bitwise op

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
925c5035ff3e0005e0604c0cd869b5cf?d=identicon&s=25 Chris T (Guest)
on 2006-03-14 19:22
Here's the scenario. I have a main tree-like table (actually it's more
of a hierarchy), where the entries (or at least some of them) can be
categorised as one or more of a fixed number of types (prob about 6 poss
types). So an entry could be a Type A and a Type D; a Type C, D, E; just
a Type F; etc.

Having a join table would seem like it might get rather expensive since
I'm going to want to know the types each time I call an entry. Seemed an
obvious way would be to use an integer and bitwise ops, so that each bit
in the integer represrented a type which could be on or off.

Does anyone have any comments re the wisdom or otherwise of doing this?
Would the benefits be outweighed by the calculation overhead? Any better
way that I haven't thought of?

Cheers in advance
Chris T

(p.s. I'm using MySQL at the moment)
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Dave Teare (Guest)
on 2006-03-14 21:00
(Received via mailing list)
I personally think the join table is a cleaner solution simpy because
Rails provides such good support for it.  However, I agree it can be
overkill.  At DevLists, we needed to keep track of the read/unread
messages for each mailing list a member subscribed to.  I originally
used a join table, but the thought of 10K members needing to keep track
of 100K messages made my colleague think I was nuts (1 billion records
is nothing to sneeze at, even for MySQL).

The approach we took was to add a TEXT field to one of the tables and
storing some YAML into it.  This way we could easily optimize the

I hope that helps.

On Tuesday, March 14, 2006, at 7:22 PM, Chris T wrote:
>Posted via
>Rails mailing list

--Dave Teare - Email list management - Apps for your hand-held
92dafea96df3ff949b426b235a19ae0e?d=identicon&s=25 Chris Taggart (Guest)
on 2006-03-14 21:18
(Received via mailing list)
I hadn't thought of YAML (haven't used it before), though I had wondered
about using a string composed of the types 'AD', 'CDE', 'F' etc, which
would be halfway between the two and might work better that bitwise ops
(I need to be able to do a select of those entries of Type B, for
example). Would YAML be easier/quicker to parse? How about select
statements? From a quick look at the Pickaxe (I'm a ruby nuby) YAML
seems pretty straightforward to use in Ruby -- always a bonus ;-)
This topic is locked and can not be replied to.