top of page
  • Writer's pictureTek Siong, Hock

Odoo ORM or SQL Query?

By John Julius Danker

This blog is a Comparison between of ORM Vs SQL Query on your Odoo performance.

Direct SQL Queries

What are SQL Queries?

Structured Query Language (SQL) is a programming language used for managing and manipulating databases. SQL queries allow you to interact directly with your database to retrieve or modify data.

Odoo ORM

What is Odoo ORM?

ORM acts as an intermediary layer between the application code and the database. It abstracts database interactions by representing database tables as Python classes and records as instances of those classes.

Experiment Code and Result

import cProfile

from odoo import models, fields, api

from odoo.http import request

def direct_sql_query():

query = "SELECT * FROM res_company"

result =

def odoo_orm_operation():

partners = self.env['].search([])

records = http.request.env[partners]

if __name__ == "__main__":

profiler = cProfile.Profile()

# Profiling the direct SQL query




print("Direct SQL Query Profiling Results:")


# Profiling the Odoo ORM operation




print("Odoo ORM Operation Profiling Results:")


Odoo SQL

414 function calls in 0.002 seconds

Odoo ORM

793884 function calls (713081 primitive calls) in 0.908 seconds

Use Cases


Use Cases


Integrate with third party to extract large amount of data

Granular Control to join multiple tables and conditions.

Backend logic to update fields

1 class or table at a time

Retrieving large amount of data

High performance

Retrieving large amount of data

Performance Overhead

87 views0 comments

Recent Posts

See All


bottom of page