Re: some grammar refactoring

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: some grammar refactoring
Дата
Msg-id 7ba261ca-41bd-001d-632d-452446b284d2@2ndquadrant.com
обсуждение исходный текст
Ответ на Re: some grammar refactoring  (Mark Dilger <mark.dilger@enterprisedb.com>)
Ответы Re: some grammar refactoring  (Mark Dilger <mark.dilger@enterprisedb.com>)
Список pgsql-hackers
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
objecttypes out of gram.y and into extension.c raises an organizational question.   At some places in gram.y, there is
Ccode 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
withthe error checking delayed until command processing.  For tokens which need to be checked against the catalogs,
thatdecision 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
thesechecks are done in gram.y vs. when they are delayed to the command processing?  I'm guessing in v1-0006 that you
aredoing it this way because there are multiple places in gram.y where tokens would need to be checked, and by delaying
thecheck 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.

This is more of that.  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.

Moreover, you now get a proper error message for unsupported object 
types rather than just a generic parse error.

> I have had reason in the past to want to reorganize gram.y to have all these types of checks in a single, consistent
formatand 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
togenerate random SQL.  The more the parsing logic is visible to bison, the more useful the generated data files are.
Buta 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.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: password_encryption default
Следующее
От: Ranier Vilela
Дата:
Сообщение: Re: PostgresSQL 13.0 Beta 1 on Phoronix