Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
4420 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
tammik. 25
931
0
kesäk. 20
2628
2
elok. 23
10418
1
heinäk. 25
154
0
helmik. 25
1095