コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
4422 ビュー

When should I use SQL Query or ORM Search Method to get better performance?
For instance:
Should I use this

query = """
        select distinct license_plate_number from car_car
        where state not in ('cancel', 'sold')
        and license_plate_number = '{}';
        """.format(license_plate_number)
self.env.cr.execute(query)
cars = self.env.cr.dictfetchall()
or this:
cars = self.search([
    ('license_plate_number', '=', self.license_plate_number),
    ('state', 'not in', ('cancel', 'sold'))
])


アバター
破棄
最善の回答

Hi,

Query is much faster than ORM. And when we use query we should take care as it bypass the orm layers, the security(rules and access rights) wont be considered. If it is small operation, go with orm layer, and for reporting and all use query.

Thanks & Regards

アバター
破棄
最善の回答

If you want to improve performance this might help you 

https://www.odoo.com/event/odoo-experience-2021-2847/track/performance-issues-here-are-the-best-solutions-4404 

アバター
破棄
関連投稿 返信 ビュー 活動
1
1月 25
933
0
6月 20
2629
2
8月 23
10419
1
7月 25
160
0
2月 25
1096