Skip to content

Performances: stockage d'un nom normalisé pour les villes & communes pour permettre l'utilisation de l'index#5599

Merged
xavfernandez merged 5 commits into
masterfrom
xfernandez/immutable_unaccent_and_faster_autocomplete
Feb 13, 2025
Merged

Performances: stockage d'un nom normalisé pour les villes & communes pour permettre l'utilisation de l'index#5599
xavfernandez merged 5 commits into
masterfrom
xfernandez/immutable_unaccent_and_faster_autocomplete

Conversation

@xavfernandez

Copy link
Copy Markdown
Contributor

🤔 Pourquoi ?

Indiquez le problème que nous sommes en train de résoudre et les objectifs métiers ou techniques qui sont visés par ces changements.

🍰 Comment ?

Décrivez en quelques mots la solution retenue et mise en oeuvre, les difficultés ou problèmes rencontrés. Attirez l'attention sur les décisions d'architecture ou de conception importantes.

🚨 À vérifier

  • Mettre à jour le CHANGELOG_breaking_changes.md ?
  • Ajouter l'étiquette « Bug » ?

🏝️ Comment tester ?

Les instructions pour reproduire le problème, les profils de test, le parcours spécifique à utiliser, etc. Si vous disposez d'une recette jetable, mettre l'URL pour tester dans cette partie.

💻 Captures d'écran

@xavfernandez xavfernandez added performance Amélioration des perfs tech labels Feb 12, 2025
@xavfernandez xavfernandez self-assigned this Feb 12, 2025
@xavfernandez xavfernandez added the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 12, 2025
@github-actions

Copy link
Copy Markdown

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@rsebille rsebille left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je pense que tu peux fusionner le commit "add normalized_name field to improve autocomplete" avec son pendant "move trigram index to normalized_name field"

Comment thread itou/cities/migrations/0002_slyly_immutable_unaccent.py
Comment thread itou/cities/models.py Outdated
Comment thread itou/cities/models.py Outdated
# https://docs.djangoproject.com/en/dev/ref/contrib/postgres/indexes/#ginindex
# https://www.postgresql.org/docs/11/pgtrgm.html#id-1.11.7.40.7
GinIndex(fields=["name"], name="cities_city_name_gin_trgm", opclasses=["gin_trgm_ops"])
GinIndex(fields=["normalized_name"], name="cities_city_norm_name_gin_trgm", opclasses=["gin_trgm_ops"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soyons urbains 😁, surtout qu'on le fait à 2 endroits.

Suggested change
GinIndex(fields=["normalized_name"], name="cities_city_norm_name_gin_trgm", opclasses=["gin_trgm_ops"])
GinIndex(fields=["normalized_name"], name="%(class)s_normalized_name_gin_trgm", opclasses=["gin_trgm_ops"])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le soucis c'est que le nom des index est limité à 30 caractères :-/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, alors en virant le suffixe gin_trgm ? Je trouve que c'est le moins utile car normalement tu retrouves plus ou moins l'information dans PG ou alors c'est dans le code, mais quand tu regardes un EXPLAIN ça aide d'avoir un nom explicite des champs concernés.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, j'ai tronqué les suffix pour que ça rentre :)
Le plus triste c'est que cette limite de 30 vient d'Oracle 😒
Et que Postgresql gère par défaut jusqu'à 63 caractères: https://www.postgresql.org/docs/15/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
Je serais presque tenté d'aller adapter Index.max_name_length 👀

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

au bucher oracle

@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch 2 times, most recently from 4e01f2f to 340e5f7 Compare February 12, 2025 10:15
@xavfernandez xavfernandez removed the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 12, 2025
@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch from 340e5f7 to 0f68da6 Compare February 12, 2025 10:57
@xavfernandez xavfernandez added the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 12, 2025
@github-actions

Copy link
Copy Markdown

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch from 0f68da6 to 7127e82 Compare February 12, 2025 13:59
@xavfernandez xavfernandez removed the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 12, 2025
@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch 3 times, most recently from 8233df6 to 160f940 Compare February 12, 2025 14:56
@xavfernandez xavfernandez added the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 12, 2025
@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch from 160f940 to 9f938a4 Compare February 12, 2025 15:08
@github-actions

Copy link
Copy Markdown

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@francoisfreitag francoisfreitag left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top, hâte que ce soit en prod pour que l’app passe moins de temps à chercher des villes 🕵️

Le commit d2dd939 mériterait vraiment une description plus approfondie. On déclare immutable une fonction qui ne l’est pas. Pourquoi ?

Comment thread itou/utils/migrations/0002_slyly_immutable_unaccent.py Outdated

@rsebille rsebille left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐎

@xavfernandez xavfernandez removed the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 13, 2025
Like the unaccent function, it is not immutable.

But it is (slyly) declared as such to Posgresql to
enable its use in indices & generated fields.
with a GIN trigram index on it.

Also, drop the unused GIN trigram index on name field
and its GIN trigram index.
Also drop the unused GIN trigram index on name field
@xavfernandez xavfernandez force-pushed the xfernandez/immutable_unaccent_and_faster_autocomplete branch from 9f938a4 to e534b14 Compare February 13, 2025 13:10
@xavfernandez xavfernandez added the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Feb 13, 2025
@github-actions

Copy link
Copy Markdown

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@xavfernandez xavfernandez added this pull request to the merge queue Feb 13, 2025
Merged via the queue into master with commit fd1aa29 Feb 13, 2025
@xavfernandez xavfernandez deleted the xfernandez/immutable_unaccent_and_faster_autocomplete branch February 13, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC performance Amélioration des perfs tech

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants