콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6897 화면

Assuming i have 2 models named model_parent and model_child. model_child has a m2o parent_id field referenced to model_parent. Each model has millions of records.

 self.env['model_child'].search([('id', '=', 3), ('parent_id.state', '=', 'done')], limit=1)

 When i execute the search above, odoo searching the parent table with query like that

"select id form model_parent where state = 'search'"

and gathering ids to use in child_model's query. 

"select id form model_child where id = 3 and parent_id in (%s, %s, %s)"

if parent table has millions of records in done state odoo will give millions of ids in second query instead of using id = 3 filter first. If that was a single join query, postgres will handle the search priority by using index but odoo orm not using join queries.

How can i trust dot notation queries in odoo? Is this not a big problem?

아바타
취소
베스트 답변

if your queries not changing by structure but only by parameters you can consider using raw sql queries in your model in order to retrieve the relevant ids which might make your life easier and query time way shorter. additional btree indexes on queried fields might speed things up too.

ORMs won't make life easy all the time. sometimes workaround is needed.


아바타
취소
관련 게시물 답글 화면 활동
2
4월 23
38780
Using search count 해결 완료
2
12월 23
20054
1
1월 25
1153
2
10월 22
4672
2
12월 19
4396