Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1asRrN-0007dR-4A for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Apr 2016 09:22:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1asRrM-0004Sq-H9 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Apr 2016 09:22:16 +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 1asRq0-0002yK-Ed for pgsql-hackers@postgresql.org; Tue, 19 Apr 2016 09:20:52 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1asRpv-00046K-VN for pgsql-hackers@postgresql.org; Tue, 19 Apr 2016 09:20:51 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 48B5021C7E02; Tue, 19 Apr 2016 12:20:46 +0300 (MSK) Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B6eIPBJdqq4S; Tue, 19 Apr 2016 12:20:44 +0300 (MSK) Received: from fujitsu (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 6896721C7DEF; Tue, 19 Apr 2016 12:20:44 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1461057644; bh=6s6gt7Mj2k3W5TfUMpvC1tCH2gbvX5jxuN8TIGY2aPI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=AJYRBa/DRI7gklvwld5oXRZyD5NPgVZIBFDmeV6ju4xzf68SHuMInps0lSvyBXR4w 6aUMBm7zEU+m4I6DK6/PFfSlXZhZp9teqWCLH16fIkIX97mjIHIm7xDAY6dhNgCTB5 oBTOiKAlQreRqMtrqAa5VsZwFPqNwFFn8FBGI5g4= Date: Tue, 19 Apr 2016 12:20:03 +0300 From: Aleksander Alekseev To: Pavel Stehule Cc: Tom Lane , Arcadiy Ivanov , PostgreSQL Hackers Subject: Re: Parser extensions (maybe for 10?) Message-ID: <20160419122003.731704b2@fujitsu> In-Reply-To: References: <570C7B5A.9070309@gmail.com> <5688.1460437831@sss.pgh.pa.us> <20160418182523.3f70ad88@fujitsu> <20160418184458.51f203ab@fujitsu> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -3.0 (---) 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 > no - it is not possible. Not with Bison parser - it cannot work with > unknown syntax - so isn't possible implement one part by parser A, and > second part by parser B. > > But we can parsers P1 and P2. P1 knows string XX, P2 knows YY. Buildin > parser (BP) knows SQL > > We can have registered parsers P1, P2, BP. > > for string SELECT > > P1 fails, > P2 fails, > BP processes it > > for string YY > > P1 fails, > P2 process it, > BP is not called > > But transformations can be allowed too (but it is slower) > > for string ZZZZ > > P1 does transformation to YYY > P2 does transformation to SELECT > BP processes it I look on this a little bit differently. Current pipeline is approximately like this: ``` query string -> LEX -> [lexemes] -> SYNT -> QueryAST -> PLANNER ``` Or in Haskell-like notation: ``` lex :: String -> [Lexeme] synt :: [Lexeme] -> AST ``` Its reasonably simple to extend a lexer. Lets say that AST type doesn't change, i.e. extensions provide only syntax sugar. After desugaring query transforms to old-good SELECT, UPDATE, procedures calls, etc. In this case what extension does is actually: ``` type Parser = [Lexeme] -> AST extendParser :: Parser -> Parser ``` Can we guarantee that extensions don't conflict? In fact we can since we already do it. If all tests pass there is no conflict. The only tricky part I see is that sometimes we want: ``` extendParser1 ( extendParser2 ( default )) ``` ... and sometimes: ``` extendParser2 ( extendParser1 ( default )) ``` I don't think that order of extension will matter most of the time. But we still should provide a mechanism to change this order. For instance, contribs could provide a default priority of parser extension. Extensions with higher priority are applied first. Also user can resolve conflicts by manually overriding these priorities: ``` select pg_parser_extension_priorities(); select pg_override_parser_extension_priority('some_extension', 100500); ``` I think it should work. Thought? -- Best regards, Aleksander Alekseev http://eax.me/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers