Join two table is slow so how to we should do it?

Answered

Hi everyone!

We have this table that is related to another like this:

  • table 1 (20k records) → column fk_jobs[] (any array of id of table 2)
  • table 2 (10k records) → column id (an id)

When we do a query all paginated the speed is very good (~0.07s), but if we want to join the table to use a search index in a fuzzy search that is in the second table we want (I think) to join the tables.

When we do so the request is so slow, like not ending (more than 360s, I didn't wait in the debugger to see if it does return something). To do it since it's an array we do a join like:

  • table2.id in table1.fk_jobs

Are we doing something wrong?

P.S. : on another note it seem the request is not ending (no timeout) when you close the debugger and the CPU usage goes to 100% for a while.

3 replies