Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THiFn-0006cN-L7 for pgsql-performance@postgresql.org; Fri, 28 Sep 2012 21:37:47 +0000 Received: from smtp2.peak6.com ([38.98.137.9]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1THiFj-0000pT-ER for pgsql-performance@postgresql.org; Fri, 28 Sep 2012 21:37:46 +0000 X-AuditID: 0a02cb1e-b7f486d000006aaa-83-506617cb57bd Message-ID: <506618A4.70706@optionshouse.com> Date: Fri, 28 Sep 2012 16:37:40 -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: Tom Lane CC: "pgsql-performance@postgresql.org" Subject: Re: Possible Performance Regression with Transitive Comparisons vs. Constants References: <5065F910.5040504@optionshouse.com> <14848.1348864525@sss.pgh.pa.us> In-Reply-To: <14848.1348864525@sss.pgh.pa.us> 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+NgFrrPIsWRmVeSWpSXmKPExsXClcIrpntaPC3A4P93A4vrM88xW5xadZfJ gcnjwr5p7B6Lnm1kCWCKamC0SczLyy9JLElVSEktTrZV8i8oyczPK/bILy1OVXDJLE7OSczM TS1SUshMsVUyV1IoyElMTs1NzSuxVUosKEjNS1Gy41LAADZAZZl5Cql5yfkpmXnptkqewf66 FhamlrqGSnbxyCChkyXj9ovjjAXv+Cs+7ZrD3sB4iKeLkZNDQsBE4tC//8wQtpjEhXvr2UBs XgFdiTP3f7CA2CwCqhKzvp4Es9mA4pP6V4DVCAmoSPSdvcEEYvMLCEvs+9AENkdUIEhi2cbv TBBzBCVOznwC1isioCDR9+AdO4jNLOAp0XFqFSOILSyQJDH/8G8miJkBEhOmPAObwwm06//L 34wQ9bYSF+ZcZ4Gw5SW2v53DDFGvKrGieSIbxP0KEv+vvGOawCg0C8nqWUjaZyFpX8DIvIpR vLgsMTkj06ygOLekwFCvIDUx20wvL7VkEyMocplOy+1gXHFB8RCjAAejEg/vxOupAUKsiWXF lbmHGCU4mJVEeDOKgUK8KYmVValF+fFFpTmpxYcYTYFhNpFZSjQ5H5hU8kriDY0NLU0tTcws zY2NDZTEeRX6lAKEBNKBySE7NbUgtQimj4mDU6qBcZUH42efirwdc20vreONZrxzXUTg+0/2 giWXv3vYR845tNvWf0Pvcj8Lac6MLJmVMxYtjOn5tVZ2dVv4+79pPtYVbxzlrxb8uXFmWptX 0Su5Sw1sXa8vML7a4M526e7Hsg/tNp6VF+yVwxcFHLiRznJi8kFHU8vznSz/ghd3/fU5eUc3 y/5isBJLcUaioRZzUXEiAK+ChKvyAgAA X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/203 X-Sequence-Number: 47949 On 09/28/2012 03:35 PM, Tom Lane wrote: > 9.1.what? For me, 8.2.23 and 9.1.6 produce the same plan and just > about the same runtime for your query 1. I withdraw that part of my question. I apparently didn't look closely enough at the actual output. I was basing the version assumption on the query speed on the new server, when it was probably due to cache effects. The first part of the question stands, though... Why isn't the optimizer substituting these values? a.created_date should be exactly equivalent to '2012-05-05', but it's clearly not being treated that way. With the full substitutions, I'm seeing things like this: http://explain.depesz.com/s/3T4 With the column names, it's this: http://explain.depesz.com/s/Fq7 This is on 8.2, but the behavior is the same on 9.1. From 130s to 23s simply by substituting the constant wherever the column name is encountered. For reference, the queries are, slow: select a.id, f.ezorder_id from reporting.account a join ezorder f on f.account_id = a.account_id where a.process_date = '2012-09-27' and f.date_created between a.process_date - interval '6 months' and a.process_date and a.row_out is null And fast: select a.id, f.ezorder_id from reporting.account a join ezorder f on f.account_id = a.account_id where a.process_date = '2012-09-27' and f.date_created between '2012-09-27'::date - interval '6 months' and '2012-09-27' and a.row_out is null We discovered this during the upgrade, but it seems to equally apply to both 8.2 and 9.1. I've been telling the devs to replace any of these they find all day. I can't quite say why we never "noticed" this before, but it got exposed today pretty plainly. If this were a compiler, I'd have expected it to treat the values as equivalent, but that's clearly not what's happening. -- 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