From bcf8181107ed4794290c448379d978361088b2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 31 Mar 2026 13:51:29 +0200 Subject: [PATCH] Split indexes for history table to have either id or __id 815a0a887c3e added the index but the id and __id are just included to the index when the pre-filtering could be improved if id was in the index and the window order could be improved if the __id was in the index. --- trytond/trytond/model/modelsql.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 684fd634b9..b406566cf2 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -370,14 +370,22 @@ class ModelSQL(ModelStorage): (history_table.id, Index.Equality())), Index( history_table, + (history_table.id, Index.Equality()), (Coalesce( history_table.write_date, history_table.create_date), Index.Range()), order='DESC', - include=[ - Column(history_table, '__id'), - history_table.id]), + include=[Column(history_table, '__id')]), + Index( + history_table, + (Coalesce( + history_table.write_date, + history_table.create_date), + Index.Range()), + (Column(history_table, '__id'), Index.Range()), + order='DESC', + include=[history_table.id]), }) @classmethod