Help to tune cql

Hi folks

I'm sending a command through the Neo4j Python driver where I am executing a session.run() and giving a query string + JSON object as a parameter. The JSON object is a list of records that I'm iterating through on the other end to make relationships between nodes.

The query, as-is, partially works. I'm making 291 Python requests to the database which is currently making 1804 relationships and has 44 failures. It is the failures that bring me here.

From the debug I can see there are no relationships being created greater than 10, and the failures are giving me a CartesianProduct notification leading me to believe the failures are the result of wanting to make more than 10 relationships but the database is refusing because the query needs optimising.

Here's the query:

CALL apoc.load.json($saleslist) YIELD value
      UNWIND value.data AS record
      MATCH (a:thesenodes), (b:thosenodes) WHERE
      b.spec_id = record.that_val_1 AND
      a.other_id = record.that_val_2 AND
      a.third_id = record.that_val_3
      CREATE (b)-[r:TEST_RELATIONSHIP {date: DATETIME(record.that_val_4)}]->(a)
      RETURN (r);

My database has indexes for the node properties used in the MATCH.

Is it possible to optimise this query? Could there be some pre-processing on the loaded JSON records where all values of a specific key are placed into a LIST and only nodes (belonging to either a or b) are referenced according to what is in the list?

Hi folks, I have PROFILE'd my failed CQL queries. What exactly should I look for? I can see the CartesianProduct expansion and see a Filter and NodeUniqueIndexSeek(Locking) which are the only entries in the profile taking up memory.

EDIT: I may have found the source of the problem. I will report back.

I believe I have solved the issue so just placing this here for benefit of anyone in future with a similar level of experience (novice) and experiencing the same thing.

The CartesianProduct lead was a red-herring. I was missing an equal number of nodes relevant to my CQL as there were failures...

Always good to not rely on others to support you solve your issues too!...