Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 961166501FB for ; Tue, 2 Dec 2008 12:07:51 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46569-04 for ; Tue, 2 Dec 2008 12:07:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by mail.postgresql.org (Postfix) with ESMTP id 29E1765019B for ; Tue, 2 Dec 2008 12:07:46 -0400 (AST) Received: from perhan.alvh.no-ip.org (190-95-21-11.bk17-dsl.surnet.cl [190.95.21.11]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id mB2GCUrB026355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 2 Dec 2008 08:12:34 -0800 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 559AA47CCC; Tue, 2 Dec 2008 13:07:37 -0300 (CLST) Date: Tue, 2 Dec 2008 13:07:37 -0300 From: Alvaro Herrera To: Daniel Cristian Cruz Cc: pgsql-admin Subject: Re: Not so simple query and a half million loop Message-ID: <20081202160737.GJ5672@alvh.no-ip.org> References: <48d0cacb0812010526i7c51b29fs9319618b3aaf3f49@mail.gmail.com> <48d0cacb0812010721t783bdcd9g36090504b7070a06@mail.gmail.com> <48d0cacb0812020210s22d44b84nc0a6719c97502e87@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <48d0cacb0812020210s22d44b84nc0a6719c97502e87@mail.gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Tue, 02 Dec 2008 08:12:36 -0800 (PST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/13 X-Sequence-Number: 30846 Daniel Cristian Cruz escribió: > No one knows why I got "actual time=0.014..0.570 rows=30 loops=511222" > and "actual time=0.005..0.006 rows=1 loops=15158976"? > > With: > cu.cal_user_type = 'u' AND > cu.cal_recur_date = COALESCE((SELECT cd.cal_start FROM egw_cal_dates > icd WHERE icd.cal_id = cd.cal_id AND icd.cal_start = cd.cal_start AND > icd.cal_start <> 0), 0) > ~ 450 seconds I don't know, but why are you using such an expression instead of an outer join? -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support