What's the correct annotation to index by the fields below? Please point out what I'm doing wrong.
I'd prefer to use JPA annotations instead of the hibernate @Index annotation I'm playing with. Also, why do all the last 3 entries of my "show keys" output refer to "GROUPID
Thanks
Code:
mysql> describe metrics;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| DOCS | int(11) | YES | | NULL | |
| GROUPID | bigint(20) | YES | MUL | NULL | |===========> need to index by this column
| GROUPTYPE | char(1) | YES | | NULL | |===========> need to index by this column
| PAGES | int(11) | YES | | NULL | |
| SIZE | int(11) | YES | | NULL | |
| TYPE | varchar(255) | YES | | NULL | |===========> need to index by this column
+-----------+--------------+------+-----+---------+----------------+
Code:
mysql> show keys from metrics;
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| metrics | 0 | PRIMARY | 1 | ID | A | 0 | NULL | NULL | | BTREE | |
| metrics | 0 | GROUPID | 1 | GROUPID | A | 0 | NULL | NULL | YES | BTREE | |=======> refer to GROUPID
| metrics | 0 | GROUPID | 2 | GROUPTYPE | A | 0 | NULL | NULL | YES | BTREE | |=======> refer to GROUPID
| metrics | 0 | GROUPID | 3 | TYPE | A | 0 | NULL | NULL | YES | BTREE | |=======> refer to GROUPID
Code:
@Entity
@Table(name = "METRICS", uniqueConstraints = { @UniqueConstraint(columnNames = { "GROUPID", "GROUPTYPE", "TYPE" }) })
public class Metrics implements Serializable, IFieldsAccessibleAsString {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Index(name = "GROUPID")
@IndexColumn(name = "GROUPID")
@Column(name = "GROUPID")
private long groupId;
@Index(name = "GROUPTYPE")
@IndexColumn(name = "GROUPTYPE")
@Column(name = "GROUPTYPE")
private char groupType;
@Index(name = "TYPE")
@IndexColumn(name = "TYPE")
@Column(name = "TYPE")
private String type;
@Column(name = "DOCS")
private int docs;
@Column(name = "PAGES")
private int pages;
@Column(name = "SIZE")
private int size;
}