Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eiLh1-0004GV-PW for pgsql-performance@arkaria.postgresql.org; Sun, 04 Feb 2018 14:54:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eiLh0-0003JU-5T for pgsql-performance@arkaria.postgresql.org; Sun, 04 Feb 2018 14:54:54 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eiLgz-0003JL-Rc for pgsql-performance@lists.postgresql.org; Sun, 04 Feb 2018 14:54:53 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eiLgw-0000ue-RB for pgsql-performance@lists.postgresql.org; Sun, 04 Feb 2018 14:54:52 +0000 Received: from [192.168.222.106] (p5B31311B.dip0.t-ipconnect.de [91.49.49.27]) by mail.i-mark.de (Postfix) with ESMTPSA id 9AC2B158018E for ; Sun, 4 Feb 2018 15:54:37 +0100 (CET) Authentication-Results: loft7616.startdedicated.de; spf=pass (sender IP is 91.49.49.27) smtp.mailfrom=andreas@a-kretschmer.de smtp.helo=[192.168.222.106] Received-SPF: pass (loft7616.startdedicated.de: connection is authenticated) Subject: Re: postgresql 10.1 wrong plan in when using partitions bug To: pgsql-performance@lists.postgresql.org References: From: Andreas Kretschmer Message-ID: Date: Sun, 4 Feb 2018 15:54:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am 04.02.2018 um 13:19 schrieb Mariel Cherkassky: > I checked the plan of the next query : > explain select count(*) from log_full where end_date between > to_date('2017/12/03','YY/MM/DD') and to_date('2017/12/03','YY/MM/DD'); > can you rewrite the query to ... where end_date between '2017/12/03' and '2017/12/03' simple test-case: test=*# \d+ t                                    Table "public.t"  Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+------+-----------+----------+---------+---------+--------------+-------------  d      | date |           |          |         | plain |              | Partition key: RANGE (d) Partitions: t_01 FOR VALUES FROM ('2018-02-04') TO ('2018-02-05'),             t_02 FOR VALUES FROM ('2018-02-05') TO ('2018-02-06') test=*# explain analyse select * from t where d between to_date('2018/02/04','YY/MM/DD') and to_date('2018/02/04','YY/MM/DD');                                                            QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------  Append  (cost=0.00..122.00 rows=26 width=4) (actual time=0.006..0.006 rows=0 loops=1)    ->  Seq Scan on t_01  (cost=0.00..61.00 rows=13 width=4) (actual time=0.004..0.004 rows=0 loops=1)          Filter: ((d >= to_date('2018/02/04'::text, 'YY/MM/DD'::text)) AND (d <= to_date('2018/02/04'::text, 'YY/MM/DD'::text)))    ->  Seq Scan on t_02  (cost=0.00..61.00 rows=13 width=4) (actual time=0.001..0.001 rows=0 loops=1)          Filter: ((d >= to_date('2018/02/04'::text, 'YY/MM/DD'::text)) AND (d <= to_date('2018/02/04'::text, 'YY/MM/DD'::text)))  Planning time: 0.241 ms  Execution time: 0.042 ms (7 rows) test=*# explain analyse select * from t where d between '2018/02/04' and '2018/02/04';                                               QUERY PLAN ------------------------------------------------------------------------------------------------------  Append  (cost=0.00..48.25 rows=13 width=4) (actual time=0.005..0.005 rows=0 loops=1)    ->  Seq Scan on t_01  (cost=0.00..48.25 rows=13 width=4) (actual time=0.004..0.004 rows=0 loops=1)          Filter: ((d >= '2018-02-04'::date) AND (d <= '2018-02-04'::date))  Planning time: 0.203 ms  Execution time: 0.030 ms (5 rows) test=*# maybe the planner should be smart enough to do that for you, but obvously he can't. So it's a workaround, but it seems to solve the problem. Regards, Andreas -- 2ndQuadrant - The PostgreSQL Support Company. www.2ndQuadrant.com