python - How to pass oracle optimization hint in django query -
i using oracle 11g , have need pass oracle hint in django query.
sql need execute in django this:
select /*+ ordered use_nl(cd) */ * table1 d inner bring together table2 cd on cd.id=d.id;
i don't want perform django raw sql query, somehow integrate in normal django orm query - i.e. in this:
table1.objects.all()
edit: it seems kind of solution needs more testing since oracle reference optimizer hints says: oracle ignores hints if comment containing them not follow delete, select, or update keyword. (thanks @swstephe noting out). in solution first bracket , because of optimizer won't process hint @ all.
if needed can check first aliases django uses when creating sql:
qs = table1.objects.all()
check query with:
>>> print qs.query # or qs.query.sql_with_params() select "table1"."id",... "table1"
and can add together "extra" dummy column using django queryset method column definition containing hint:
>>> qs = qs.extra(select={"dummy1" : '/*+ ordered use_nl("table1") */ 1 '}).all()
if check of query - looks this:
>>> print qs.query select (/*+ ordered use_nl("table1") */ 1) "dummy1", "table1"."id", ... "table1"
additional useful reference:
django database access optimization python django oracle
No comments:
Post a Comment