details:   https://code.tryton.org/tryton/commit/e131346274c3
branch:    default
user:      Cédric Krier <[email protected]>
date:      Tue Mar 31 12:02:51 2026 +0200
description:
        Add index for target column of xxx2Many field on history table

        Closes #14725
diffstat:

 trytond/trytond/model/modelsql.py |  23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diffs (46 lines):

diff -r 85902c3ab347 -r e131346274c3 trytond/trytond/model/modelsql.py
--- a/trytond/trytond/model/modelsql.py Sat Apr 04 00:52:12 2026 +0200
+++ b/trytond/trytond/model/modelsql.py Tue Mar 31 12:02:51 2026 +0200
@@ -408,6 +408,9 @@
                     continue
                 table = cls.__table__()
                 column = Column(table, field_name)
+                if cls._history:
+                    history_table = cls.__table_history__()
+                    history_column = Column(history_table, field_name)
                 if not field.required and cls != Target:
                     where = column != Null
                 else:
@@ -424,12 +427,32 @@
                                 (field.sql_id(column, Target), Index.Range()),
                                 where=where),
                             })
+                    if cls._history:
+                        cls._history_sql_indexes.update({
+                                Index(
+                                    history_table,
+                                    (history_column, Index.Equality()),
+                                    where=where),
+                                Index(
+                                    history_table,
+                                    (history_column,
+                                        Index.Similarity(begin=True)),
+                                    (field.sql_id(history_column, Target),
+                                        Index.Range()),
+                                    where=history_column != Null),
+                                })
                 else:
                     cls._sql_indexes.add(
                         Index(
                             table,
                             (column, Index.Range()),
                             where=where))
+                    if cls._history:
+                        cls._history_sql_indexes.add(
+                            Index(
+                                history_table,
+                                (history_column, Index.Range()),
+                                where=history_column != Null))
                     break
 
     @classmethod

Reply via email to