SELECT
문법SELECT
절WITH
절FROM
절USE
절USE
절을 사용하여 쿼리가 특정 키 또는 특정 인덱스를 사용하도록 지정할 수 있다FROM
절 내에서 사용된다query_select
권한이 있어야 한다use-clause ::= use-keys-clause | use-index-clause
USE KEYS
절use-keys-clause ::= USE use-keys-term
use-keys-term ::= [ PRIMARY ] KEYS expr
use-keys-clause
는 USE use-keys-term
로 구성USE use-keys-term
는 [ PRIMARY ] KEYS expr
로 구성USE KEYS
오 USE PRIMARY KEYS
는 동의어SELECT *
FROM `travel-sample`
USE KEYS "airport_1254";
[
{
"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"
}
}
]
SELECT *
FROM `travel-sample`
USE KEYS ["airport_1254","airport_1255"];
[
{
"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 )
GSI
FTS
:
USE INDEX ([ index-name ] USING ( GSI | FTS ))
index-name
-- 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";
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
절