아래에 나의 샘플 요구 사항
내가 원하는 고객을 충족하는 모든 아래 조건
- 국가에서"xyz",통합된 사 2019 2021.
- 을 가지고해야합니다 적어도 하나의 계정으로 사이에 균형을 10000 및 13000 및 지사는"abc"및 트랜잭션 날짜를 사 20200110 및 20210625. 그것은 포맷으로 저장 번호
- 을 가지고해야합니다 적어도 하나의 주소는 상태에서"state1"과 pin 코드를 사 625001 및 625015
아래 테이블 구조
CREATE TABLE IF NOT EXISTS customer_search_ms.customer
(
customer_id integer,
customer_details jsonb
)
가 될 수 있는 수백만의 행 테이블에 있습니다. 내가 만들어 진 index 의 유형 jsonb_ops 에 customer_details 열로 우리는 것도 확인 존재에 대한 조건 및 비교
아래 샘플은 데이터 customer_data 대화는 두서없이 열
customer_id : 1
{
"customer_data": {
"name": "abc",
"incorporated_year": 2020,
"country":"xyz",
"account_details": [
{
"transaction_dates": [
20180125, 20190125, 20200125,20200525
],
"account_id": 1016084,
"account_balance": 2000,
"account_branch": "xyz"
},
{
"transaction_dates": [
20180125, 20190125, 20200125
],
"account_id": 1016087,
"account_balance": 12010,
"account_branch": "abc"
}
],
"address": [
{
"address_id": 24739,
"door_no": 4686467,
"street_name":"street1",
"city": "city1",
"state": "state1",
"pin_code": 625001
},
{
"address_id": 24730,
"door_no": 4686442,
"street_name":"street2",
"city": "city1",
"state": "state1",
"pin_code": 625014
}
]
}
}
지금 쿼리를 작성해가
SELECT c.customer_id,
c.customer_details
FROM customer_search_ms.customer c
WHERE c.customer_details @@ CAST('$.customer_data.country == "xyz" && $.customer_data.incorporated_year >= 2019 && $.customer_data.incorporated_year <= 2021 ' AS JSONPATH)
AND c.customer_details @? CAST('$.customer_data.account_details[*] ? (@.account_balance >= 10000) ? (@.account_balance <= 13000) ?(@.account_branch == "abc") ? (@.transaction_dates >= 20200110) ? (@.transaction_dates <= 20210625)' AS JSONPATH)
AND c.customer_details @? CAST('$.customer_data.address[*] ? (@.state == "state1") ? (@.pin_code >= 625001) ? (@.pin_code <= 625015) ' AS JSONPATH)
위에서 처리 할 수 있는 시나리오 그것이 최선의 방법으로 작성합니다. 를 결합 할 수 있는 모든 3 조건의(고객/계/주소)를 하나의 식? 테이블의 수백만의 행이 있습니다. 나의 의견을 중 하나로 표현하고 타격 DB 것이 최상의 성능을 제공합니다. 가 결합이 가능한 이러한 3 조건 중 하나로 표현