# Apoc.periodic.iterate is never ending

**URL:** <https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147>\
**Category:** Procedures & APOC\
**Tags:** apoc, cypher, relationship, import\
**Created:** [April 20, 2023, 11:37am UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147 "2023-04-20T11:37:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![1996haribaskar](https://avatars.discourse-cdn.com/v4/letter/1/838e76/32.png) [@1996haribaskar](https://community.neo4j.com/u/1996haribaskar)\
**Post date:** [April 20, 2023, 11:37am UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/1 "2023-04-20T11:37:19Z")

</div>

I am using the apoc.periodic.iterate procedure to upload data from ORA DB into the Neo4j and trying to create relationships. Initially I created the nodes and now trying to match those existing nodes and creating relationships.

For example, I have a two type of nodes (:Library) and (:Books). These nodes are created initially and now I am trying to create the relationship between the Library and books by matching the existing nodes.

CALL apoc.periodic.iterate(  
'CALL apoc.load.jdbc("jdbc:oracle:thin:connection\_string","select \* from library\_books") YIELD row',  
'MATCH (a:Library),  
(b:Books)  
where b.book\_name=row.BOOK\_NAME  
and a.lib\_id=row.LIB\_ID  
create (a)-[y:HAS\_BOOKS]-\>(b)  
SET y.lib\_book\_code=row.CODE',  
{ batchSize:10000, parallel:true})

Even when I run this code for 500 nodes, its never ending. can someone please help me with this query or How can I write this query better?

Thank you!

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [April 20, 2023, 12:37pm UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/2 "2023-04-20T12:37:59Z")

</div>

What happens when you execute just the database call in the browser, do is it return the data and complete in a reasonable amount of time?

```auto
CALL apoc.load.jdbc("jdbc:oracle:thin:connection_string","select * from library_books") YIELD row'

```

Do you have indexes on the two properties you are matching on?

Books(book\_name) and Library(lib\_id)

Have you tried with parallel set to false? I imagine the same library node could be used concurrently I multiple batches, so maybe you are experiencing some blocking.

---

<div class="post-metadata">

**Author:** ![1996haribaskar](https://avatars.discourse-cdn.com/v4/letter/1/838e76/32.png) [@1996haribaskar](https://community.neo4j.com/u/1996haribaskar)\
**Post date:** [April 20, 2023, 12:46pm UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/3 "2023-04-20T12:46:52Z")

</div>

1. Yes, when I just try to run the database call, I get the data within seconds.

2. I dont have any indexing on the property. May be I can add the index and try it again

3. Yes, I tried setting the parallel to false but still the same

---

<div class="post-metadata">

**Author:** ![1996haribaskar](https://avatars.discourse-cdn.com/v4/letter/1/838e76/32.png) [@1996haribaskar](https://community.neo4j.com/u/1996haribaskar)\
**Post date:** [April 20, 2023, 2:28pm UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/4 "2023-04-20T14:28:38Z")

</div>

I created the index for the properties that I am using to match and the query keeps on running for more than an hour now for 300 nodes.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [April 20, 2023, 4:36pm UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/5 "2023-04-20T16:36:49Z")

</div>

Try this to determine if it is caused by nesting the db call within the iterate. I assume you don't have 100,000s of rows to collect. If you do, you could limit the number of rows for debugging purposes by inserting 'WITH row LIMIT 1000' after the DB call, before the collect operation.

```auto
CALL apoc.load.jdbc("jdbc:oracle:thin:connection_string","select * from library_books") YIELD row
WITH collect(row) as data
CALL apoc.periodic.iterate(
'UNWIND data as row RETURN row',
'MATCH (a:Library),
(b:Books)
where b.book_name=row.BOOK_NAME
and a.lib_id=row.LIB_ID
create (a)-[y:HAS_BOOKS]->(b)
SET y.lib_book_code=row.CODE',
{ batchSize:10000, parallel:true, params:{data:data}})

```

---

<div class="post-metadata">

**Author:** ![1996haribaskar](https://avatars.discourse-cdn.com/v4/letter/1/838e76/32.png) [@1996haribaskar](https://community.neo4j.com/u/1996haribaskar)\
**Post date:** [April 24, 2023, 12:12pm UTC](https://community.neo4j.com/t/apoc-periodic-iterate-is-never-ending/62147/6 "2023-04-24T12:12:52Z")

</div>

Thankyou so much Gary!!

It worked and as you said its because nesting the db call within the iterate and I have around more than a million rows
