기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Amazon Neptune의 쿼리 계획 캐시
쿼리가 Neptune에 제출되면 쿼리 문자열이 구문 분석, 최적화 및 쿼리 계획으로 변환된 다음 엔진에서 실행됩니다. 애플리케이션은 종종 서로 다른 값으로 인스턴스화되는 일반적인 쿼리 패턴에 의해 지원됩니다. 쿼리 계획 캐시는 쿼리 계획을 캐싱하여 반복되는 패턴에 대한 구문 분석 및 최적화를 방지함으로써 전체 지연 시간을 줄일 수 있습니다.
쿼리 계획 캐시는 파라미터화되지 않았거나 파라미터화된 쿼리인 OpenCypher 쿼리에 사용할 수 있습니다. READ와 HTTP 및 Bolt에 대해 활성화됩니다. OC 변형 쿼리에는 지원되지 않습니다. Gremlin 또는 SPARQL 쿼리에는 지원되지 않습니다.
쿼리 계획 캐시를 강제로 활성화 또는 비활성화하는 방법
쿼리 계획 캐시는 지연 시간이 짧은 파라미터화된 쿼리에 대해 기본적으로 활성화됩니다. 파라미터화된 쿼리에 대한 계획은 지연 시간이 100ms의 임계값보다 낮은 경우에만 캐시됩니다. 이 동작은 쿼리 수준 쿼리 힌트 QUERY:PLANCACHE를 통해 쿼리별(파라미터화 여부와 무관하게)로 재정의할 수 있습니다. USING 절과 함께 사용해야 합니다. 쿼리 힌트는 enabled 또는 disabled를 값으로 허용합니다.
- AWS CLI
-
캐시되거나 재사용되는 강제 계획:
aws neptunedata execute-open-cypher-query \
--endpoint-url https://your-neptune-endpoint:port \
--open-cypher-query "Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1"
파라미터 포함:
aws neptunedata execute-open-cypher-query \
--endpoint-url https://your-neptune-endpoint:port \
--open-cypher-query "Using QUERY:PLANCACHE \"enabled\" RETURN \$arg" \
--parameters '{"arg": 123}'
캐싱되거나 재사용되지 않도록 강제 계획:
aws neptunedata execute-open-cypher-query \
--endpoint-url https://your-neptune-endpoint:port \
--open-cypher-query "Using QUERY:PLANCACHE \"disabled\" MATCH(n) RETURN n LIMIT 1"
자세한 내용은 AWS CLI 명령 참조의 execute-open-cypher-query를 참조하세요.
- SDK
-
import boto3
from botocore.config import Config
client = boto3.client(
'neptunedata',
endpoint_url='https://your-neptune-endpoint:port',
config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)
# Forcing plan to be cached or reused
response = client.execute_open_cypher_query(
openCypherQuery='Using QUERY:PLANCACHE "enabled" MATCH(n) RETURN n LIMIT 1'
)
print(response['results'])
다른 언어의 AWS SDK 예제는 섹션을 참조하세요AWS SDK.
- awscurl
-
캐시되거나 재사용되는 강제 계획:
awscurl https://your-neptune-endpoint:port/openCypher \
--region us-east-1 \
--service neptune-db \
-X POST \
-d "query=Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1"
이 예제에서는 자격 AWS 증명이 환경에 구성되어 있다고 가정합니다. us-east-1을 Neptune 클러스터의 리전으로 바꿉니다.
- curl
-
캐시되거나 재사용되는 강제 계획:
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1"
파라미터 포함:
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"enabled\" RETURN \$arg" \
-d "parameters={\"arg\": 123}"
캐싱되거나 재사용되지 않도록 강제 계획:
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"disabled\" MATCH(n) RETURN n LIMIT 1"
계획이 캐시되었는지 여부를 확인하는 방법
HTTP READ의 경우, 쿼리가 제출되고 계획이 캐시된 경우 explain은 쿼리 계획 캐시와 관련된 세부 정보를 표시합니다.
- AWS CLI
-
aws neptunedata execute-open-cypher-explain-query \
--endpoint-url https://your-neptune-endpoint:port \
--open-cypher-query "Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1" \
--explain-mode details
자세한 내용은 AWS CLI 명령 참조의 execute-open-cypher-explain-query를 참조하세요.
- SDK
-
import boto3
from botocore.config import Config
client = boto3.client(
'neptunedata',
endpoint_url='https://your-neptune-endpoint:port',
config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)
response = client.execute_open_cypher_explain_query(
openCypherQuery='Using QUERY:PLANCACHE "enabled" MATCH(n) RETURN n LIMIT 1',
explainMode='details'
)
print(response['results'].read().decode('utf-8'))
다른 언어의 AWS SDK 예제는 섹션을 참조하세요AWS SDK.
- awscurl
-
awscurl https://your-neptune-endpoint:port/openCypher \
--region us-east-1 \
--service neptune-db \
-X POST \
-d "query=Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1" \
-d "explain=details"
이 예제에서는 자격 AWS 증명이 환경에 구성되어 있다고 가정합니다. us-east-1을 Neptune 클러스터의 리전으로 바꿉니다.
- curl
-
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"enabled\" MATCH(n) RETURN n LIMIT 1" \
-d "explain=details"
계획이 캐시된 경우 explain 출력에 다음이 표시됩니다.
Query: <QUERY STRING>
Plan cached by request: <REQUEST ID OF FIRST TIME EXECUTION>
Plan cached at: <TIMESTAMP OF FIRST TIME EXECUTION>
Parameters: <PARAMETERS, IF QUERY IS PARAMETERIZED QUERY>
Plan cache hits: <NUMBER OF CACHE HITS FOR CACHED PLAN>
First query evaluation time: <LATENCY OF FIRST TIME EXECUTION>
The query has been executed based on a cached query plan. Detailed explain with operator runtime statistics can be obtained by running the query with plan cache disabled (using HTTP parameter planCache=disabled).
Bolt를 사용하는 경우 설명 기능은 지원되지 않습니다.
제거
쿼리 계획은 캐시 TTL(Time to Live) 또는 캐시된 쿼리 계획의 최대 수에 도달했을 때 제거됩니다. 쿼리 계획에 도달하면 TTL이 새로 고쳐집니다. 기본값은 다음과 같습니다.
계획이 캐시되지 않는 조건
다음 조건에서는 쿼리 계획 캐시가 사용되지 않습니다.
-
쿼리 힌트 QUERY:PLANCACHE "disabled"를 사용하여 쿼리를 제출하는 경우입니다. 쿼리를 다시 실행하고 QUERY:PLANCACHE "disabled"를 제거하여 쿼리 계획 캐시를 활성화할 수 있습니다.
-
제출된 쿼리가 파라미터화된 쿼리가 아니며 힌트 QUERY:PLANCACHE "enabled"를 포함하지 않는 경우입니다.
-
쿼리 평가 시간이 지연 시간 임계값보다 클 경우, 해당 쿼리는 캐시되지 않으며 쿼리 계획 캐시의 혜택을 받지 못하는 장기 실행 쿼리로 간주됩니다.
-
쿼리에 결과를 반환하지 않는 패턴이 포함된 경우입니다.
-
즉, 지정된 레이블을 가진 노드가 없는 경우에 MATCH (n:nonexistentLabel) return n
-
즉, name=abcde를 포함하는 노드가 없는 경우에 parameters={"param": "abcde"}인 MATCH (n {name: $param}) return n
-
쿼리 파라미터가 list 또는 map과 같은 복합 유형인 경우입니다.
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"enabled\" RETURN \$arg" \
-d "parameters={\"arg\": [1, 2, 3]}"
curl https://your-neptune-endpoint:port/openCypher \
-d "query=Using QUERY:PLANCACHE \"enabled\" RETURN \$arg" \
-d "parameters={\"arg\": {\"a\": 1}}"
-
쿼리 파라미터가 데이터 로드 또는 데이터 삽입 작업의 일부가 아니었던 문자열인 경우입니다. 예를 들어, "X"를 삽입하기 위해 CREATE (n {name: "X"})가 실행되면 RETURN "Y"는 캐시되지만, RETURN "X"는 캐시되지 않으며 "Y"는 삽입되지 않았으며 데이터베이스에 존재하지 않습니다.