Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THg9P-0003nz-Ru for pgsql-performance@postgresql.org; Fri, 28 Sep 2012 19:23:03 +0000 Received: from smtp2.peak6.com ([38.98.137.9]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THg9M-0007Gf-83 for pgsql-performance@postgresql.org; Fri, 28 Sep 2012 19:23:03 +0000 X-AuditID: 0a02cb1e-b7f7d6d000003898-7e-5065f8374da0 Message-ID: <5065F910.5040504@optionshouse.com> Date: Fri, 28 Sep 2012 14:22:56 -0500 From: Shaun Thomas Reply-To: Organization: Peak6 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: Possible Performance Regression with Transitive Comparisons vs. Constants Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.201.64] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsXClcIrpmvxIzXAYNtTDovrM88xOzB6XNg3 jT2AMaqB0SYxLy+/JLEkVSEltTjZVsm/oCQzP6/YI7+0OFXBJbM4OScxMze1SEkhM8VWyVxJ oSAnMTk1NzWvxFYpsaAgNS9FyY5LAQPYAJVl5imk5iXnp2TmpdsqeQb761pYmFrqGirZxSOD hE6WjI7ub4wFbwUqHu7aydjAOJ+3i5GDQ0LAROLXfM0uRk4gU0ziwr31bCA2r4C+xOJdr5lB bBYBVYkrW9oZQWw2AV2JSf0rwGqEBFQk+s7eYAKx+QWEJfZ9aAKrFxUIkli28TsTxBxBiZMz n7CA2CICnhKz928Ds4WBam5fegdWzyxgK3FhznUWCFteYvvbOcwQ81UlVjRPZIO4TUHi/5V3 TBMY+WchGTsLSfssJO0LGJlXMYoXlyUmZ2SaFRTnlhQY6hWkJmab6eWllmxiBMUW02m5HYwr LigeYhTgYFTi4Z14PTVAiDWxrLgy9xCjBAezkghvRjFQiDclsbIqtSg/vqg0J7X4EKMpMDwm MkuJJucD4z6vJN7Q2NDS1NLEzNLc2NhASZxXoU8pQEggHRjT2ampBalFMH1MHJxSDYxyM9g/ /pB1W7bkftEek6r5TDl2jquTnvZ9c1PMKZXK+XBcrWLx5gPr/4tc3/TbbeHR8/u9M8xeb+63 felrmOs7+/rspi8f0uImtXqs3plssVBw/bKMyOVtPMH7f5/eeUo7zJq/Xsj2mett33u3lZtD Dtz7WH+/zaHy4XL96q9OBXsYtP4Ka/xSYinOSDTUYi4qTgQALrCW0cMCAAA= X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/200 X-Sequence-Number: 47946 Hey guys, I ran into this while we were working on an upgrade project. We're moving from 8.2 (don't ask) to 9.1, and started getting terrible performance for some queries. I've managed to boil it down to a test case: create temp table my_foo as select a.id, '2012-01-01'::date + (random()*365)::int AS created_dt from generate_series(1,5000) as a(id); create temp table my_bar as select b.id, (random()*4999)::int + 1 as aid, '2012-01-01'::date + (random()*365)::int AS created_dt from generate_series(1,500000) as b(id); analyze my_foo; analyze my_bar; create index idx_foo_id on my_foo (id); create index idx_foo_const on my_foo (created_dt); create index idx_bar_id on my_bar(id); create index idx_bar_aid on my_bar(aid); create index idx_bar_const on my_bar (created_dt); Ok, simple enough, right? Now do this: explain analyze select b.* from my_foo a, my_bar b where a.created_dt = '2012-05-05' and b.created_dt between a.created_dt and a.created_dt + interval '1 month'; explain analyze select b.* from my_foo a, my_bar b where a.created_dt = '2012-05-05' and b.created_dt between '2012-05-05' and '2012-05-05'::date + interval '1 month'; These do not create the same query plan, which itself is odd. But the other thing, is that query 1 is about 4-8x slower than query 2, but only when I test it on PostgreSQL 9.1. When I test it on 8.2 (eww) they're about equal in performance. I should note that the plan for both cases in 8.2, performs better than query 1 in 9.1. So I've got two questions: 1. Is it normal for trivially equal values to be non-optimal like this? 2. What on earth happened between 8.2 and 9.1 that made performance worse for this test case? Just to address any questions, I've tested this in multiple environments, and it's always consistent. 9.1 performs worse than 8.2 here, so long as you rely on PostgreSQL to make the equivalence instead of doing it manually. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 500 | Chicago IL, 60604 312-444-8534 sthomas@optionshouse.com ______________________________________________ See http://www.peak6.com/email_disclaimer/ for terms and conditions related to this email