Create index with a substring field

4

Is it possible to create an index in mysql but the index field is a substring? For example:

Create NON-UNIQUE INDEX nombreInidice on nombreTabla (SUBSTRING(nombreCampo FROM 1 FOR 4)) USING HASH;
    
asked by Santiago Muñoz 18.11.2016 в 14:45
source

1 answer

5

Starting with MySQL 5.7.6 , you can use a auto generated column to store the sub-string you're interested in and create an index on that column, for example:

CREATE TABLE MiTabla (
      id int
    , MiCampo CHAR(50)
    , MiSubCampo CHAR(10) AS SUBSTRING(MiCampo, 8, 10) STORED
    , INDEX(MiSubCampo)
)
    
answered by 18.11.2016 / 15:36
source