Skip to content

[IMP] partner_internal_code: trigram index on internal_code behind a feature flag - #160

Closed
maq-adhoc wants to merge 1 commit into
ingadhoc:18.0from
adhoc-dev:18.0-t-79487-maq
Closed

maq-adhoc wants to merge 1 commit into
ingadhoc:18.0from
adhoc-dev:18.0-t-79487-maq

Conversation

@maq-adhoc

Copy link
Copy Markdown

Tarea: https://www.adhoc.inc/odoo/project.task/79487

Qué cambia

Complemento de ingadhoc/miscellaneous#505 (base_ux). Cuando internal_code está en los campos de búsqueda de base_name_search_improved, cada pasada del módulo hace unaccent(internal_code) ILIKE '%texto%', y el campo solo tiene btree: recorre la tabla entera.

partner_internal_code crea desde init() un índice gin de trigramas en internal_code (res_partner__internal_code_trgm_index), con el mismo patrón que base_ux:

  • Nombre propio, al lado del btree del campo. Declarar index="trigram" haría que el registry borre el btree y lo recree como gin sin CONCURRENTLY; el btree sirve el = y el control de unicidad.
  • Mismo flag: solo se crea con saas_feature.partner_search_trigram_index prendido, en el próximo -u del módulo.
  • Sin pg_trgm o con unaccent no IMMUTABLE no se crea nada (log en info).

Medición

Copia de una base 18.0 con 272k contactos y internal_code como campo de búsqueda, con los índices de base_ux ya creados. name_search(limit=8):

Término Sin índice en internal_code Con índice
sin resultados 908 a 928 ms (4 consultas de ~215 ms en internal_code) 9 a 16 ms
dos palabras 239 ms 13 ms

Crear el índice: 2,4 s, 5,8 MB.

…feature flag

- Create a gin trigram index on unaccent(internal_code) from init(), so
  ILIKE '%term%' on the field stops scanning the whole table (it is one of
  the smart search fields of base_name_search_improved)
- Use an own index name next to the btree of the field: declaring
  index="trigram" would make the registry drop the btree and rebuild it as
  gin without CONCURRENTLY, and the btree serves "=" and the unique check
- Only create it when the system parameter
  saas_feature.partner_search_trigram_index is on, the same flag as the
  base_ux partner search indexes; it is built on the next -u of the module
- Skip creation when pg_trgm is missing or unaccent is not IMMUTABLE
- Bump version to 18.0.1.1.0

Change note: Búsqueda de contactos por código interno más rápida en bases con muchos contactos (se habilita por base)
@roboadhoc

Copy link
Copy Markdown

Pull request status dashboard

@maq-adhoc
maq-adhoc requested a review from az-adhoc November 11, 2026 12:34
@az-adhoc

Copy link
Copy Markdown
Contributor

Revisé el PR contra 18.0. La expresión del índice coincide con la que arma el ORM para el ILIKE. Tengo dos observaciones, las mismas que en ingadhoc/miscellaneous#505:

  1. Un error al crear el índice hace fallar todo el -u. El registry crea sus índices dentro de cr.savepoint(flush=False) con try y deja un log si falla. Acá create_index se llama sin ninguno de los dos. Propongo hacer lo mismo que el registry.
  2. Bump de versión del manifest. Por lo que tenemos acordado, la versión la sube roboadhoc, y para actualizar alcanza con -u. ¿Hace falta el bump acá?

@az-adhoc

Copy link
Copy Markdown
Contributor

@roboadhoc r+ nobump

roboadhoc pushed a commit that referenced this pull request Nov 11, 2026
…feature flag

- Create a gin trigram index on unaccent(internal_code) from init(), so
  ILIKE '%term%' on the field stops scanning the whole table (it is one of
  the smart search fields of base_name_search_improved)
- Use an own index name next to the btree of the field: declaring
  index="trigram" would make the registry drop the btree and rebuild it as
  gin without CONCURRENTLY, and the btree serves "=" and the unique check
- Only create it when the system parameter
  saas_feature.partner_search_trigram_index is on, the same flag as the
  base_ux partner search indexes; it is built on the next -u of the module
- Skip creation when pg_trgm is missing or unaccent is not IMMUTABLE
- Bump version to 18.0.1.1.0

Change note: Búsqueda de contactos por código interno más rápida en bases con muchos contactos (se habilita por base)

closes #160

Related: ingadhoc/miscellaneous#505
Signed-off-by: Andrés Zacchino <[email protected]>
roboadhoc pushed a commit to ingadhoc/miscellaneous that referenced this pull request Nov 11, 2026
- Create gin trigram indexes on unaccent(name), complete_name, email, ref
  and vat of res.partner from init(), so ILIKE '%term%' in name_search
  stops scanning the whole table
- Use own index names next to the core btree indexes: declaring
  index="trigram" on the fields would make the registry drop the btree
  and rebuild it as gin without CONCURRENTLY, and the btree serves "="
- Only create them when the system parameter
  saas_feature.partner_search_trigram_index is on, so the rollout goes
  database by database; the indexes are built on the next -u of the module
- Skip creation when pg_trgm is missing or unaccent is not IMMUTABLE
- Bump version to 18.0.4.1.0

Change note: Búsqueda de contactos más rápida en bases con muchos contactos (se habilita por base)

closes #505

Related: ingadhoc/partner#160
Signed-off-by: Andrés Zacchino <[email protected]>
@roboadhoc roboadhoc closed this Nov 11, 2026
@roboadhoc
roboadhoc deleted the 18.0-t-79487-maq branch November 11, 2026 19:32

This branch was successfully deployed

1 active deployment
merge — 1df1d9c1 Deployed Nov 11, 2026 by roboadhoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants