[1.7.x] Factorized create_index_sql expression

Backport of 6072f17d0 from master, with one test reinforced.