Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2FB62C24695 for ; Fri, 30 Dec 2011 12:23:40 -0400 (AST) Received: from meteor.mejor.pl ([2001:470:1f15:1b61::2]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RgfF4-0005nw-La for pgsql-performance@postgresql.org; Fri, 30 Dec 2011 16:23:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mejor.pl; s=cokolwiek; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Subject:To:MIME-Version:From:Date:Message-ID; bh=H7ue5McxoIBS699aVWNit4oMZyepnTmqDod0A7YNd0A=; b=SQg5KyQ5H+CsBu8iYwsqGlRJ57YyItZeEYqQxpQySKBw4Yk1m6G3IGjCVq00o326JA11HHqAaqcN1SR3cXAGyMVWTek686beIlWrzMjW+0CU1B2QNP1G6g78Eda6xiDb; Received: from cadera.waw.pl ([62.121.127.119] helo=[192.168.138.46]) by meteor.mejor.pl with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.77) (envelope-from ) id 1RgfEr-000B6Q-T0 for pgsql-performance@postgresql.org; Fri, 30 Dec 2011 17:23:26 +0100 Message-ID: <4EFDE57D.6090303@mejor.pl> Date: Fri, 30 Dec 2011 17:23:25 +0100 From: =?UTF-8?B?TWFyY2luIE1pcm9zxYJhdw==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111214 Thunderbird/8.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: partitioned table: differents plans, slow on some situations References: <00842f17-90cb-4154-8be0-a49379514739@zimbra1.ovus.it> In-Reply-To: <00842f17-90cb-4154-8be0-a49379514739@zimbra1.ovus.it> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -3.3 (---) X-Archive-Number: 201112/206 X-Sequence-Number: 46005 W dniu 30.12.2011 17:01, Matteo Sgalaberni pisze: > Hi, Hello, > I have a two tables that are partitioned by month. > > I have different results for the same query (query A/query B), the only thing that differ from A and B is the customer id. Not only: > Query A: > > SELECT sms.id AS id_sms > > FROM > sms_messaggio AS sms, > sms_messaggio_dlr AS dlr > WHERE sms.id = dlr.id_sms_messaggio > AND sms.timestamp_todeliver >= '1/3/2010'::timestamp > AND sms.timestamp_todeliver < '30/4/2010'::timestamp > AND dlr.timestamp_todeliver >= '1/3/2010'::timestamp > AND dlr.timestamp_todeliver < '30/4/2010'::timestamp > AND sms.id_cliente = '13' > ORDER BY dlr.timestamp_todeliver DESC LIMIT 50; ^^^^^^^ > Query B: > EXPLAIN ANALYZE SELECT sms.id AS id_sms, > dlr.msisdn, > to_char(dlr.timestamp_stato,'DD/MM/YYYY HH24:MI:SS') AS timestamp_stato, > dlr.stato, > dlr.id AS id_dlr, > dlr.numero_pdu, > dlr.costo_cli > FROM > sms_messaggio AS sms, > sms_messaggio_dlr AS dlr > WHERE sms.id = dlr.id_sms_messaggio > AND sms.timestamp_todeliver >= '1/3/2010'::timestamp > AND sms.timestamp_todeliver < '30/4/2010'::timestamp > AND dlr.timestamp_todeliver >= '1/3/2010'::timestamp > AND dlr.timestamp_todeliver < '30/4/2010'::timestamp > AND sms.id_cliente = '7' > ORDER BY dlr.timestamp_todeliver ASC LIMIT 50; ^^^^^ > I'm using pg 9.1 > > Can someone explain me why the planner do this? Those queries are diffrent. Regards.