Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fsr1A-00078Q-8k for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Aug 2018 14:55:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fsr16-0001ak-RS for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Aug 2018 14:55:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fsr16-0001aT-KX for pgsql-hackers@lists.postgresql.org; Thu, 23 Aug 2018 14:55:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fsr13-0001Y1-Ji for pgsql-hackers@postgresql.org; Thu, 23 Aug 2018 14:55:19 +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 w7NEtF87018471; Thu, 23 Aug 2018 10:55:15 -0400 From: Tom Lane To: Andrew Gierth cc: pgsql-hackers@postgresql.org Subject: Re: A really subtle lexer bug In-reply-to: <87ftz90yma.fsf@news-spur.riddles.org.uk> References: <87va851ppl.fsf@news-spur.riddles.org.uk> <87ftz90yma.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Mon, 20 Aug 2018 17:58:49 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18469.1535036115.1@sss.pgh.pa.us> Date: Thu, 23 Aug 2018 10:55:15 -0400 Message-ID: <18470.1535036115@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Andrew" == Andrew Gierth writes: > Andrew> I guess the fix is to extend the existing special case code > Andrew> that checks for one character left after removing trailing [+-] > Andrew> and also check for the two-character ops "<>" ">=" "<=" "=>" > Andrew> "!=". > Patch attached. > This fixes two bugs: first the mis-lexing of two-char ops as mentioned > originally; second, the O(N^3) lexing time of strings of - or + > characters is reduced to O(N^2) (in practice it's better than O(N^2) > once N gets large because the bison stack gets blown out, ending the > loop early). Looks reasonable offhand (didn't test). A couple of thoughts: * Some regression tests exercising these code paths might be a good thing. * There should likely be a comment near where EQUALS_GREATER and friends are defined, pointing out that if we add any more multi-character operators with special precedences, this code has to be taught about them. regards, tom lane