diff --git a/issue12480.diff b/issue12480.diff new file mode 100644 index 0000000..6e764de --- /dev/null +++ b/issue12480.diff @@ -0,0 +1,53 @@ +diff --git a/tryton/trytond/trytond/backend/postgresql/table.py b/tryton/trytond/trytond/backend/postgresql/table.py +index e874ee61c0..44ff97ce9b 100644 +--- a/tryton/trytond/trytond/backend/postgresql/table.py ++++ b/tryton/trytond/trytond/backend/postgresql/table.py +@@ -647,23 +647,42 @@ class TrigramTranslator(IndexMixin, IndexTranslatorInterface): + + @classmethod + def score(cls, index): +- has_trigram = Transaction().database.has_extension('pg_trgm') +- if not has_trigram: ++ database = Transaction().database ++ has_btree_gin = database.has_extension('btree_gin') ++ has_trigram = database.has_extension('pg_trgm') ++ if not has_btree_gin and not has_trigram: + return 0 + + score = 0 + for _, usage in index.expressions: + if usage.__class__.__name__ == 'Similarity': +- score += 100 ++ if has_trigram: ++ score += 100 ++ else: ++ score += 50 ++ elif has_btree_gin: ++ if usage.__class__.__name__ == 'Range': ++ score += 90 ++ elif usage.__class__.__name__ == 'Equality': ++ score += 40 + else: + return 0 + return score + + @classmethod + def _get_indexed_expressions(cls, index): +- return [ +- (e, u) for e, u in index.expressions +- if u.__class__.__name__ == 'Similarity'] ++ database = Transaction().database ++ has_btree_gin = database.has_extension('btree_gin') ++ has_trigram = database.has_extension('pg_trgm') ++ ++ def filter(usage): ++ if usage.__class__.__name__ == 'Similarity': ++ return has_trigram ++ elif usage.__class__.__name__ in {'Range', 'Equality'}: ++ return has_btree_gin ++ else: ++ return False ++ return [(e, u) for e, u in index.expressions if filter(u)] + + @classmethod + def _get_expression_variables(cls, expression, usage): diff --git a/series b/series index ccdda05..ba0e4fd 100644 --- a/series +++ b/series @@ -47,3 +47,5 @@ issue12414.diff # [stock_lot_sled] Check expiration lot in case Shelf Life Time merge_request581.diff # [account] Post cancelled, grouped, rescheduled and delegated moves issue12216.diff # [stock] Handle evaluation error of cost price in cost price revision + +issue12480.diff # [trytond] Support GIN index with btree_gin PostgreSQL extension