Re: IMPORT FOREIGN SCHEMA statement - Mailing list pgsql-hackers
From | Michael Paquier |
---|---|
Subject | Re: IMPORT FOREIGN SCHEMA statement |
Date | |
Msg-id | CAB7nPqTeD08QYeb8XmqRSaA8rk-9aBq47mti70a2RfY-V+NogA@mail.gmail.com Whole thread Raw |
In response to | IMPORT FOREIGN SCHEMA statement (Ronan Dunklau <ronan.dunklau@dalibo.com>) |
Responses |
Re: IMPORT FOREIGN SCHEMA statement
|
List | pgsql-hackers |
On Sat, May 24, 2014 at 5:08 AM, Ronan Dunklau <ronan.dunklau@dalibo.com> wrote: > Hello, > > Since my last proposal didn't get any strong rebuttal, please find attached a > more complete version of the IMPORT FOREIGN SCHEMA statement. > > I tried to follow the SQL-MED specification as closely as possible. > > This adds discoverability to foreign servers. The structure of the statement > as I understand it is simple enough: > > IMPORT FOREIGN SCHEMA remote_schema FROM SERVER some_server [ (LIMIT TO | > EXCEPT) table_list ] INTO local_schema. > > The import_foreign_schema patch adds the infrastructure, and a new FDW > routine: > > typedef List *(*ImportForeignSchema_function) (ForeignServer *server, > ImportForeignSchemaStmt * parsetree); > > This routine must return a list of CreateForeignTableStmt mirroring whatever > tables were found on the remote side, which will then be executed. > > The import_foreign_schema_postgres_fdw patch proposes an implementation of > this API for postgres_fdw. It will import a foreign schema using the right > types as well as nullable information. > > Regarding documentation, I don't really know where it should have been put. If > I missed something, let me know and I'll try to correct it. I have been playing a bit with this patch... And got a couple of comments. 1) Perhaps somebody could guide me to a better spec but by looking at the spec here => http://farrago.sourceforge.net/design/sqlmed.html, it seems that the FROM SERVER clause is misplaced, it should be placed after the table list. 2) The query I am seeing on this spec offers the possiblitily to query TABLE_NAME LIKE 'pattern'. Is this part of the spec as well? If yes, are you planning to add it as well. I imagine that this could be quite handy for users importing from a foreign schema tables that have the same prefix name for example. ImportForeignSchemaRestrictionType could be extended with an IMPORT_LIKE type. Extending a bit the spec... There could be a list of LIKE patterns, this matches more your code by adding all of them in table_names. I am not voting to add TABLE_NAME in the list of reserved keywords though, so something like "TABLE LIKE 'pattern'" would be nice. 3) This has been already raised in this thread, but something missing with this patch is the possiblity to pass options when executing an import. This could allow a FDW to do more fine-grained operations on the underlying objects of the table. There would be two level of options: table level and schema level. For example, with the current feature it is not possible to rename imported tables on-the-fly. I imagine that this would be useful. 4) Something not mandatory with the core patch but always nice to have: tab completion for this command in psql. 5) The error message returned to user when import fails because of a missing type is rather unfriendly. Let's imagine with two nodes and postgres_fdw... Node 1: create type toto as (a int, b int); create table toto_tab (a toto); Node 2: =# import foreign schema public from server postgres_server into public; ERROR: 42704: type "public.toto" does not exist LOCATION: parseTypeString, parse_type.c:797 I would rather imagine something like "IMPORT failed because of missing type defined on remote but not locally". 6) Import does not fail if a table specified in LIMIT TO is not defined on remote-side: =# import foreign schema public from server postgres_server limit to (tab_not_there) into public; IMPORT FOREIGN SCHEMA =# \d No relations found. 7) A small thing: code comments do not respect the project format: http://www.postgresql.org/docs/9.1/interactive/source-format.html 8) In fetch_remote_tables@postgres_fdw.c, you are missing materialized views: WHERE relkind IN ('r', 'v', 'f') 9) The changes in pg_type.h adding new OID defines should be a separate patch IMO 10) Code has many whitespaces. 11) Sometimes the import goes strangely: 11-1) After some testing I noticed that tables with incorrect names were imported when using LIMIT TO. For example on remote a table called "ab" is present, IMPORT SCHEMA LIMIT TO 'other_ab' created a local entry called "other_ab" while it should create nothing. 11-2) Tables with empty names can be created locally. On foreign server: =# \d List of relationsSchema | Name | Type | Owner --------+----------+-------+--------public | aa | table | ioltaspublic | toto_tab | table | ioltas (2 rows) On local node: =# import foreign schema public from server postgres_server limit to (toto_tab, "NULL", aa) into public; -- (Forget about NULL here, I could reproduce it without as well) IMPORT FOREIGN SCHEMA Time: 13.589 ms =# \d List of relationsSchema | Name | Type | Owner --------+----------+---------------+--------public | | foreign table | ioltaspublic | toto_tab | foreign table |ioltas (2 rows) Some more testing showed me that as well: =# \d List of relationsSchema | Name | Type | Owner --------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------+--------public | | foreign table | ioltaspublic | toto_tab | foreign table | ioltaspublic | \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F | foreign table | ioltas That's all I have for now. Regards, -- Michael
pgsql-hackers by date: