Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpMFw-0006Z6-7W for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Sep 2016 21:19:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bpMFv-0005XD-Oc for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Sep 2016 21:19:07 +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 1bpMFu-0005WO-2A for pgsql-hackers@postgresql.org; Wed, 28 Sep 2016 21:19:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bpMFr-0002y0-Cv for pgsql-hackers@postgresql.org; Wed, 28 Sep 2016 21:19:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u8SLIpMk029143; Wed, 28 Sep 2016 17:18:52 -0400 From: Tom Lane To: Artur Zakirov cc: Pavel Stehule , Robert Haas , "David G. Johnston" , Alex Ignatov , Bruce Momjian , amul sul , PostgreSQL-development Subject: Re: Bug in to_timestamp(). In-reply-to: References: <1873520224.1784572.1465833145330.JavaMail.yahoo.ref@mail.yahoo.com> <1873520224.1784572.1465833145330.JavaMail.yahoo@mail.yahoo.com> <884791796.213185.1466667686999.JavaMail.yahoo@mail.yahoo.com> <20160623133001.GF21246@momjian.us> <1877e60a-a970-18b5-453c-e342f96150e6@postgrespro.ru> <31915.1466703655@sss.pgh.pa.us> <32684.1466704957@sss.pgh.pa.us> <734e50cd-c563-4afd-d1c8-80f244b3265e@postgrespro.ru> Comments: In-reply-to Artur Zakirov message dated "Thu, 11 Aug 2016 12:46:28 +0300" Date: Wed, 28 Sep 2016 17:18:51 -0400 Message-ID: <29142.1475097531@sss.pgh.pa.us> X-Pg-Spam-Score: -4.9 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Artur Zakirov writes: > - now DCH_cache_getnew() is called after parse_format(). Because now > parse_format() can raise an error and in the next attempt > DCH_cache_search() could return broken cache entry. I started looking at your 0001-to-timestamp-format-checking-v4.patch and this point immediately jumped out at me. Currently the code relies ... without any documentation ... on no elog being thrown out of parse_format(). That's at the very least trouble waiting to happen. There's a hack to deal with errors from within the NUMDesc_prepare subroutine, but it's a pretty ugly and underdocumented hack. And what you had here was randomly different from that solution, too. After a bit of thought it seemed to me that a much cleaner fix is to add a "valid" flag to the cache entries, which we can leave clear until we have finished parsing the new format string. That avoids adding extra data copying as you suggested, removes the need for PG_TRY, and just generally seems cleaner and more bulletproof. I've pushed a patch that does it that way. The 0001 patch will need to be rebased over that (might just require removal of some hunks, not sure). I also pushed 0002-to-timestamp-validation-v2.patch with some revisions (it'd broken acceptance of BC dates, among other things, but I think I fixed everything). Since you told us earlier that you'd be on vacation through the end of September, I'm assuming that nothing more will happen on this patch during this commitfest, so I will mark the CF entry Returned With Feedback. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers