💻
Albert's Til
GitHub
  • 매일매일 조금씩 성장하기
    • README
    • CS
      • Network
      • HTTP
        • NO-CACHE
      • 오류 코드
      • ORM 도구
      • Design Pattern
        • CQRS Pattern
          • Event Sourcing and CQRS pattern
        • Builder Pattern
    • DB
      • MySQL
        • Timeline
        • Pagination
        • Index
        • Database Performance Optimization Strategies
        • B+ tree
        • MySQL Connectors VS MySQL Shell(Scripting) VS MySQL Workbench
        • MySQL Storage Engine Architecture
      • Normalization & Denormalization
      • JPA
        • @Transactional
        • Why JPA?
        • About JPA
        • N+1 Issue
        • Index
        • ElementCollection&CollectionTable
        • orphanRemoval
        • CascadeType
        • Use Subselect
        • Dynamic Instance Creation
        • Paging
        • Order
        • Spefication
        • mappedBy
      • MongoDB
        • ObjectId
      • Why MySQL?
      • ACID properties of transactions
      • Between JPA and JDBC
      • Identifiers in Hibernate/JPA
    • Java
      • Jackson de/serialize
      • Collections.singletonList() vs List.of()
      • Manage dependencies in Gradle
      • Logging Level
      • Bean Validation
      • JVM Internals
        • Threads
          • Frame
        • Shared Between Threads
          • Classloader
            • Class Loader Hierarchy
            • Loading Linking Initialization
      • Java Collection Framework
      • Annotation
      • Generic
      • 디미터 법칙
    • Spring
      • Caching
      • Spring Integration Overview
        • ThreadPollTaskExecutor
        • Messaging Bridge
        • Channel Adapter
        • Poller
        • Configuration and @EnableIntegration
        • Message Endpoints
        • Message Channels
      • HATEOAS
      • @Autowired vs Constructor Dependency Injection
      • Spring Security
        • JWT 토큰 사용한 인가
        • OAuth 2 Login
        • OAuth 2 인증
        • 인가
        • 인증
        • PasswordEncoder
      • IoC Container
      • Filter,Interceptor,AOP,Argument Resolver
      • Spring Annotation
      • About Spring
    • Kafka
      • Error Channel
    • Infra
      • Scale Up || Scale Out
      • Docker
        • Dockerfile
        • Docker Hub Deploy
        • Command
      • Cloud 유형
        • Infrastructure as a Service
        • Platform as a Service
        • Software as a Service
      • 무중단 배포
        • 엔진엑스(Nginx)
      • 코드 자동 배포
        • Technical
      • AWS EC2
        • PEM(Privacy Enhanced Mail) 키
      • AWS RDS
      • AWS S3
    • CodeSquad
      • Spring Boot Project 1주차 회고
      • Spring Boot Project 2주차 회고
      • Spirng Boot Project 3주차 회고
      • Spring Boot Project 4주차 회고
    • Foody Moody 프로젝트
      • Query Performance Comparison
      • HeartCount Asynchronous Issue
      • DeferredResult
      • ResponseBodyEmitter
      • SseEmitter (Spring)
      • Server-Sent Events (SSE)
      • 기술 스택 적용 이유
      • NO-CACHE(HTTP)
      • Transactional
    • DDD
      • AggregateId
    • Test
      • RestAssured
    • Coding and Algorithmic Problems
      • 819. Most Common Word
      • 344. Reverse String
      • 125. Valid Palindrome
      • 937. Reorder Data in Log Files
    • Node
      • Async... Await...
      • Custom Transactional Decorator Challenger
    • Python
      • Python Basic Grammar
        • Comments and Input/Output
        • Variable
        • Data type
        • Operations and syntax
        • List,Tuple,Dictionary,Set
        • Function
        • Conditional statement
        • Loop
    • HTML
      • HTML Basic
      • HTML Basic Tags
      • HTML Form Tags
      • HTML Table Tags
    • CSS
      • CSS Basic
      • CSS Practice
Powered by GitBook
On this page
  • 사용 예시
  • 인덱스 이름
  • 컬럼 리스트
  • 유니크 인덱스
  • 인덱스 컬럼 길이
  • 인덱스 위치
  • 테이블 수준 인덱스

Was this helpful?

  1. 매일매일 조금씩 성장하기
  2. DB
  3. JPA

Index

데이터베이스에서의 인덱스 설정

인덱스는 데이터베이스에서 데이터를 빠르게 검색하기 위해 사용되는 구조입니다. @Index를 사용하여 특정 컬럼 또는 컬럼 그룹에 인덱스를 생성하고 관리할 수 있습니다.

@Index를 사용하여 인덱스를 정의하면 데이터베이스에서 데이터를 효율적으로 검색할 수 있습니다. 이를 통해 쿼리의 성능을 향상시킬 수 있습니다. 주의할 점은 @Index는 JPA의 스키마 생성 기능에 의해 DDL문을 생성할 때만 영향을 준다는 점입니다. 따라서 특정 데이터베이스에서는 스키마 생성 시점에서 인덱스가 생성되지 않을 수도 있으므로, 인덱스를 명시적으로 생성해야 할 수도 있습니다.

사용 예시

@Entity
@Table(name = "users")
@Index(name = "idx_username", columnList = "username")
public class UserEntity {
    // ...
    @Column(name = "username")
    private String username;
    // ...
}

위의 예시에서 @Index 어노테이션은 UserEntity의 username 컬럼에 인덱스를 생성하는 데 사용됩니다. name 속성은 인덱스의 이름을 지정하고, columnList 속성은 인덱스를 생성할 컬럼 이름을 지정합니다

인덱스 이름

@Index의 name 속성을 사용하여 인덱스의 이름을 지정할 수 있습니다. 기본적으로는 자동으로 생성되는 이름이 사용됩니다.

컬럼 리스트

@Index의 columnList 속성을 사용하여 인덱스를 생성할 컬럼의 이름 또는 컬럼 그룹을 지정할 수 있습니다. 컬럼 이름은 쉼표로 구분하여 여러 개를 지정할 수 있습니다.

유니크 인덱스

@Index의 unique 속성을 사용하여 유니크 인덱스를 생성할 수 있습니다. unique를 true로 설정하면 중복된 값이 허용되지 않는 유니크 인덱스가 생성됩니다.

인덱스 컬럼 길이

@Index의 columnList 속성 내에서 특정 컬럼의 길이를 지정할 수 있습니다. 예를 들어, columnList = "username(30)"과 같이 사용하여 username 컬럼의 길이를 30으로 제한할 수 있습니다.

인덱스 위치

@Index의 columnList 속성 내에서 컬럼의 위치를 지정할 수 있습니다. 예를 들어, columnList = "2, 1"과 같이 사용하여 두 개의 컬럼의 순서를 지정할 수 있습니다.

테이블 수준 인덱스

@Index를 엔티티 클래스 위에 선언하면 해당 테이블 전체에 대한 인덱스를 생성할 수 있습니다.

Last updated 1 year ago

Was this helpful?