Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 9BE121BA1319 for ; Thu, 5 Apr 2012 09:43:57 -0300 (ADT) Received: from mxin.ulb.ac.be ([164.15.128.112]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SFm2a-0002PE-V9 for pgsql-sql@postgresql.org; Thu, 05 Apr 2012 12:43:57 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBACaTfU+kD30E/2dsb2JhbAANNYV8tg0BAQEEI1URCxgJFgsCAgIHAwIBAgFFEwgBAbR2iwmNNoIMgRgEjmuBI4s6jUA Received: from bebif01.ulb.ac.be (HELO [10.0.0.194]) ([164.15.125.4]) by smtp.ulb.ac.be with ESMTP; 05 Apr 2012 14:43:39 +0200 Message-ID: <4F7D937B.6080908@ulb.ac.be> Date: Thu, 05 Apr 2012 14:43:39 +0200 From: Julien Cigar Organization: Belgian Biodiversity Platform User-Agent: Mozilla/5.0 (X11; FreeBSD i386; rv:10.0.2) Gecko/20120314 Thunderbird/10.0.2 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: bad plan References: <4F7D843E.4060304@ulb.ac.be> <4F7D89F5.7090301@gmail.com> <4F7D8B3F.1030402@ulb.ac.be> <4F7D90C0.3090800@gmail.com> In-Reply-To: <4F7D90C0.3090800@gmail.com> Content-Type: multipart/mixed; boundary="------------080607020901090209080102" X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201204/13 X-Sequence-Number: 36490 This is a multi-part message in MIME format. --------------080607020901090209080102 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Mario, Setting it to > -1, or even removing the condition doesn't change anything .. the problem is more that the estimate of the join point sucks pretty much .. Julien On 04/05/2012 14:32, Mario Dankoor wrote: > Julien, > > I generally try avoid NOT predicates. > If your geo_id is an integer, try geo_id > -1 > or if it's a varchar geo_id > ''. > The idea is that geo_id > 0 is false for null values. > > I don't think query optimizers are fond of NOT predicates. > > SELECT t_geo.frequence > ,ST_SetSRID(gc.geom, 4326) as geom > FROM ( > SELECT geo_id > ,count(*) AS frequence > FROM hit.context_to_context_links > WHERE geo_id > -1 > AND taxon_id= ANY ( > SELECT taxon_id > FROM rab.ancestors > WHERE ancestors.subphylum_id = 18830 > ) GROUP BY geo_id > ) as t_geo > JOIN hit.geo_candidates gc > ON gc.id = t_geo.geo_id; > > > > > > > > > > On 2012-04-05 2:08 PM, Julien Cigar wrote: >> SELECT >> t_geo.frequence, ST_SetSRID(gc.geom, 4326) as geom >> FROM ( >> SELECT >> geo_id , count(*) AS frequence >> FROM >> hit.context_to_context_links >> WHERE >> NOT geo_id IS NULL ANDtaxon_id= ANY ( >> SELECT >> taxon_id >> FROM >> rab.ancestors >> WHERE >> ancestors.subphylum_id = 18830 >> ) GROUP BY geo_id >> ) as t_geo >> JOIN >> hit.geo_candidates gc ON gc.id = t_geo.geo_id; > > -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. --------------080607020901090209080102 Content-Type: text/x-vcard; charset=utf-8; name="jcigar.vcf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="jcigar.vcf" YmVnaW46dmNhcmQNCmZuOkp1bGllbiBDaWdhcg0KbjpDaWdhcjtKdWxpZW4NCm9yZztxdW90 ZWQtcHJpbnRhYmxlOkJlbGdpYW4gQmlvZGl2ZXJzaXR5IFBsYXRmb3JtO1VMQiAoVW5pdmVy c2l0PUMzPUE5IExpYnJlIGRlIEJydXhlbGxlcykNCmFkcjo7OztCcnVzc2Vsczs7O0JlbGdp dW0NCmVtYWlsO2ludGVybmV0OmpjaWdhckB1bGIuYWMuYmUNCnRlbDt3b3JrOiszMigwKTI2 NTA1NzUyDQp4LW1vemlsbGEtaHRtbDpGQUxTRQ0KdXJsOmh0dHA6Ly93d3cuYmlvZGl2ZXJz aXR5LmJlDQp2ZXJzaW9uOjIuMQ0KZW5kOnZjYXJkDQoNCg== --------------080607020901090209080102--