Skip to content

EXISTS subquery fails with multiple MATCH clauses in Memgraph 3.7.1 #3544

Description

@tjasa-paurus

Memgraph version
3.7.1

Environment

  • Operating system: macOS Tahoe 26.1
  • Architecture: ARM64 (chip: Apple M4 Pro)
  • Running via: Docker (Docker version 29.1.2, build 890dcca) using docker-compose.yaml:
name: test
services:
  memgraph:
    image: memgraph/memgraph:3.7.1
    container_name: memgraph
    restart: always
    ports:
      - "7687:7687"
      - "7444:7444"
    command:
      - "--also-log-to-stderr"
      - "--log-level=INFO"
    volumes:
      - mg_lib:/var/lib/memgraph
      - mg_log:/var/log/memgraph
      - mg_etc:/etc/memgraph

  memgraph-lab:
    image: memgraph/lab:3.7.0
    container_name: memgraph-lab
    ports:
      - "3000:3000"
    depends_on:
      - memgraph
    environment:
      - QUICK_CONNECT_MG_HOST=memgraph
      - QUICK_CONNECT_MG_PORT=7687

volumes:
  mg_lib:
  mg_log:
  mg_etc:
  • Connection to memgraph: via Memgraph Lab included in docker compose. Queries are run directly via Memgraph Lab

Bug description
When using multiple MATCH clauses (or comma-separated patterns) inside an EXISTS { ... } subquery on Memgraph v3.7.1, Memgraph throws the following error in Memgraph Lab v3.7.0:

Expected to generate all filters! Please contact Memgraph support as this scenario should not happen and is very likely a bug in the query engine!

To Reproduce
Steps to reproduce the behavior:

  1. Run the following to create a minimal test database dataset:
CREATE (p:Person {id: 2})
CREATE (d1:Dog {name: "Max"})
CREATE (d2:Dog {name: "Luna"})
CREATE (b:Breed {name: "Bulldog"})
CREATE (p)-[r1:OWNS_DOG]->(d1)-[r3:BELONGS_TO_BREED]->(b)
CREATE (p)-[r2:OWNS_DOG]->(d2);
  1. Run any of the following queries in Memgraph Lab to trigger the error:
  • Comma-separated patterns in a single MATCH:
MATCH (p:Person)
WHERE EXISTS {
  MATCH (p)-[r1:OWNS_DOG]->(d:Dog), (d)-[:BELONGS_TO_BREED]->(b:Breed)
  WHERE b.name = "Bulldog"
}
RETURN p;
  • Multiple MATCH clauses:
MATCH (p:Person)
WHERE EXISTS {
  MATCH (p)-[r1:OWNS_DOG]->(d:Dog)
  MATCH (d)-[:BELONGS_TO_BREED]->(b:Breed)
  WHERE b.name = "Bulldog"
}
RETURN p;
  • MATCH + OPTIONAL MATCH:
MATCH (p:Person)
WHERE EXISTS {
  MATCH (p)-[r1:OWNS_DOG]->(d:Dog)
  OPTIONAL MATCH (d)-[:BELONGS_TO_BREED]->(b:Breed)
  WHERE b.name = "Bulldog"
}
RETURN p;

Expected behavior
All queries above should evaluate the patterns inside EXISTS correctly and return the matching Person node without triggering internal query engine errors.
Multiple MATCH clauses in subqueries should behave the same as a single MATCH with a longer pattern.

Logs
No additional server logs were generated during these tests.

Additional context

  1. Problem reproduces consistently on a clean dataset.
  2. The equivalent pattern expressed as a single MATCH clause works correctly. Example query:
MATCH (p:Person)
WHERE EXISTS {
  MATCH (p)-[r1:OWNS_DOG]->(d:Dog)-[:BELONGS_TO_BREED]->(b:Breed)
  WHERE b.name = "Bulldog"
}
RETURN p;

Verification Environment
To test a fix Memgraph Docker image is sufficient for verification.

Activity

  1. pmcmick commented on Jan 22, 2026

    @pmcmick

    We encountered a similar "Expected to generate all filters" error with a different pattern: a single MATCH inside NOT EXISTS that references a property from the outer scope.

    Reproducer:

    -- Setup
    CREATE (a:Test {project: 'source', hash: 1});
    CREATE (b:Test {project: 'source', hash: 2});
    CREATE (c:Test {project: 'sidecar', hash: 1});
    
    -- This fails with "Expected to generate all filters!"
    MATCH (src:Test {project: 'source'})
    WHERE NOT EXISTS {
      MATCH (sc:Test {project: 'sidecar'})
      WHERE sc.hash = src.hash
    }
    RETURN src;

    Expected: Return node b (hash=2, not in sidecar)
    Actual: Error: "Expected to generate all filters! Please contact Memgraph support..."

    Workaround: Use NOT IN with collect():

    MATCH (sc:Test {project: 'sidecar'})
    WITH collect(sc.hash) AS hashes
    MATCH (src:Test {project: 'source'})
    WHERE NOT src.hash IN hashes
    RETURN src;

    Perhaps this suggests a broader issue than multiple MATCH clauses - in our limited testing, it seems to involve any outer scope property reference inside EXISTS subqueries.

    Environment:

    • Memgraph: v3.7.2 (memgraph/memgraph-mage:latest, sha256:9b6e9ecd...)
    • Container: Podman 5.7.1
    • OS: Linux, x86_64
    • Client: pymgclient 1.5.1, Python 3.13.11

    Hope this is helpful.

  2. added theissue type on Jan 24, 2026
  3. changed the issue type fromtoon Jan 24, 2026
  4. added a commit that references this issue on Sep 17, 2026
    abf8cc9
  5. added a commit that references this issue on Sep 23, 2026
    c906cf7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions