Hibernate automatically creates an index?

I have a Term table with just over 5 million rows. Each line consists of an identifier and a name. A search with the name field takes almost 35 seconds.

MariaDB [WordDS]> select * from Term where name="Google";
+---------+--------+
| id      | name   |
+---------+--------+
| 1092923 | Google |
+---------+--------+
1 row in set (35.35 sec)

script from the table generated by Hibernate:

DROP TABLE IF EXISTS `Term`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Term` (
  `id` bigint(20) NOT NULL,
  `name` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

Java Annotations:

@Id
@Column(unique=true)
private long id;

@NotNull
@Size(min = 1, max = 100)
private String name;

So slowly search in the "name" field, so I think there is no index. Does Hibernate automatically create an index for the id and name in this table? If not, how to allow creating an index for both?

+4
source share
2 answers

Use annotation @Index:

@Entity
@Table(name = "Term", indexes = {
    @Index(columnList = "name, id", name = "name_idx") })

Hibernate will automatically create an index when creating a table at startup.

+2
source

name, @Index:

@NotNull
@Size(min = 1, max = 100)
@Index(name = "idx_name")
private String name;
0

All Articles