Re: deparsing utility commands

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: deparsing utility commands
Date: 2015-03-25 17:59:54
Message-ID: 20150325175954.GL3636@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here's an updated version of this series. I have fixed many issues; in
particular the supported command set is now complete, with the only
exception being CREATE TABLE AS EXECUTE.

I went to all the prior reviews and compiled a list of unhandled issues,
on which I will be working shortly. I copied it below. I wanted to
post an updated version so in case someone wants to give this another
look while I do so.

I have changed the ALTER TABLE preparatory patch: Stephen had previously
commented that it'd be better to have it return ObjAddress rather than
Oid/attnum. I originally thought this wasn't an improvement, but after
looking again, it turns out that it is, so I changed it that way.
Things look better this way.

Note patch 0004: this modifies pg_event_trigger_dropped_objects to
report temporary objects as they are dropped. In the original coding,
all temp objects are silently ignored, but for the purposes of the
testing module of this patch, this is a problem; consider the case where
a test create a temp object, then drops it, then creates another object
with the same name. We need the sql_drop event trigger in the test
harness to report the dropped object, so that it can be dropped in the
regression_deparse database as well -- otherwise the second create
command fails because the first object still exists.

I have applied numerous other fixes.

For the first time I also include the regression test harness. To run
this, execute "make deparsecheck" in src/test/regress. This runs a
special schedule file, corresponding to serial_schedule minus the
tablespace test, and adds one test at the beginning and one test after
the end; those add event triggers to capture all commands and then run
the commands so captured in another database. The output of that is
grepped for errors; there's a very short list of errors that are always
present. Later, pg_dump is run on both databases, and the dumps are
compared. Currently there are some differences in the dumps; those
correspond to remaining issues in the deparse code. Regarding CREATE
TABLE AS EXECUTE, I had to add two "expected" files for two tests that
have an extra WARNING line when that command fails to deparse. I would
love to, instead, be able to deparse the command to something sensible.
(This is a bit brittle, because it's run from a makefile rather than
inside pg_regress; it's not pretty when things fail. Must be improved,
perhaps as a separate pg_regress binary that does all the process
control internally.)

Known remaining issues:

* Rename pg_event_trigger_get_creation_command(). Some ideas:
- pg_event_trigger_commands()
- pg_event_trigger_ddl_commands()
- pg_event_trigger_deparsed_commands()
- pg_event_trigger_deparsed_ddl_commands()

* CREATE SEQUENCE OWNED BY is not handled properly for freestanding
sequences.

* Handle default_tablespace GUC in CREATE TABLE and others.

* Handle the extension version in some way to CREATE EXTENSION.

* RENAME and others need to handle the inheritance flags (ONLY, etc)

* Many constant strings in SQL syntax ought to use a JSON object
representation with the "present" boolean thingy, instead of an empty
string as currently. That makes it easier to turn them on/off from
event triggers without forcing the user to be aware of the exact
spelling of each option.

* Should we prohibit DDL from within event triggers?

* Handle subxact aborts in ALTER TABLE processing.

* Maybe stash of commands should be an slist rather than List, just like
the dropped objects list.

* For CREATE TABLE AS, the generated command does not have a column list,
and the deparsed version might depend on temp tables for instance;
maybe we need some way to control that one from producing a normal
CREATE TABLE instead.

* The "provider" bit in SECURITY LABEL is messy. There is no Oid for
security providers, they're just loadable modules.

* event trigger currentEventTriggerContext was only being set up when
there were sql_drop/table_rewrite events; we remove that and set it up
always now. That should be restored.

* There are several XXX/FIXME/TODO comments in deparse_utility.c.

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

Attachment Content-Type Size
0001-add-secondaryOid-to-DefineTSConfiguration.patch text/x-diff 2.1 KB
0002-deparse-core-have-ALTER-TABLE-return-address-of-affe.patch text/x-diff 49.7 KB
0003-deparse-core-transform-expr-during-parse-analysis-in.patch text/x-diff 4.9 KB
0004-deparse-core-report-temp-objs-in-pg_event_trigger_dr.patch text/x-diff 11.6 KB
0005-deparse-infrastructure-needed-for-command-deparsing.patch text/x-diff 70.8 KB
0006-deparse-add-EventTriggerStashCommand-calls-to-Proces.patch text/x-diff 18.3 KB
0007-deparse-Support-CREATE-SCHEMA-TABLE-SEQUENCE-INDEX-T.patch text/x-diff 54.0 KB
0008-deparse-Support-CREATE-TYPE-AS-ENUM-RANGE.patch text/x-diff 5.0 KB
0009-deparse-Support-EXTENSION-commands.patch text/x-diff 5.7 KB
0010-deparse-Support-CREATE-RULE.patch text/x-diff 6.4 KB
0011-deparse-Support-ALTER-TYPE-ADD-VALUE-enums.patch text/x-diff 2.0 KB
0012-deparse-Support-ALTER-.-RENAME-OWNER-SCHEMA.patch text/x-diff 22.4 KB
0013-deparse-Support-CREATE-ALTER-DOMAIN.patch text/x-diff 6.8 KB
0014-deparse-Support-CREATE-ALTER-FUNCTION.patch text/x-diff 16.1 KB
0015-deparse-Support-ALTER-TABLE.patch text/x-diff 33.4 KB
0016-deparse-Support-CREATE-VIEW.patch text/x-diff 3.2 KB
0017-deparse-Support-CREATE-OPERATOR-FAMILY.patch text/x-diff 2.1 KB
0018-deparse-Support-CREATE-CONVERSION.patch text/x-diff 2.2 KB
0019-deparse-Support-DefineStmt-commands.patch text/x-diff 25.4 KB
0020-deparse-support-CREATE-CAST.patch text/x-diff 3.2 KB
0021-deparse-Support-GRANT-REVOKE.patch text/x-diff 15.1 KB
0022-deparse-support-COMMENT-ON-and-SECURITY-LABEL.patch text/x-diff 5.7 KB
0023-deparse-Handle-default-security-provider.patch text/x-diff 960 bytes
0024-deparse-support-CREATE-TABLE-AS.patch text/x-diff 6.3 KB
0025-deparse-support-CREATE-ALTER-POLICY.patch text/x-diff 4.9 KB
0026-deparse-support-REFRESH-MATERIALIZED-VIEW.patch text/x-diff 1.8 KB
0027-deparse-support-FDW-related-commands.patch text/x-diff 14.4 KB
0028-infrastructure-for-ALTER-OPERATOR-FAMILY.patch text/x-diff 6.9 KB
0029-deparse-Support-ALTER-OPERATOR-FAMILY.patch text/x-diff 8.8 KB
0030-deparse-support-ALTER-DEFAULT-PRIVILEGES.patch text/x-diff 8.9 KB
0031-deparse-support-CREATE-OPERATOR-CLASS.patch text/x-diff 11.9 KB
0032-deparse-support-CREATE-LANGUAGE.patch text/x-diff 3.1 KB
0033-deparse-infrastructure-for-ALTER-TEXT-SEARCH-CONFIG-.patch text/x-diff 9.3 KB
0034-deparse-support-ALTER-TSCONFIG.patch text/x-diff 4.6 KB
0035-deparse-test-add-pg_regress-dbname-deparse-option.patch text/x-diff 4.4 KB
0036-deparse-pg_regress-support-generate_files_only.patch text/x-diff 2.2 KB
0037-deparse-initial-testing-framework.patch text/x-diff 26.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Nasby 2015-03-25 18:03:13 Re: Exposing PG_VERSION_NUM in pg_config
Previous Message Jim Nasby 2015-03-25 17:52:39 Re: proposal: plpgsql - Assert statement