Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
select_related がクエリセットチェーンに入れられる順序は重要ですか?
つまり、以下の間に違いはありますか:
SomeModel.objects.select_related().all()
と
SomeModel.objects.all().select_related()
私の簡単なテストでは、どちらもオブジェクトをキャッシュしているように見えますが、パフォーマンスに違いがあるのか 、それとも私が気づいていない違いがあるのか 疑問に思っていますか?
どちらもまったく同じクエリを実行します。いいえ、パフォーマンスの違いはありません。
テストするには、これを試してください:
q = SomeModel.objects.select_related().all() print q.query q = SomeModel.objects.all().select_related() print q.query
同じ正確なクエリを取得する必要があります