Re: SEVEN cross joins?!?!?

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: SEVEN cross joins?!?!?
Дата
Msg-id 434BB042.7000309@archonet.com
обсуждение исходный текст
Ответ на SEVEN cross joins?!?!?  (Frank Bax <fbax@sympatico.ca>)
Ответы Re: SEVEN cross joins?!?!?
Список pgsql-sql
Frank Bax wrote:
> I have a table with only 434 rows in it.  Two important columns are 
> "itemid" and "locn".  Each item must be in one of seven locations.  We 
> need to create a "combo" by selecting one item from each of seven 
> locations; then determine which "combo" is the "best" according to our 
> analysis (see below).
> 
> A subselect for items in a location looks something like:
> (select * from suit_item where locn='Head' AND username='Walter' ORDER 
> BY itemid LIMIT 10) as Head
> 
> One subselect for each location, cross join them all and the query 
> generates 10,000,000 combinations!  Without the "LIMIT 10",  there are  
> 78 * 37 * 91 * 81 * 99 * 47 * 1 = 98,981,901,018 results returned for 
> username='Walter' (the only user at the moment).  The large volume is 
> causing a problem for my systems!  The "ORDER BY itemid" was added only 
> so that same 10 items were processed on different computer systems I 
> tested this query on.  Only one item for 7th locn in the database at the 
> moment.

Frank - it might just be me, but I've read your email twice and despite 
all the information I still don't have any idea what you are trying to do.

Are you saying that you WANT to generate a cross-join, score the 
millions of results and then pick the best 10? It's doing what you want, 
but you'd like it to be faster.

Or are you saying that you'd like to avoid the explosion in rows altogether?

In either case - I don't suppose you could provide a real example of the 
query, so we can see exactly what you're trying to do.
--  Richard Huxton  Archonet Ltd


В списке pgsql-sql по дате отправления:

Предыдущее
От: Frank Bax
Дата:
Сообщение: SEVEN cross joins?!?!?
Следующее
От: "Rick Schumeyer"
Дата:
Сообщение: question re. count, group by, and having