postgresql - Django select_related with join on multiple fields -


i have complex database in django. makes extensive use of partitioned tables. have had problems before django , partitioned tables far have found satisfactory solutions of problems.

my newest problem concerns foreign key relationship between 2 partitioned tables. have model called event submodel called monitorevent houses additional information type of events. the, question, important fields of models are:

class event(models.model):     id pk, (automatically added)     ts timestamp  class monitorevent(event):     event_ptr_id fk -> event (automatically added)     ts_copy timestamp 

both tables partitioned month using timestamp. timestamp, not part of pk, since django not allow multi-field pks. (i have tried using joined pk fields without success stackoverflow question) therefore need copy of timestamp in subclass allow partitioned table of subclass.

now problem: select events , monitorevents executing:

event.objects.all().select_related('monitorevent') 

(i would, of course, add filters not select available events.) understanding result in sql query like:

select * event left join monitorevent on event.id = monitorevent.event_ptr_id; 

which should join event table partitions monitorevent table partitions. want like:

select * event left join monitorevent on event.id = monitorevent.event_ptr_id , event.ts = monitorevent ts_copy; 

which should allow query planner make use of partition scheme speed query.

is there possibility in django write custom manager modifies default select_related include additional field in on condition of query?

another possibility me write custom raw query select_related manually, according question django select related in raw request not seem possible except manual proposition made in question.

of course add additional fields original event model , delete submodel eliminate problem altogether, least favorite solution.

i using django 1.5 in combination postgres db.

thank suggestions.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -