Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 0FE739FB99E for ; Mon, 6 Aug 2007 17:17:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 53130-04 for ; Mon, 6 Aug 2007 17:16:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mac.se (slimjim.mantaray.se [195.43.255.244]) by postgresql.org (Postfix) with ESMTP id 92C2E9FB6A6 for ; Mon, 6 Aug 2007 17:16:59 -0300 (ADT) Received: from [85.24.169.56] (account henke HELO [10.168.1.146]) by mac.se (CommuniGate Pro SMTP 4.2.10) with ESMTP-TLS id 3742892; Mon, 06 Aug 2007 22:16:58 +0200 In-Reply-To: <46B77ACA.9010302@enterprisedb.com> References: <27459.1186412327@sss.pgh.pa.us> <3176138F-E316-46AF-99AE-0CC8F1EF1E73@mac.se> <46B77ACA.9010302@enterprisedb.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <976CDC49-082B-4612-B6A4-4B46B5109829@mac.se> Cc: Tom Lane , pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Henrik Zagerholm Subject: Re: Extreme slow select query 8.2.4 Date: Mon, 6 Aug 2007 22:16:55 +0200 To: Heikki Linnakangas X-Mailer: Apple Mail (2.752.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/52 X-Sequence-Number: 26182 6 aug 2007 kl. 21:47 skrev Heikki Linnakangas: > Henrik Zagerholm wrote: >> I know the query retrieves way more which is really necessary to >> show to >> the user so I would gladly come up with a way to limit the query >> so the >> GUI doesn't hang for several minutes if a user does a bad search. >> The problem is that I don't know a good way of limit the search >> efficiently as only going on tbl_file with limit 100 could make the >> query only to return 10 rows if the user doesn't have access to >> 900 of >> the files (This is what the join with tbl_acl does). Using cursors >> doesn't help because I really don't retrieve that much data > > Could you just add a LIMIT 100 to the end of the query, if 100 rows is > enough? That would cut the runtime of the query, if there's a quicker > plan to retrieve just those 100 rows. As you can see in the query I already have a limit 20 and it doesn't make any difference as the query still does the big joins between tbl_file, tbl_file_structure and tbl_acl. This is why I think I have to come up with a way of using sub select with internal limits. Maybe have a cursor like procedure using these so I always get the correct number of lines back. > > Another alternative is to use statement_timeout. If a query takes > longer > than specified timeout, it's automatically aborted and an error is > given. Interesting! I'll take a look at that. Thanks, henrik > > -- > Heikki Linnakangas > EnterpriseDB http://www.enterprisedb.com