SELECT

개요

SELECT 문법

SELECT

WITH

FROM

USE

목적

전제 조건

문법

use-clause ::= use-keys-clause | use-index-clause

USE KEYS

목적

문법

use-keys-clause ::= USE use-keys-term
use-keys-term ::= [ PRIMARY ] KEYS expr

인자

expr

예제1

Query
SELECT *
FROM `travel-sample`
USE KEYS "airport_1254";
Result
[
  {
    "travel-sample": {
      "airportname": "Calais Dunkerque",
      "city": "Calais",
      "country": "France",
      "faa": "CQF",
      "geo": {
        "alt": 12,
        "lat": 50.962097,
        "lon": 1.954764
      },
      "icao": "LFAC",
      "id": 1254,
      "type": "airport",
      "tz": "Europe/Paris"
    }
  }
]

예제2

Query
SELECT *
FROM `travel-sample`
USE KEYS ["airport_1254","airport_1255"];
Result
[
  {
    "travel-sample": {
      "airportname": "Calais Dunkerque",
      "city": "Calais",
      "country": "France",
      "faa": "CQF",
      "geo": {
        "alt": 12,
        "lat": 50.962097,
        "lon": 1.954764
      },
      "icao": "LFAC",
      "id": 1254,
      "type": "airport",
      "tz": "Europe/Paris"
    }
  },
  {
    "travel-sample": {
      "airportname": "Peronne St Quentin",
      "city": "Peronne",
      "country": "France",
      "faa": null,
      "geo": {
        "alt": 295,
        "lat": 49.868547,
        "lon": 3.029578
      },
      "icao": "LFAG",
      "id": 1255,
      "type": "airport",
      "tz": "Europe/Paris"
    }
  }
]

USE INDEX

목적

문법

use-index-clause ::= USE use-index-term
use-index-term ::= INDEX '(' index-ref [ ',' index-ref ]* ')'
index-ref ::= [ index-name ] [ index-type ]
index-type ::= USING ( GSI | FTS )
USE INDEX ([ index-name ] USING ( GSI | FTS ))

인자

index-name

예제1

Query with GSI
-- airlines와 destination airports의 인덱스 생성
CREATE INDEX idx_destinations
ON `travel-sample` (airlineid, airline, destinationairport)
WHERE type="route";
-- SFO(San Francisco)에서 온 비행기 조회하는 쿼리
SELECT
    airlineid,
    airline,
    sourceairport,
    destinationairport
FROM `travel-sample`
    USE INDEX (idx_destinations USING GSI)
WHERE sourceairport = "SFO";

예제2

Query with FTS
SELECT META().id
FROM `travel-sample` USE INDEX (USING FTS)
WHERE type = "hotel" AND (state = "Corse" OR state = "California");

JOIN

NEST

UNNEST

LET

WHERE

GROUP BY

UNION, INTERSECT, EXCEPT

ORDER BY

LIMIT

OFFSET