Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-23 Thread Steve Holden
On 8/23/2010 8:08 AM, Russell Keith-Magee wrote: > On Mon, Aug 23, 2010 at 7:53 PM, Steve Holden wrote: >> On 8/23/2010 7:48 AM, Russell Keith-Magee wrote: >>> On Mon, Aug 23, 2010 at 7:32 PM, Andy wrote: >> [...] Also how random is random -

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-23 Thread Russell Keith-Magee
On Mon, Aug 23, 2010 at 7:53 PM, Steve Holden wrote: > On 8/23/2010 7:48 AM, Russell Keith-Magee wrote: >> On Mon, Aug 23, 2010 at 7:32 PM, Andy wrote: > [...] >>> Also how random is random - would I get a uniform distribution of >>> records among

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-23 Thread Steve Holden
On 8/23/2010 7:48 AM, Russell Keith-Magee wrote: > On Mon, Aug 23, 2010 at 7:32 PM, Andy wrote: [...] >> Also how random is random - would I get a uniform distribution of >> records among the shards? > > Depending on your level of mathematical rigor, that's not a simple

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-23 Thread Russell Keith-Magee
On Mon, Aug 23, 2010 at 7:32 PM, Andy wrote: > On Aug 20, 10:04 pm, Russell Keith-Magee > wrote: > >>Of course, given that you know your sharding scheme, you could use the >>router directly. >> >>Tweet.objects.using(router.db_for_read(Tweet,

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-23 Thread Andy
On Aug 20, 10:04 pm, Russell Keith-Magee wrote: >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) Ah Thanks. This is what I need. > You won't get

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-20 Thread Russell Keith-Magee
On Sat, Aug 21, 2010 at 8:09 AM, Andy 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

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-20 Thread Andy
On Aug 19, 9:03 pm, Russell Keith-Magee wrote: > As for the instance not existing: Consider the following queries: > > MyModel.objects.filter(foo=bar) > > or > > MyModel.objects.update(foo=bar) > > These are read and write queries respectively, but neither has any >

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread Russell Keith-Magee
On Fri, Aug 20, 2010 at 9:57 AM, hcarvalhoalves wrote: > On 19 ago, 22:03, Russell Keith-Magee wrote: >> The instance will exist, but the author_id won't. Unless you are >> manually allocating the primary key, the primary key is allocated by >>

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread hcarvalhoalves
On 19 ago, 22:03, Russell Keith-Magee wrote: > The instance will exist, but the author_id won't. Unless you are > manually allocating the primary key, the primary key is allocated by > the database at the time of object save, which means you won't be able > to determine

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread Russell Keith-Magee
On Fri, Aug 20, 2010 at 6:48 AM, Andy wrote: > > > On Aug 19, 9:28 am, Russell Keith-Magee > wrote: > > >> You've got the right idea, but the implementation you provide probably >> won't be comprehensive enough in practice. The hint is any extra

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread Andy
On Aug 19, 9:28 am, Russell Keith-Magee wrote: > You've got the right idea, but the implementation you provide probably > won't be comprehensive enough in practice. The hint is any extra > information that will help you determine the right database to use; > there's

Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread Russell Keith-Magee
On Thu, Aug 19, 2010 at 7:06 PM, Andy wrote: > I have a model Tweet that I'd like to shard horizontally based on the > tweet author's id. > > class Tweet(models.Model): >    author_id = models.IntegreField() >    text = models.TextField() > > > Let's say I set up 3

How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?

2010-08-19 Thread Andy
I have a model Tweet that I'd like to shard horizontally based on the tweet author's id. class Tweet(models.Model): author_id = models.IntegreField() text = models.TextField() Let's say I set up 3 databases: shard0, shard1, shard2 I'd like to take the tweet author's id, do a modulo 3