python - SQLAlchemy MySQL STRAIGHT_JOIN -
my code executes queries fine in sqlalchemy orm layer so:
session().query(model_a).join( (model_b, == somethingelse) ).join( (model_c, == somethingelse) ) # etc ...
but i've come across query taking minutes finish. turns out mysql blame because it's not joining in order ask to. adding straight_join
after select
like:
select straight_join table_a.id table_a inner join table_b ...
fixes problem can't figure out if there's way make sqlalchemy add straight_join
after select
. docs suggest hints can added select()
via with_hint(table_a, "straight_join")
adds text in wrong place causes mysql syntax error. involve stepping outside of orm not ideal.
i've tried using various mysql debugging techniques explain
, analyze table
etc... can't seem find out why mysql choosing wrong path. manually switching around order of joins doesn't seem either i'm in position need straight_join work.
any ideas?
we support directly case of mysql , strange keywords:
session().query(model_a).prefix_with("straight_join").join( (model_b, == somethingelse) ).join( (model_c, == somethingelse) ) # etc ...
Comments
Post a Comment