Query is taking far too long

Hello, Friends!

I am trying to load some data and create a relationship using a golang-neo4j driver. This query (within golang program) runs forever whereas when I tried using apoc.periodic.iterate it completes within a couple of seconds.

	return func(tx neo4j.Transaction) (interface{}, error) {
		_, err := tx.Run(`unwind $events as event Merge (p:Product{product_id: event.product_id}) SET p = event
		WITH p MATCH (i:Inventory{inventory_id:''}) WHERE i.product_id <> '' WITH i WHERE i.product_id = p.product_id MERGE (p)-[:PRODUCED_BY]->(i)`,
			map[string]interface{}{"events": data})

I have 303 Product p nodes and the i of total 406156 nodes (with the above matching condition). I am expecting 401038 PRODUCED_BY relationships.

I have indexes created for both inventory_id and product_id.

I ran the same query using call apoc.periodic.iterate with the batchSize of 10000 and it finished within a couple of secs. I am not what I am missing in my golang query. Could someone please help me out here? Thanks!

I just plugged in the apoc statement to the go program and used session.Run to execute it. It worked like a charm!

Do you really want to compare the id with the empty string instead of NULL. I suspect the NULL will go faster.