X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id ECB08D7D7F for ; Wed, 12 Oct 2005 07:35:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27445-05 for ; Wed, 12 Oct 2005 10:35:26 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 23AEDD810F for ; Wed, 12 Oct 2005 07:35:27 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 2432C40D4C8; Wed, 12 Oct 2005 11:35:21 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 535EB15ED9; Wed, 12 Oct 2005 11:34:36 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16217-08; Wed, 12 Oct 2005 11:34:32 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id D707E15ED5; Wed, 12 Oct 2005 11:34:32 +0100 (BST) Message-ID: <434CE6B8.5060106@archonet.com> Date: Wed, 12 Oct 2005 11:34:32 +0100 From: Richard Huxton User-Agent: Thunderbird 1.4.1 (X11/20051006) MIME-Version: 1.0 To: Frank Bax Cc: pgsql-sql@postgresql.org Subject: Re: SEVEN cross joins?!?!? References: <5.2.1.1.0.20051011071510.0364d850@pop6.sympatico.ca> <5.2.1.1.0.20051011071510.0364d850@pop6.sympatico.ca> <5.2.1.1.0.20051011145705.00a31440@pop6.sympatico.ca> In-Reply-To: <5.2.1.1.0.20051011145705.00a31440@pop6.sympatico.ca> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.487 required=5 tests=[AWL=-0.420, FORGED_RCVD_HELO=0.05, MANY_EXCLAMATIONS=0, PLING_QUERY=0.857] X-Spam-Level: X-Archive-Number: 200510/102 X-Sequence-Number: 22955 Frank Bax wrote: >> 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. > > > There is no "best 10". I currently limit each subselect to 10 items so > that query will actually run without crashing. I would like to remove > the "ORDER BY itemid LIMIT 10" mentioned above. At the end of the query > I have a "LIMIT 100" clause which will stay and produces a list of "best > 100" combos. > > Either of your solutions would be acceptable; since avoiding the > "explosion" would also make the query faster. Current calculations > indicate that running the query without "LIMIT 10" in subselect would > take years to process. OK - so at the heart of the problem is the fact that you want to search a space with 100 billion possible states. There are three main options 1. Brute force and patience - simple and is guaranteed to produce the "best" answers. You can use cursors/multiple queries to manage the workload. The disadvantage is that it's probably slower than you'd like. 2. Smarter algorithms - possibly something genetic to work towards local maxima. Or, if you'd like to keep it simple, just split your 7 locations into 2,2,3 and solve for each separately. 3. Statistical - examine a subset of possible states and accept you'll only be able to say "almost best" to 99% confidence or similar. I'd be tempted by #2 - there are probably some combinations you can rule out, which combined with a split/recombine should reduce the number of states to query. That any help? -- Richard Huxton Archonet Ltd