Skip to Content
Neo4j: The Definitive Guide
book

Neo4j: The Definitive Guide

by Luanne Misquitta, Christophe Willemsen
July 2025
Beginner to intermediate
410 pages
6h 27m
Korean
O'Reilly Media, Inc.
Content preview from Neo4j: The Definitive Guide

8장. 고급 그래프 패턴

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

이 장에서는 Neo4j 전문가로서 알아두면 유용한 고급 그래프 패턴을 살펴봅니다. 여기서는 보안을 위한 모델링 기법, 엔티티 해상도, 보다 효율적인 쿼리, 노드 수준 처리 및 최신 정량화된 경로 패턴에 대해 다룹니다. 이전 장에서 하위 쿼리의 일부 사용법을 살펴보셨으니 이제 이에 대해 자세히 알아보겠습니다.

쿼리를 사용해 보려면 chapter5 데이터베이스를 계속 사용하거나 GitHub 리포지토리에 있는 README에 따라 다시 만들어 보세요.

하위 쿼리

Cypher 의하위 쿼리는 외부 쿼리의 중첩된 범위 내에서 실행되는 중첩 쿼리입니다. CALL 하위 쿼리는 외부 쿼리에서 도착하는 행마다 실행됩니다. 중요한 점은 하위 쿼리가 자체 범위에서 작동하기 때문에 행을 실행하는 동안 생성된 데이터 구조를 다음 수신 행으로 이동하기 전에 보유할 필요가 없으므로 메모리 오버헤드가 줄어든다는 점입니다. 하위 쿼리는 그래프에서 읽고 쓸 때 모두 사용됩니다.

호출 하위 쿼리

5장에서는 1,800만 개의 노드와 1억 개의 관계가 있는 그래프가 있는 대규모 데이터 집합을 가져왔습니다. 이 그래프는 하위 쿼리 사용의 효과를 조사하는 데 이상적입니다. 첫 번째 버전 쿼리는 그래프의 모든 트랙과 해당 트랙이 재생 중인 재생 목록을 반환하도록 Neo4j에 요청하며, 경로 확장이 포함된 일반 MATCH 을 사용합니다:

//001-explain-all-tracks.cypher
EXPLAIN
MATCH (t:Track)-[:ON_PLAYLIST]->(p:Playlist)
RETURN t as track, COLLECT(p) as playlists

이 그래프에는 약 1,300만 개의 트랙이 있으며, 이 쿼리는 모든 트랙을 순회하여 재생 중인 재생 목록을 수집합니다. 이 쿼리의 EXPLAIN 을 실행합니다( PROFILE 을 시도하지 마십시오. 그렇지 않으면 쿼리가 실제로 실행될 때까지 매우 오래 기다릴 수 있습니다). 그림 8-1에 표시된 계획은 EagerAggregation 연산자를 보여줍니다(열망 연산에 대한 자세한 내용은 5장을 참조하세요).

그림 8-1. 모든 트랙과 해당 재생 목록을 반환하는 EXPLAIN 쿼리 계획

COLLECT 집계가 올바르게 처리되려면 MATCH 연산이 모든 트랙과 재생 목록에 대해 완전히 실행되어야 합니다. 이렇게 집계된 결과는 연산자가 완료할 때까지 메모리에 보관된 후 결과 스트리밍이 진행됩니다. 이로 인해 힙에 스트레스가 가해져 잠재적인 Out of Memory 예외가 발생하거나 가비지 수집(GC) 일시 중지가 증가할 수 있습니다. 이러한 유형의 쿼리는 하위 쿼리의 성능을 보여주는 데 이상적입니다. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Neo4j: The Definitive Guide

Neo4j: The Definitive Guide

Luanne Misquitta, Christophe Willemsen
Apache Iceberg: The Definitive Guide

Apache Iceberg: The Definitive Guide

Tomer Shiran, Jason Hughes, Alex Merced
Kafka: The Definitive Guide, 2nd Edition

Kafka: The Definitive Guide, 2nd Edition

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9798341664869