How to add a prefix-length index in postgresql? -
As we know, there are prefix length columns that can be added during index creation. For example in mysql,
change the table j1 index idx_j1_str1 (str1 (5)); After searching for google.com and stackoverflow.com, I did not find any equivalent solution in postgresql.
Then someone can give me the answer except the function
< Code> index id on J1 idx_j1_str (left (str1,5)); But I do not think you want something like this in postgres. An index on just str1 is probably more versatile, but of course it relies heavily on the questions you run - which you have not shown to us, so it is impossible to say how you Need an index. To use the function based index in Postgres and basically supports any other DBMS) It is necessary to include the same expression in your query as you use in the index:
select = from j1 where left (str1,5) = '1234' / code> will use the above index (if this is understood, for example if The table is large and the overall results in the situation are substantially reduced).
If you make regular index on that column:
build index idx_j1_str at J1 (str1 varchar_pattern_ops); Then it can be used for some:
select from j1 * where str1 like '1234%' (which is equivalent to left (str1,5) = '1234' ) but also can be used for: * Choose from 1 to j1 where str1 like '1234678%' or any other prefix search using wildcard.
Comments
Post a Comment