From: | Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: some grammar refactoring |
Date: | 2020-05-25 19:09:52 |
Message-ID: | 27D5539A-7278-4548-81B9-4F04989A24D7@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> On May 25, 2020, at 2:55 AM, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:
>
> On 2020-05-22 18:53, Mark Dilger wrote:
>> I like the general direction you are going with this, but the decision in v1-0006 to move the error for invalid object types out of gram.y and into extension.c raises an organizational question. At some places in gram.y, there is C code that checks parsed tokens and ereports if they are invalid, in some sense extending the grammar right within gram.y. In many other places, including what you are doing in this patch, the token is merely stored in a Stmt object with the error checking delayed until command processing. For tokens which need to be checked against the catalogs, that decision makes perfect sense. But for ones where all the information necessary to validate the token exists in the parser, it is not clear to me why it gets delayed until command processing. Is there a design principle behind when these checks are done in gram.y vs. when they are delayed to the command processing? I'm guessing in v1-0006 that you are doing it this way because there are multiple places in gram.y where tokens would need to be checked, and by delaying the check until ExecAlterExtensionContentsStmt, you can put the check all in one place. Is that all it is?
>
> We have been for some time moving to a style where we rely on switch statements around OBJECT_* constants to (a) decide what is allowed with certain object types, and (b) make sure we have an explicit decision on each object type and don't forget any. This has worked well, I think.
Yes, I think so, too. I like that overall design.
> This is more of that.
Yes, it is.
> Before this patch, it would have been pretty hard to find out which object types are supported with extensions or security labels, except by very carefully reading the grammar.
Fair enough.
> Moreover, you now get a proper error message for unsupported object types rather than just a generic parse error.
Sounds great.
>> I have had reason in the past to want to reorganize gram.y to have all these types of checks in a single, consistent format and location, rather than scattered through gram.y and backend/commands/. Does anybody else have an interest in this?
>> My interest in this stems from the fact that bison can be run to generate data files that can then be used in reverse to generate random SQL. The more the parsing logic is visible to bison, the more useful the generated data files are. But a single, consistent design for extra-grammatical error checks could help augment those files fairly well, too.
>
> It's certainly already the case that the grammar accepts statements that end up being invalid, even if you ignore catalog lookup. I don't think my patch moves the needle on this in a significant way.
I don't think it moves the needle too much, either. But since your patch is entirely a refactoring patch and not a feature patch, I thought it would be fair to ask larger questions about how the code should be structured. I like using enums and switch statements and getting better error messages, but there doesn't seem to be any fundamental reason why that should be in the command execution step. It feels like a layering violation to me.
I don't object to this patch getting committed. A subsequent patch to consolidate all the grammar checks into src/backend/parser and out of src/backend/commands won't be blocked by this.
—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From | Date | Subject | |
---|---|---|---|
Next Message | Chapman Flack | 2020-05-25 19:15:48 | what can go in root.crt ? |
Previous Message | David Gilman | 2020-05-25 18:54:29 | Re: Warn when parallel restoring a custom dump without data offsets |