Some of my tables (in a web application using Pylons) will eventually
need to be partitioned to separate shards, but some tables won't. For
example, imagine that I'd like to partition a Users table across 3
different databases, while leaving others just on one master database.

I've read the ShardedSession docs a few times. The shard_chooser()
callable is straightforward, and thanks to the example [1], I think I
understand how to use query_chooser(); but I need a pointer about how
to use id_chooser() properly. The docs describe id_chooser as this: "a
function which can return a list of shard ids which apply to a
particular instance identifier", but that seems unclear to me.

Say I issue the following queries:

1) Session.query(User).filter_by(id=4)
2) Session.query(UnrelatedTable).filter_by(id=567)
3) Session.query(UserProfiles).filter_by(user_id=4) # where
UserProfiles is mapped to a User class

In the first query, the id_chooser would simply return the proper
shard, since I know that I'm querying for a User. The second query
searches for a completely unrelated (non-sharded) table; how would I
inspect the id_chooser()'s "query" parameter to determine that it's
searching for a user? Lastly, in the third query above, which only
indirectly wants to find a User class, which shard callable would be
invoked and how do I make sure it finds the right shard for the
associated User?

A related question: Should I use a separate "Session" to separate the
sharded tables from the non-sharded ones, in the case where I would
not need to aggregate queries between the two sessions?

If I were doing this in plain SQL, I'd probably just connect to all of
the databases, and then manually choose which instance to perform
individual queries on (query aggregation between shards doesn't need
to happen much in my current project). Apologies in advance if my
questions are confusing; I'm having trouble grasping whether it's
feasible to use the ORM for this or if it would be simpler/clearer to
take a more manual approach.

[1]: 
http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/sharding/attribute_shard.py
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to