跳至內容
選單
此問題已被標幟
2 回覆
4557 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
1月 25
1026
0
6月 20
2717
2
8月 23
10510
0
7月 25
752
1
7月 25
614