X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id C3A229FB252 for ; Wed, 2 Aug 2006 07:56:25 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 22379-06 for ; Wed, 2 Aug 2006 07:56:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from office.redwerk.com (office.redwerk.com [85.90.206.104]) by postgresql.org (Postfix) with ESMTP id C97F69FB24F for ; Wed, 2 Aug 2006 07:56:20 -0300 (ADT) Received: from bofh by office.redwerk.com with local (Exim 4.62 (FreeBSD)) (envelope-from ) id 1G8EOk-0000gp-3w for pgsql-performance@postgresql.org; Wed, 02 Aug 2006 13:56:22 +0300 Date: Wed, 2 Aug 2006 13:56:22 +0300 From: Eugeny N Dzhurinsky To: pgsql-performance@postgresql.org Subject: Re: Query/database optimization Message-ID: <20060802105622.GA2627@office.redwerk.com> References: <20060801131837.GC4221@office.redwerk.com> <29157.1154488511@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <29157.1154488511@sss.pgh.pa.us> User-Agent: Mutt/1.5.12-2006-07-14 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200608/24 X-Sequence-Number: 20209 On Tue, Aug 01, 2006 at 11:15:11PM -0400, Tom Lane wrote: > Eugeny N Dzhurinsky writes: > > [slow query] > The bulk of your time seems to be going into this indexscan: > > -> Index Scan using task_scheduler_icustomer_id on task_scheduler ts (cost=2.03..11.51 rows=1 width=51) (actual time=2.785..2.785 rows=0 loops=4161) > > Index Cond: ("outer".customer_id = ts.customer_id) > > Filter: ((get_available_pages(task_id, customer_id) > 0) AND ((get_check_period(task_id, next_check) IS NULL) OR ((date_part('epoch'::text, get_check_period(task_id, next_check)) - date_part('epoch'::text, (timenow())::timestamp without time zone)) < 3600::double precision)) AND (status <> 1) AND ((((start_time)::time with time zone < ('now'::text)::time(6) with time zone) AND ((stop_time)::time with time zone > ('now'::text)::time(6) with time zone)) OR ((start_time IS NULL) AND (stop_time IS NULL))) AND (NOT (hashed subplan))) > > SubPlan > > -> Unique (cost=2.02..2.03 rows=1 width=4) (actual time=0.617..0.631 rows=3 loops=1) > > ... > > I kinda doubt that the index search itself is that slow --- doubtless > the problem comes from having to evaluate that filter condition on a lot > of rows. How fast are those functions you're calling? Well, not really fast, especially get_available_pages there is special table with history of changes, and there is a view for latest changes per task, and this function selects all records from a view for given ID, then calculates sum of pages of tasks and then calculates number of available pages as number of allowed pages deduct number of processed pages. probably there is bottleneck in this view selection? -- Eugene N Dzhurinsky