- Learning Neo4j 3.x(Second Edition)
- Jér?me Baton Rik Van Bruggen
- 537字
- 2021-07-08 09:37:36
Complex queries
Complex queries are the types of questions that you want to ask of your data that are inherently composed of a number of complex join-style operations. These operations, as every database administrator knows, are very expensive operations in relational database systems, because we need to be computing the Cartesian product of the indices of the tables that we are trying to join. That may be okay for one or two joins between two or three tables in a relational database management system, but as you can easily understand, this problem becomes exponentially bigger with every table join that you add. On smaller datasets, it can become an unsolvable problem in a relational system, and this is why complex queries become problematic.
An example of such a complex query would be finding all the restaurants in a certain London neighborhood that serve Indian food, are open on Sundays, and cater for kids. In relational terms, this would mean joining up data from the restaurant table, the food type table, the opening hours table, the caters for table, and the zip-code table holding the London neighborhoods, and then providing an answer. No doubt there are numerous other examples where you would need to do these types of complex queries; this is just a hypothetical one.
In a graph database, a join operation will never need to be performed: all we need to do is to find a starting node in the database (for example, London), usually with an index lookup, and then just use the index-free adjacency characteristic and hop from one node (London) to the next (Restaurant) over its connecting relationships (Restaurant-[LOCATED_IN]->London). Every hop along this path is, in effect, the equivalent of a join operation. Relationships between nodes can therefore also be thought of as an explicitly stored representation of such a join operation.
We often refer to these types of queries as pattern matching queries. We specify a pattern (refer to the following diagram: blue connects to orange, orange connects to green, and blue connects to green), we anchor that pattern to one or more starting points and we start looking for the matching occurrences of that pattern. As you can see, the graph database will be an excellent tool to spin around the anchor node and figure out whether there are matching patterns connected to it. Non-matching patterns will be ignored, and matching patterns that are not connected to the starting node will not even be considered.
This is actually one of the key performance characteristics of a graph database: as soon as you grab a starting node, the database will only explore the vicinity of that starting node and will be completely oblivious to anything that is not connected to the starting node. The key performance characteristic that follows from this is that query performance is very independent of the dataset size, because in most graphs, everything is not connected to everything. By the same token, as we will see later, performance will be much more dependent on the size of the result set, and this will also be one of the key things to keep in mind when putting together your persistence architecture:

- Learning Single:page Web Application Development
- 解構(gòu)產(chǎn)品經(jīng)理:互聯(lián)網(wǎng)產(chǎn)品策劃入門(mén)寶典
- 深入淺出Electron:原理、工程與實(shí)踐
- JavaFX Essentials
- AngularJS深度剖析與最佳實(shí)踐
- 機(jī)械工程師Python編程:入門(mén)、實(shí)戰(zhàn)與進(jìn)階
- SAS數(shù)據(jù)統(tǒng)計(jì)分析與編程實(shí)踐
- Python機(jī)器學(xué)習(xí)經(jīng)典實(shí)例
- 軟件測(cè)試技術(shù)指南
- SQL Server從入門(mén)到精通(第3版)
- Learning Unreal Engine Android Game Development
- Spring+Spring MVC+MyBatis從零開(kāi)始學(xué)
- 汽車(chē)人機(jī)交互界面整合設(shè)計(jì)
- SwiftUI極簡(jiǎn)開(kāi)發(fā)
- 美麗洞察力:從化妝品行業(yè)看顧客需求洞察