On Sat, Aug 21, 2010 at 8:09 AM, Andy <selforgani...@gmail.com> wrote:
>

> So is there any way to write the database router to route the above
> query?

Other than explicitly naming the database -- not at present.

Of course, given that you know your sharding scheme, you could use the
router directly.

Tweet.objects.using(router.db_for_read(Tweet, author=a)).filter(author_id=a)

This will use the router to determine the right database, based upon a
custom 'author' hint. It will require a bit of extra logic in your
router, and a little extra work whenever you use the Tweet object.,
but it will ensure your routing logic is used consistently.

>> If you think that Django isn't providing
>> sufficient information to implement a specific routing scheme, make
>> your case and we will see about adding whatever extra information may
>> be required.
>
> The issue with using only "instance" as a hint is that in almost all
> cases of database reads there isn't any instance to speak of at the
> time the query is being issued. After all the very purpose of a
> database read is to retrieve the instance!

No - the purposes of a database read is to issue queries, which may
represent an instance, or many instances, or selected columns from one
or many instances, or aggregated data across instances.

The filter clause *might* include the argument being used as a
sharding deteminant, or it might not; it might be a simple equality
query, or it might be a gt/lt/not clause; and the sharding behavior
that is implemented may be based on a combination of multiple factors,
rather than a single field value.

As always, the devil is in the detail.

> The above example of:
> Tweet.objects.filter(author_id=123)
> represents pretty much the most common scenario for database sharding.
> I'd think it's important for Django's multidatabase function to be
> able to handle a case like that.

You won't get any argument from me. What's missing is a clear
suggestion on how we can encompass this problem in the general case.
Suggestions are welcome.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to