Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcanS-0000ze-U6 for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 18:54:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcanQ-0006Cn-4c for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 18:54:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcanP-00067z-QQ for pgsql-hackers@lists.postgresql.org; Thu, 27 Dec 2018 18:54:15 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcanI-00044B-6Y for pgsql-hackers@postgresql.org; Thu, 27 Dec 2018 18:54:14 +0000 Received: by mail-yb1-xb29.google.com with SMTP id q2so640927ybd.12 for ; Thu, 27 Dec 2018 10:54:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=6pa2r2RojwiiZQ2z8u+x07cbU2D5eJrLpsXZgMr62NU=; b=kkQBwVumCWbIRqnBRi3DrGuVMg948k3oPnlpdy7n9mFqtmVgjBdHD9HvOBbuUenKXE TQssi/9DJJ2XGg7wM4IhdZ7fVTy9EbFId0JGVOM3vyyC3bhHHOTBMMbK40/HhZB8a6Cs rbUPFetsbKwHNMWvv3MckOSJAIE3sSF2eSHkIlyKwIbuAu2w4HQ4Zcek0fiFo4VThLtE hCFclGEM7X9WKCa2odzLz82bma7cyeMuqYR9XjsUyPzLBDh/7NoX6raCQLJI5JhTVxiM Sju0MQ3mtyU6BeDiYgPs9eJXxal6CFe76T45N3EnnBN4jHhXWCIfRP+uDlJ8oRychNbO 4Fyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=6pa2r2RojwiiZQ2z8u+x07cbU2D5eJrLpsXZgMr62NU=; b=QIPkcCcLup3YsCwdUWk/h2SGSaGK14yCB6CqDph/g9t4Al/vPqKcwjJppMf9Hkd4ZS or1TmGAJzf1Af7djAzFtghnBO6nxhZ8vJ+uzRH0O1yE2/eDbLWv14fRG7mukGKP2EuI2 q2alRTXaTWi2PnD9MRKSMJ00WcefWxlpK4bxNVM1IfIJBZZC6N5pNe1obHuIHj5I35VB Dl0KXMAn7QxWp7t2wt6nJJZ2RVTeZOO4V6ON1e8yPneyQBFuV5o3ILFJe/aN07EoWx1F TunWa5DL+5px5D1gnC2hFIOb87W6/79qFMGQQZ7XNPnIgwKmXC5MnXkxT29L7/tJFeme Vm9g== X-Gm-Message-State: AA+aEWYW+bGzD/CNWmf9tzno3YRGP3yU6ECc3btWt5geiaNMeIW6QrQK k1JT7Bihf2QqQXA9PTr/+LzdHSK1CqWunnuWGqfwGyNs6UYoQEjwU7jexeJeqiCY7f/8wVHkmEf ytC4q1cChVLmx9aRD8wDEDQ0oABRUWcjcp+AoxDMts9TjLw5DcfpLfJL3D45QdwbVysG6IMV4Xh nrH8ezl+fbeY+T X-Google-Smtp-Source: ALg8bN6R5MTGTh7TKSLH6At1KGwVCNKfidZsjY+n7eOsSTqk3dUWsneEFl3X8DnyAkHuajAewlye3A== X-Received: by 2002:a25:1585:: with SMTP id 127-v6mr25184244ybv.208.1545936846906; Thu, 27 Dec 2018 10:54:06 -0800 (PST) Received: from [192.168.10.146] ([98.122.175.38]) by smtp.gmail.com with ESMTPSA id k127sm4120756ywa.81.2018.12.27.10.54.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Dec 2018 10:54:06 -0800 (PST) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: reducing the footprint of ScanKeyword (was Re: Large writable variables) To: Tom Lane , Andres Freund Cc: Robert Haas , Andrew Gierth , John Naylor , "pgsql-hackers@postgresql.org" References: <31505.1545149557@sss.pgh.pa.us> <87lg4luimz.fsf@news-spur.riddles.org.uk> <20181220010114.k3wv6r25sc7sr7z5@alap3.anarazel.de> <28725.1545841359@sss.pgh.pa.us> <20181226180217.qad6ahkkzk4g5poy@alap3.anarazel.de> <4585.1545851037@sss.pgh.pa.us> <20181227131953.fnspabit3lq56lej@alap3.anarazel.de> <4029.1545930759@sss.pgh.pa.us> Openpgp: preference=signencrypt Autocrypt: addr=andrew.dunstan@2ndQuadrant.com; prefer-encrypt=mutual; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNL0FuZHJldyBEdW5zdGFuIDxhbmRyZXcuZHVuc3RhbkAybmRRdWFkcmFudC5jb20+wsCY BBMBAgBCAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAUJDyV6hBYhBOQ+WEYd/Hy/RGkV pZn6f8tZ/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Nj3I c5/fFJsmxljbnaDbXPcnFsur1Oo9mIHFakgWgOBMuxoWfjONiLjjLh/9+ZIqSSLX Message-ID: Date: Thu, 27 Dec 2018 13:54:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <4029.1545930759@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/27/18 12:12 PM, Tom Lane wrote: >> I don't buy that we're inable to write a descent parser that way. > I do not think that we could write one for the current state of the > PG grammar without an investment of effort so large that it's not > going to happen. Even if such a parser were to spring fully armed > from somebody's forehead, we absolutely cannot expect that it would > continue to work correctly after non-wizard contributors modify it. I just did a quick survey of generator tools. Unfortunately, the best candidate alternative (ANTLR) no longer supports generating plain C code. I don't know of another tool that is well maintained, supports C, and generates top down parsers. Twenty-five years ago or so I wrote a top-down table-driven parser generator, but that was in another country, and besides, the wench is dead. There are well known techniques (See s 4.4 of the Dragon Book, if you have a copy) for formal analysis of grammars to determine predictive parser action. They aren't hard, and the tables they produce are typically much smaller than those used for LALR parsers. Still, probably not for the faint of heart. The tools that have moved to using hand cut RD parsers have done so precisely because they get a significant performance benefit from doing so. RD parsers are not terribly hard to write. Yes, the JSON grammar is tiny, but I think I wrote the basics of the RD parser we use for JSON in about an hour. I think arguing that our hacker base is not competent to maintain such a thing for the SQL grammar is wrong.  We successfully maintain vastly more complex pieces of code. Having said all that, I don't intend to spend any time on implementing an alternative parser. It would as you say involve a heck of a lot of time, which I don't have. It would be a fine academic research project for some student. A smaller project might be to see if we can replace the binary keyword search  in ScanKeyword with a perfect hashing function generated by gperf, or something similar. I had a quick look at that, too. Unfortunately the smallest hash table I could generate for our 440 symbols had 1815 entries, so I'm not sure how well that would work. Worth investigating, though. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services