Обсуждение: Large select, best practice question

Поиск
Список
Период
Сортировка

Large select, best practice question

От
Bendik Rognlien Johansen
Дата:
Hello,
I have three tables (very simplified):
- people (~6  million records)
- addresses (~7 million records)
- contacts (~10 million records)

I need to select all records from the people table and join addresses
and contacts on it. I use the result to build a Lucene index. One
document for each person (including all contacts and addresses). I am
using jdbc.

When doing it this way, i end up with many more rows than people, and
my application logic takes care of putting the correct address/
contact with each person. To do this the records have to be sorted.
(Takes a loong time) This causes a lot of very similar result rows.
Example:

John Smith has 2 phone numbers and 2 addresses

John Smith | 555-67567 | Elm street 32
John Smith | 555-83463 | Elm street 32
John Smith | 555-83463 | P.O box 55
John Smith | 555-67567 | P.O box 55


This method is quite slow and error prone.

Is there a more elegant solution to this problem?

Re: Large select, best practice question

От
Sean Davis
Дата:


On 3/1/06 11:16 AM, "Bendik Rognlien Johansen" <bendik.johansen@gmail.com>
wrote:

> Hello,
> I have three tables (very simplified):
> - people (~6  million records)
> - addresses (~7 million records)
> - contacts (~10 million records)
>
> I need to select all records from the people table and join addresses
> and contacts on it. I use the result to build a Lucene index. One
> document for each person (including all contacts and addresses). I am
> using jdbc.
>
> When doing it this way, i end up with many more rows than people, and
> my application logic takes care of putting the correct address/
> contact with each person. To do this the records have to be sorted.
> (Takes a loong time) This causes a lot of very similar result rows.
> Example:
>
> John Smith has 2 phone numbers and 2 addresses
>
> John Smith | 555-67567 | Elm street 32
> John Smith | 555-83463 | Elm street 32
> John Smith | 555-83463 | P.O box 55
> John Smith | 555-67567 | P.O box 55
>
>
> This method is quite slow and error prone.
>
> Is there a more elegant solution to this problem?

What SQL are you using to do this?  Should be a simple join on the tables?
Perhaps post your SQL here.

Sean