Indexes

인덱스 종류

Primary

Secondary

Full Text

View

Shadow Data Set

[GSI(Global Secondary Index)]

장점

Advanced Scaling

Predictable Performace

Low Latency Querying

Independent Partitioning

가용성과 성능

Index Replication

Index Partitioning

Index Consistency

Index Snapshots

Index Rollback

Indexing

개요

표준 GSI
메모리 최적화 GSI

Primary Index

CREATE PRIMARY INDEX ON `travel-sample`;
사용 경우
Metadata for Primary Index
SELECT * FROM system:indexes WHERE name = '#primary';

Results:
[
  {
    "indexes": {
      "datastore_id": "http://127.0.0.1:8091",  // 인덱스가 존재하는 
      "id": "1b7ac1abf01d9038",
      "index_key": [],
      "is_primary": true,
      "keyspace_id": "travel-sample",
      "name": "#primary",
      "namespace_id": "default",
      "state": "online",                        // 인덱스 상태
      "using": "gsi"                            // 인덱스 메서드
    }
  }
]

Named Primary Index

CREATE PRIMARY INDEX def_primary ON `travel-sample`;

Secondary Index

Key is a Simple Scalar Value
CREATE INDEX travel_name ON `travel-sample`(name);

# Name is a simple scalar value such as:
{
    "name": "Air France"
}
Key is an Object, Embedded Within the Document
CREATE INDEX travel_geo on `travel-sample`(geo);

-- geo is an object, embedded within the document such as:
"geo": {
    "alt": 12,
    "lat": 50.962097,
    "lon": 1.954764
}
Keys from Nested Objects
CREATE INDEX travel_geo on `travel-sample`(geo.alt);

CREATE INDEX travel_geo on `travel-sample`(geo.lat);
Keys is an Array of Objects

CREATE INDEX travel_schedule ON `travel-sample`(schedule);

-- Schedule is an array of objects with flight details.
-- This command indexes the complete array and is useful only if you're looking for the entire array.
-- Example Results:
"schedule": [
        {
            "day": 0,
            "flight": "AF198",
            "utc": "10:13:00"
            },
        {
            "day": 0,
            "flight": "AF547",
            "utc": "19:14:00"
            },
        {
            "day": 0,
            "flight": "AF943",
            "utc": "01:31:00"
            },
        {
            "day": 1,
            "flight": "AF356",
            "utc": "12:40:00"
            },
        {
            "day": 1,
            "flight": "AF480",
            "utc": "08:58:00"
            },
        {
            "day": 1,
            "flight": "AF250",
            "utc": "12:59:00"
            }
    ]

Composite Secondary Index

Functional Index

Array Index

Partial Index

Duplicate Index

Covering Index

Scans

개요

절차

  1. 애플리케이션 및 데이터베이스 드라이버에서 클러스터의 사용 가능한 쿼리 노드 중 하나에 N1QL 쿼리 제출
  2. 쿼리 노드는 쿼리를 분석하고, 최적의 실행 플랜을 찾아내기 위해 오브젝트의 메타데이터를 사용하고, 그 다음에 이를 실행
  3. 실행 동안, 쿼리에 따라, 적용 가능한 인덱스를 사용하여, 쿼리 노드는 해당 인덱스와 데이터 노드와 함께 작동하여 계획된 작업을 검색하고 수행

쿼리 실행 상세 내용

  1. Client REST API 통해 쿼리 제출
SELECT
    t.airportname,
    t.city
FROM `tracvel-sample` t
WHERE
    type = "airport" AND
    tz = "America/Anchorage" AND
    geo.alt >= 2100;
  1. Query Service 파싱, 분석, 계획 생성
  2. Index Service Scan Request; index filter
  3. Index Service 한정된(qualified) 문서 키 가져오기
  4. Data Service Fetch Request, doc keys
  5. Data Service Fetch Documents
  6. Query Service Evaluate: Doucuments to results
  7. Clients Query result(JSON)