Investigate

Introduction

In this challenge you will be presented with a query that exhibits common performance issues.

You should:

  1. Use PROFILE to analyze the query.

  2. Identify the root causes of the performance issues.

  3. Implement effective solutions to resolve the performance problems.

Finding product reorder levels by category

The following query finds the reorder levels for products in the "Beverages" category.

cypher
Find reorder levels by category
MATCH (p:Product)
WITH p, p.productName as productName, p.reorderLevel as reorderLevel
MATCH (p)-[:PART_OF]->(c:Category {categoryName: "Beverages"})
RETURN c.categoryName, productName, reorderLevel

You should profile the query and identify improvement opportunities. Consider the following questions:

  • What is the anchor node(s) in this query?

  • How can the query be simplified to reduce the number of operations?

  • What properties are being searched?

Click to reveal the solution
  1. The query is overly complicated and is performing unnecessary operations, such as using WITH to read properties that are not needed until later in the query.

  2. The anchor for the query is all the Product nodes.

    Profile showing the Product nodes as the anchor

    You can simplify the query and make the Category nodes the anchor:

    cypher
    Simplify the query to make Category the anchor
    MATCH (p:Product)-[:PART_OF]->(c:Category {categoryName: "Beverages"})
    RETURN c.categoryName, p.productName as productName, p.reorderLevel as reorderLevel
    Profile showing the Category nodes as the anchor
  3. The query is searching for categoryName on the Category nodes, you can also create an index on that property:

    cypher
    Create an index on categoryName
    CREATE INDEX categoryName_Category
    IF NOT EXISTS
    FOR (c:Category) ON c.categoryName

The simplified query with the new index significantly improves the performance.

Lesson Summary

In this challenge, you investigated query performance issues, using various diagnostic approaches, and implementing solutions to resolve common performance problems.

Chatbot

How can I help you today?