How to create indexes on multiple columns

后端 未结 3 1473
孤街浪徒
孤街浪徒 2021-01-20 16:55

We have the following entity relationships where a User belongs to a particular Organization. My queries either look like \"select * from User where org=:org\" or \"select *

3条回答
  •  心在旅途
    2021-01-20 17:41

    As you can read in JSR-000338 Java Persistence 2.1 Proposed Final Draft Specification:

    11.1.23 Index Annotation

    The Index annotation is used in schema generation. Note that it is not necessary to specify an index for a primary key, as the primary key index will be created automatically, however, the Index annotation may be used to specify the ordering of the columns in the index for the primary key.

    @Target({}) @Retention(RUNTIME)
    public @interface Index {
      String name() default "";
      String columnList();
      boolean unique() default false;
    }
    

    The syntax of the columnList element is a column_list, as follows:

    column::= index_column [,index_column]*
    index_column::= column_name [ASC | DESC]
    

    The persistence provider must observe the specified ordering of the columns.

    If ASC or DESC is not specified, ASC (ascending order) is assumed.

    Usage example:

    @Table(indexes = {
            @Index(columnList = "org,type"),
            @Index(columnList = "another_column")})
    

提交回复
热议问题