samedi 4 novembre 2017

Sort customers by name according to country/language specific collation rules in a MySQL database

We have customers from different countries using our Grails web application in their own native language (Swedish, Norwegian, Polish, German, Spanish etc) and they save data that is local to them. An example is a Customer-table having columns for first name and last name that need to be sorted as expected in the local language. This means that:
• A Swedish customer wants to sort the list of customer according to collation utf8mb4_swedish_ci which will sort a/o/å/ä/ö as expected. Örjan will be sorted last and not in the same place as Olof.
• A German customer wants to sort the list of customer according to collation utf8mb4_german2_ci which will sort ß/ss/u/ü as expected. • Similar cases for other languages like Norwegian, Polish etc.

All our columns have the character set utf8mb4 to be able to support the storage of characters from multiple languages.

Previously we used utf8mb4_swedish_ci as our collation for all columns that we could sort on by but because we are getting customers from other countries and languages and moving to an international market we need to implement changes to support customers globally.

We are investigating the following solutions: • Use utf8mb4_unicode_ci as collation in the database but add a collate expression like “order by firstname collate utf8mb4_swedish_ci” on all our queries depending on what language/location is used in the application. • Use multiple columns in the database that has the target collation like “firstname_swedish”(utf8mb4_swedish_ci), “firstname_german” (utf8mb4_german2) or reference a specific table with different columns. • Implement sorting in the application layer instead of the database.

Which solutions above would be the best approach regarding performance, implementation time and maintainability?




Aucun commentaire:

Enregistrer un commentaire