I'm not a pro in SQL at all :) Having a very critical performance issue. Here is the info directly related to problem.
I have 2 tables in my DB- table condos
and table goods
.
table condos
have the fields:
- id (PK)
- name
- city
- country
table items:
- id (PK)
- name
- multiple fields not related to issue
- condo_id (FK)
I have 1000+ entities in condos
table and 1000+ in items
table.
The problem is how i perform items search
currently it is:
For example, i want to get all the items for city = Sydney
- Perform a
SELECT condos.condo_id FROM public.condos WHERE city = 'Sydney'
- Make a
SELECT * FROM public.items WHERE item.condo_id = ?
for eachcondo_id
i get in step 1.
The issue is that once i get 1000+ entities in condos
table, the request is performed 1000+ times for each condo_id
belongs to 'Sydney'. And the execution of this request takes more then a 2 minutes which is a critical performance issue.
So, the questions is:
What is the best way for me to perform such search ? should i put a 1000+ id's in single WHERE
request? or?
For add info, i use PostgreSQL 9.4 and Spring MVC.