Why is django ORM so much slower than raw SQL

前端 未结 1 424
予麋鹿
予麋鹿 2020-12-18 11:04

I have the following two pieces of code:

First, in SQL:

self.cursor.execute(\'SELECT apple_id FROM main_catalog WHERE apple_id=%s\', apple_id)
if sel         


        
相关标签:
1条回答
  • 2020-12-18 11:32

    Typically ORMs go to the trouble of instantiating a complete object for each row and returning it. Your raw SQL doesn't do that, so it won't take the penalty that incurs. For large result sets where you don't intend to use the object, it is better to bypass the ORM.

    0 讨论(0)
提交回复
热议问题