Re: Materialized views WIP patch

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Marko Tiikkaja <pgmail(at)joh(dot)to>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Materialized views WIP patch
Date: 2013-02-20 16:20:41
Message-ID: 7366.1361377241@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Kevin Grittner <kgrittn(at)ymail(dot)com> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Having said that, I don't think I believe your analysis of why
>> this doesn't work.

> Well, it wouldn't be the first time you've seen a better way to do
> something in flex than I was able to see. Taking just the gram.y
> part of the change which implemented this, and omitting the change
> in reservedness of MATERIALIZED, I have:

> - TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
> + TRUNCATE trunc_type relation_expr_list opt_restart_seqs opt_drop_behavior

> +trunc_type:
> + TABLE { $$ = OBJECT_TABLE; }
> + | MATERIALIZED VIEW { $$ = OBJECT_MATVIEW; }
> + | /*EMPTY*/ { $$ = OBJECT_UNSPECIFIED; }
> + ;

Yeah, this is a standard gotcha when working with unreserved keywords.
You can't factor it like that because then the parser is required to
make a shift-reduce decision (on whether to reduce trunc_type to empty)
before it can "see past" the first word. So for instance given

TRUNCATE MATERIALIZED ...
^

the parser has to make that decision when it can't see past the word
"MATERIALIZED" and so doesn't know what comes after it.

The way to fix it is to not try to use the sub-production but spell it
all out:

TRUNCATE TABLE relation_expr_list ...
| TRUNCATE MATERIALIZED VIEW relation_expr_list ...
| TRUNCATE relation_expr_list ...

Now the parser doesn't have to make any shift-reduce decision until
after it can "see past" the first identifier. It's a bit tedious
but beats making a word more reserved than it has to be.

regards, tom lane

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Kevin Grittner 2013-02-20 16:26:10 Re: Materialized views WIP patch
Previous Message Kevin Grittner 2013-02-20 15:28:25 Re: Materialized views WIP patch

Browse pgsql-hackers by date

  From Date Subject
Next Message Misa Simic 2013-02-20 16:25:41 Altering Views
Previous Message Heikki Linnakangas 2013-02-20 16:02:05 Re: streaming header too small