Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
4553 Prikazi

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'))
])


Avatar
Opusti
Best Answer

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

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jan. 25
1026
0
jun. 20
2717
2
avg. 23
10510
0
jul. 25
735
1
jul. 25
601