Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 292FC9FBBF0 for ; Mon, 6 Aug 2007 16:47:43 -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 33506-03-3 for ; Mon, 6 Aug 2007 16:47:39 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by postgresql.org (Postfix) with ESMTP id 3090C9FA4A3 for ; Mon, 6 Aug 2007 16:47:38 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id f5so566948nfh for ; Mon, 06 Aug 2007 12:47:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=AAZlCZkYH+Zw1TeL1S7JBPvfvxuztnhtB0hc+R2y3yNfmzqQD7huvt06+HLh8+9Ucjf/9uU++JbNlZ0+7A+ciqMqLS9/Fb6KA1gajtayZ7clgWuOv9ZL2gFgTNoZvF/xiiKSNHu3IVkpTb31tIYwJBuCBJ7ZzVG8atikgQNL4Co= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=j+uwm+5rlHrgw5vh8E6jn5QQvmAEGZjn4jM5hisqDxzbdz1kzOfksKX2I4CEoAcJMpeGs3pRKR9ZYIqaCO7iAmRFFMBTyFu0jkx8PGoJMi6A8Vsz/wfwaMYT8mRt5NpfuwwhgZq8FSuXyON1kcW+lpgQpy4H9awqOGlVkhznDJ0= Received: by 10.86.58.3 with SMTP id g3mr4587188fga.1186429656904; Mon, 06 Aug 2007 12:47:36 -0700 (PDT) Received: from ?192.168.0.199? ( [80.222.48.97]) by mx.google.com with ESMTPS id g28sm13375539fkg.2007.08.06.12.47.33 (version=SSLv3 cipher=RC4-MD5); Mon, 06 Aug 2007 12:47:34 -0700 (PDT) Message-ID: <46B77ACA.9010302@enterprisedb.com> Date: Mon, 06 Aug 2007 20:47:22 +0100 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.10 (X11/20070329) MIME-Version: 1.0 To: Henrik Zagerholm CC: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Extreme slow select query 8.2.4 References: <27459.1186412327@sss.pgh.pa.us> <3176138F-E316-46AF-99AE-0CC8F1EF1E73@mac.se> In-Reply-To: <3176138F-E316-46AF-99AE-0CC8F1EF1E73@mac.se> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/51 X-Sequence-Number: 26181 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. Another alternative is to use statement_timeout. If a query takes longer than specified timeout, it's automatically aborted and an error is given. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com