pull/629/merge
Burak Yücesoy 2016-07-01 10:24:57 +00:00 committed by GitHub
commit fafc89ecb2
7 changed files with 291 additions and 197 deletions

View File

@ -229,51 +229,67 @@ pg_get_tableschemadef_string(Oid tableRelationId)
AttrNumber constraintIndex = 0; AttrNumber constraintIndex = 0;
AttrNumber constraintCount = 0; AttrNumber constraintCount = 0;
StringInfoData buffer = { NULL, 0, 0, 0 }; StringInfoData buffer = { NULL, 0, 0, 0 };
OverrideSearchPath *overridePath = NULL;
/* /*
* Instead of retrieving values from system catalogs as other functions in * Set search_path to NIL so that all objects outside of pg_catalog will be
* ruleutils.c do, we follow an unusual approach here: we open the relation, * schema-prefixed. pg_catalog will be added automatically when we call
* and fetch the relation's tuple descriptor. We do this because the tuple * PushOverrideSearchPath(), since we set addCatalog to true;
* descriptor already contains information harnessed from pg_attrdef,
* pg_attribute, pg_constraint, and pg_class; and therefore using the
* descriptor saves us from a lot of additional work.
*/ */
relation = relation_open(tableRelationId, AccessShareLock); overridePath = GetOverrideSearchPath(CurrentMemoryContext);
relationName = generate_relation_name(tableRelationId, NIL); overridePath->schemas = NIL;
overridePath->addCatalog = true;
PushOverrideSearchPath(overridePath);
relationKind = relation->rd_rel->relkind; PG_TRY();
if (relationKind != RELKIND_RELATION && relationKind != RELKIND_FOREIGN_TABLE)
{ {
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), /*
errmsg("%s is not a regular or foreign table", relationName))); * Instead of retrieving values from system catalogs as other functions in
} * ruleutils.c do, we follow an unusual approach here: we open the relation,
* and fetch the relation's tuple descriptor. We do this because the tuple
* descriptor already contains information harnessed from pg_attrdef,
* pg_attribute, pg_constraint, and pg_class; and therefore using the
* descriptor saves us from a lot of additional work.
*/
relation = relation_open(tableRelationId, AccessShareLock);
relationName = generate_relation_name(tableRelationId, NIL);
initStringInfo(&buffer); relationKind = relation->rd_rel->relkind;
if (relationKind == RELKIND_RELATION) if (relationKind != RELKIND_RELATION && relationKind != RELKIND_FOREIGN_TABLE)
{
appendStringInfo(&buffer, "CREATE TABLE %s (", relationName);
}
else
{
appendStringInfo(&buffer, "CREATE FOREIGN TABLE %s (", relationName);
}
/*
* Iterate over the table's columns. If a particular column is not dropped
* and is not inherited from another table, print the column's name and its
* formatted type.
*/
tupleDescriptor = RelationGetDescr(relation);
tupleConstraints = tupleDescriptor->constr;
for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++)
{
Form_pg_attribute attributeForm = tupleDescriptor->attrs[attributeIndex];
const char *attributeName = NULL;
const char *attributeTypeName = NULL;
if (!attributeForm->attisdropped && attributeForm->attinhcount == 0)
{ {
ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("%s is not a regular or foreign table", relationName)));
}
initStringInfo(&buffer);
if (relationKind == RELKIND_RELATION)
{
appendStringInfo(&buffer, "CREATE TABLE %s (", relationName);
}
else
{
appendStringInfo(&buffer, "CREATE FOREIGN TABLE %s (", relationName);
}
/*
* Iterate over the table's columns. If a particular column is not dropped
* and is not inherited from another table, print the column's name and its
* formatted type.
*/
tupleDescriptor = RelationGetDescr(relation);
tupleConstraints = tupleDescriptor->constr;
for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++)
{
Form_pg_attribute attributeForm = tupleDescriptor->attrs[attributeIndex];
const char *attributeName = NULL;
const char *attributeTypeName = NULL;
if (attributeForm->attisdropped || attributeForm->attinhcount != 0)
{
continue;
}
if (firstAttributePrinted) if (firstAttributePrinted)
{ {
appendStringInfoString(&buffer, ", "); appendStringInfoString(&buffer, ", ");
@ -325,64 +341,75 @@ pg_get_tableschemadef_string(Oid tableRelationId)
appendStringInfoString(&buffer, " NOT NULL"); appendStringInfoString(&buffer, " NOT NULL");
} }
} }
}
/* /*
* Now check if the table has any constraints. If it does, set the number of * Now check if the table has any constraints. If it does, set the number of
* check constraints here. Then iterate over all check constraints and print * check constraints here. Then iterate over all check constraints and print
* them. * them.
*/ */
if (tupleConstraints != NULL) if (tupleConstraints != NULL)
{
constraintCount = tupleConstraints->num_check;
}
for (constraintIndex = 0; constraintIndex < constraintCount; constraintIndex++)
{
ConstrCheck *checkConstraintList = tupleConstraints->check;
ConstrCheck *checkConstraint = &(checkConstraintList[constraintIndex]);
Node *checkNode = NULL;
List *checkContext = NULL;
char *checkString = NULL;
/* if an attribute or constraint has been printed, format properly */
if (firstAttributePrinted || constraintIndex > 0)
{ {
appendStringInfoString(&buffer, ", "); constraintCount = tupleConstraints->num_check;
} }
appendStringInfo(&buffer, "CONSTRAINT %s CHECK ", for (constraintIndex = 0; constraintIndex < constraintCount; constraintIndex++)
quote_identifier(checkConstraint->ccname)); {
ConstrCheck *checkConstraintList = tupleConstraints->check;
ConstrCheck *checkConstraint = &(checkConstraintList[constraintIndex]);
/* convert expression to node tree, and prepare deparse context */ Node *checkNode = NULL;
checkNode = (Node *) stringToNode(checkConstraint->ccbin); List *checkContext = NULL;
checkContext = deparse_context_for(relationName, tableRelationId); char *checkString = NULL;
/* deparse check constraint string */ /* if an attribute or constraint has been printed, format properly */
checkString = deparse_expression(checkNode, checkContext, false, false); if (firstAttributePrinted || constraintIndex > 0)
{
appendStringInfoString(&buffer, ", ");
}
appendStringInfoString(&buffer, checkString); appendStringInfo(&buffer, "CONSTRAINT %s CHECK ",
quote_identifier(checkConstraint->ccname));
/* convert expression to node tree, and prepare deparse context */
checkNode = (Node *) stringToNode(checkConstraint->ccbin);
checkContext = deparse_context_for(relationName, tableRelationId);
/* deparse check constraint string */
checkString = deparse_expression(checkNode, checkContext, false, false);
appendStringInfoString(&buffer, checkString);
}
/* close create table's outer parentheses */
appendStringInfoString(&buffer, ")");
/*
* If the relation is a foreign table, append the server name and options to
* the create table statement.
*/
if (relationKind == RELKIND_FOREIGN_TABLE)
{
ForeignTable *foreignTable = GetForeignTable(tableRelationId);
ForeignServer *foreignServer = GetForeignServer(foreignTable->serverid);
char *serverName = foreignServer->servername;
appendStringInfo(&buffer, " SERVER %s", quote_identifier(serverName));
AppendOptionListToString(&buffer, foreignTable->options);
}
} }
PG_CATCH();
/* close create table's outer parentheses */
appendStringInfoString(&buffer, ")");
/*
* If the relation is a foreign table, append the server name and options to
* the create table statement.
*/
if (relationKind == RELKIND_FOREIGN_TABLE)
{ {
ForeignTable *foreignTable = GetForeignTable(tableRelationId); /* close the connection */
ForeignServer *foreignServer = GetForeignServer(foreignTable->serverid); relation_close(relation, AccessShareLock);
PopOverrideSearchPath();
char *serverName = foreignServer->servername; PG_RE_THROW();
appendStringInfo(&buffer, " SERVER %s", quote_identifier(serverName));
AppendOptionListToString(&buffer, foreignTable->options);
} }
PG_END_TRY();
/* close the connection */
relation_close(relation, AccessShareLock); relation_close(relation, AccessShareLock);
PopOverrideSearchPath();
return (buffer.data); return (buffer.data);
} }

View File

@ -1731,6 +1731,8 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
deparse_context context; deparse_context context;
deparse_namespace dpns; deparse_namespace dpns;
OverrideSearchPath *overridePath = NULL;
/* Guard against excessively long or deeply-nested queries */ /* Guard against excessively long or deeply-nested queries */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
check_stack_depth(); check_stack_depth();
@ -1746,51 +1748,73 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
*/ */
AcquireRewriteLocks(query, false, false); AcquireRewriteLocks(query, false, false);
context.buf = buf; /*
context.namespaces = lcons(&dpns, list_copy(parentnamespace)); * Set search_path to NIL so that all objects outside of pg_catalog will be
context.windowClause = NIL; * schema-prefixed. pg_catalog will be added automatically when we call
context.windowTList = NIL; * PushOverrideSearchPath(), since we set addCatalog to true;
context.varprefix = (parentnamespace != NIL || */
list_length(query->rtable) != 1); overridePath = GetOverrideSearchPath(CurrentMemoryContext);
context.prettyFlags = prettyFlags; overridePath->schemas = NIL;
context.wrapColumn = wrapColumn; overridePath->addCatalog = true;
context.indentLevel = startIndent; PushOverrideSearchPath(overridePath);
context.distrelid = distrelid;
context.shardid = shardid;
set_deparse_for_query(&dpns, query, parentnamespace); PG_TRY();
switch (query->commandType)
{ {
case CMD_SELECT: context.buf = buf;
get_select_query_def(query, &context, resultDesc); context.namespaces = lcons(&dpns, list_copy(parentnamespace));
break; context.windowClause = NIL;
context.windowTList = NIL;
context.varprefix = (parentnamespace != NIL ||
list_length(query->rtable) != 1);
context.prettyFlags = prettyFlags;
context.wrapColumn = wrapColumn;
context.indentLevel = startIndent;
context.distrelid = distrelid;
context.shardid = shardid;
case CMD_UPDATE: set_deparse_for_query(&dpns, query, parentnamespace);
get_update_query_def(query, &context);
break;
case CMD_INSERT: switch (query->commandType)
get_insert_query_def(query, &context); {
break; case CMD_SELECT:
get_select_query_def(query, &context, resultDesc);
break;
case CMD_DELETE: case CMD_UPDATE:
get_delete_query_def(query, &context); get_update_query_def(query, &context);
break; break;
case CMD_NOTHING: case CMD_INSERT:
appendStringInfoString(buf, "NOTHING"); get_insert_query_def(query, &context);
break; break;
case CMD_UTILITY: case CMD_DELETE:
get_utility_query_def(query, &context); get_delete_query_def(query, &context);
break; break;
default: case CMD_NOTHING:
elog(ERROR, "unrecognized query command type: %d", appendStringInfoString(buf, "NOTHING");
query->commandType); break;
break;
case CMD_UTILITY:
get_utility_query_def(query, &context);
break;
default:
elog(ERROR, "unrecognized query command type: %d",
query->commandType);
break;
}
} }
PG_CATCH();
{
/* close the connection */
PopOverrideSearchPath();
PG_RE_THROW();
}
PG_END_TRY();
PopOverrideSearchPath();
} }
/* ---------- /* ----------
@ -6395,14 +6419,17 @@ generate_relation_or_shard_name(Oid relid, Oid distrelid, int64 shardid,
if (relid == distrelid) if (relid == distrelid)
{ {
/* XXX: this is where we would--but don't yet--handle schema-prefixing */
relname = get_relation_name(relid); relname = get_relation_name(relid);
if (shardid > 0) if (shardid > 0)
{ {
Oid schemaOid = get_rel_namespace(relid);
char *schemaName = get_namespace_name(schemaOid);
AppendShardIdToName(&relname, shardid); AppendShardIdToName(&relname, shardid);
relname = (char *) quote_identifier(relname); relname = quote_qualified_identifier(schemaName, relname);
} }
} }
else else

View File

@ -1838,6 +1838,8 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
deparse_context context; deparse_context context;
deparse_namespace dpns; deparse_namespace dpns;
OverrideSearchPath *overridePath = NULL;
/* Guard against excessively long or deeply-nested queries */ /* Guard against excessively long or deeply-nested queries */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
check_stack_depth(); check_stack_depth();
@ -1853,52 +1855,75 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
*/ */
AcquireRewriteLocks(query, false, false); AcquireRewriteLocks(query, false, false);
context.buf = buf; /*
context.namespaces = lcons(&dpns, list_copy(parentnamespace)); * Set search_path to NIL so that all objects outside of pg_catalog will be
context.windowClause = NIL; * schema-prefixed. pg_catalog will be added automatically when we call
context.windowTList = NIL; * PushOverrideSearchPath(), since we set addCatalog to true;
context.varprefix = (parentnamespace != NIL || */
list_length(query->rtable) != 1); overridePath = GetOverrideSearchPath(CurrentMemoryContext);
context.prettyFlags = prettyFlags; overridePath->schemas = NIL;
context.wrapColumn = wrapColumn; overridePath->addCatalog = true;
context.indentLevel = startIndent; PushOverrideSearchPath(overridePath);
context.special_exprkind = EXPR_KIND_NONE;
context.distrelid = distrelid;
context.shardid = shardid;
set_deparse_for_query(&dpns, query, parentnamespace); PG_TRY();
switch (query->commandType)
{ {
case CMD_SELECT: context.buf = buf;
get_select_query_def(query, &context, resultDesc); context.namespaces = lcons(&dpns, list_copy(parentnamespace));
break; context.windowClause = NIL;
context.windowTList = NIL;
context.varprefix = (parentnamespace != NIL ||
list_length(query->rtable) != 1);
context.prettyFlags = prettyFlags;
context.wrapColumn = wrapColumn;
context.indentLevel = startIndent;
context.special_exprkind = EXPR_KIND_NONE;
context.distrelid = distrelid;
context.shardid = shardid;
case CMD_UPDATE: set_deparse_for_query(&dpns, query, parentnamespace);
get_update_query_def(query, &context);
break;
case CMD_INSERT: switch (query->commandType)
get_insert_query_def(query, &context); {
break; case CMD_SELECT:
get_select_query_def(query, &context, resultDesc);
break;
case CMD_DELETE: case CMD_UPDATE:
get_delete_query_def(query, &context); get_update_query_def(query, &context);
break; break;
case CMD_NOTHING: case CMD_INSERT:
appendStringInfoString(buf, "NOTHING"); get_insert_query_def(query, &context);
break; break;
case CMD_UTILITY: case CMD_DELETE:
get_utility_query_def(query, &context); get_delete_query_def(query, &context);
break; break;
default: case CMD_NOTHING:
elog(ERROR, "unrecognized query command type: %d", appendStringInfoString(buf, "NOTHING");
query->commandType); break;
break;
case CMD_UTILITY:
get_utility_query_def(query, &context);
break;
default:
elog(ERROR, "unrecognized query command type: %d",
query->commandType);
break;
}
} }
PG_CATCH();
{
/* close the connection */
PopOverrideSearchPath();
PG_RE_THROW();
}
PG_END_TRY();
PopOverrideSearchPath();
} }
/* ---------- /* ----------
@ -6975,14 +7000,16 @@ generate_relation_or_shard_name(Oid relid, Oid distrelid, int64 shardid,
if (relid == distrelid) if (relid == distrelid)
{ {
/* XXX: this is where we would--but don't yet--handle schema-prefixing */
relname = get_relation_name(relid); relname = get_relation_name(relid);
if (shardid > 0) if (shardid > 0)
{ {
Oid schemaOid = get_rel_namespace(relid);
char *schemaName = get_namespace_name(schemaOid);
AppendShardIdToName(&relname, shardid); AppendShardIdToName(&relname, shardid);
relname = (char *) quote_identifier(relname); relname = quote_qualified_identifier(schemaName, relname);
} }
} }
else else

View File

@ -17,9 +17,9 @@ CREATE TABLE simple_table (
id bigint id bigint
); );
SELECT table_ddl_command_array('simple_table'); SELECT table_ddl_command_array('simple_table');
table_ddl_command_array table_ddl_command_array
---------------------------------------------------------------------------- -----------------------------------------------------------------------------------
{"CREATE TABLE simple_table (first_name text, last_name text, id bigint)"} {"CREATE TABLE public.simple_table (first_name text, last_name text, id bigint)"}
(1 row) (1 row)
-- ensure not-null constraints are propagated -- ensure not-null constraints are propagated
@ -28,9 +28,9 @@ CREATE TABLE not_null_table (
id bigint not null id bigint not null
); );
SELECT table_ddl_command_array('not_null_table'); SELECT table_ddl_command_array('not_null_table');
table_ddl_command_array table_ddl_command_array
----------------------------------------------------------------- ------------------------------------------------------------------------
{"CREATE TABLE not_null_table (city text, id bigint NOT NULL)"} {"CREATE TABLE public.not_null_table (city text, id bigint NOT NULL)"}
(1 row) (1 row)
-- ensure tables not in search path are schema-prefixed -- ensure tables not in search path are schema-prefixed
@ -50,9 +50,9 @@ CREATE TABLE column_constraint_table (
age int CONSTRAINT non_negative_age CHECK (age >= 0) age int CONSTRAINT non_negative_age CHECK (age >= 0)
); );
SELECT table_ddl_command_array('column_constraint_table'); SELECT table_ddl_command_array('column_constraint_table');
table_ddl_command_array table_ddl_command_array
--------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE column_constraint_table (first_name text, last_name text, age integer, CONSTRAINT non_negative_age CHECK (age >= 0))"} {"CREATE TABLE public.column_constraint_table (first_name text, last_name text, age integer, CONSTRAINT non_negative_age CHECK (age >= 0))"}
(1 row) (1 row)
-- including table constraints -- including table constraints
@ -63,9 +63,9 @@ CREATE TABLE table_constraint_table (
CONSTRAINT bids_ordered CHECK (min_bid > max_bid) CONSTRAINT bids_ordered CHECK (min_bid > max_bid)
); );
SELECT table_ddl_command_array('table_constraint_table'); SELECT table_ddl_command_array('table_constraint_table');
table_ddl_command_array table_ddl_command_array
--------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE table_constraint_table (bid_item_id bigint, min_bid numeric NOT NULL, max_bid numeric NOT NULL, CONSTRAINT bids_ordered CHECK (min_bid > max_bid))"} {"CREATE TABLE public.table_constraint_table (bid_item_id bigint, min_bid numeric NOT NULL, max_bid numeric NOT NULL, CONSTRAINT bids_ordered CHECK (min_bid > max_bid))"}
(1 row) (1 row)
-- default values are supported -- default values are supported
@ -74,9 +74,9 @@ CREATE TABLE default_value_table (
price decimal default 0.00 price decimal default 0.00
); );
SELECT table_ddl_command_array('default_value_table'); SELECT table_ddl_command_array('default_value_table');
table_ddl_command_array table_ddl_command_array
------------------------------------------------------------------------------ -------------------------------------------------------------------------------------
{"CREATE TABLE default_value_table (name text, price numeric DEFAULT 0.00)"} {"CREATE TABLE public.default_value_table (name text, price numeric DEFAULT 0.00)"}
(1 row) (1 row)
-- of course primary keys work... -- of course primary keys work...
@ -86,9 +86,9 @@ CREATE TABLE pkey_table (
id bigint PRIMARY KEY id bigint PRIMARY KEY
); );
SELECT table_ddl_command_array('pkey_table'); SELECT table_ddl_command_array('pkey_table');
table_ddl_command_array table_ddl_command_array
------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE pkey_table (first_name text, last_name text, id bigint NOT NULL)","ALTER TABLE public.pkey_table ADD CONSTRAINT pkey_table_pkey PRIMARY KEY (id)"} {"CREATE TABLE public.pkey_table (first_name text, last_name text, id bigint NOT NULL)","ALTER TABLE public.pkey_table ADD CONSTRAINT pkey_table_pkey PRIMARY KEY (id)"}
(1 row) (1 row)
-- as do unique indexes... -- as do unique indexes...
@ -97,9 +97,9 @@ CREATE TABLE unique_table (
username text UNIQUE not null username text UNIQUE not null
); );
SELECT table_ddl_command_array('unique_table'); SELECT table_ddl_command_array('unique_table');
table_ddl_command_array table_ddl_command_array
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE unique_table (user_id bigint NOT NULL, username text NOT NULL)","ALTER TABLE public.unique_table ADD CONSTRAINT unique_table_username_key UNIQUE (username)"} {"CREATE TABLE public.unique_table (user_id bigint NOT NULL, username text NOT NULL)","ALTER TABLE public.unique_table ADD CONSTRAINT unique_table_username_key UNIQUE (username)"}
(1 row) (1 row)
-- and indexes used for clustering -- and indexes used for clustering
@ -110,9 +110,9 @@ CREATE TABLE clustered_table (
CREATE INDEX clustered_time_idx ON clustered_table (received_at); CREATE INDEX clustered_time_idx ON clustered_table (received_at);
CLUSTER clustered_table USING clustered_time_idx; CLUSTER clustered_table USING clustered_time_idx;
SELECT table_ddl_command_array('clustered_table'); SELECT table_ddl_command_array('clustered_table');
table_ddl_command_array table_ddl_command_array
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE clustered_table (data json NOT NULL, received_at timestamp without time zone NOT NULL)","CREATE INDEX clustered_time_idx ON clustered_table USING btree (received_at)","ALTER TABLE clustered_table CLUSTER ON clustered_time_idx"} {"CREATE TABLE public.clustered_table (data json NOT NULL, received_at timestamp without time zone NOT NULL)","CREATE INDEX clustered_time_idx ON clustered_table USING btree (received_at)","ALTER TABLE clustered_table CLUSTER ON clustered_time_idx"}
(1 row) (1 row)
-- fiddly things like storage type and statistics also work -- fiddly things like storage type and statistics also work
@ -129,9 +129,9 @@ ALTER TABLE fiddly_table
ALTER traceroute SET STORAGE EXTERNAL, ALTER traceroute SET STORAGE EXTERNAL,
ALTER ip_addr SET STATISTICS 500; ALTER ip_addr SET STATISTICS 500;
SELECT table_ddl_command_array('fiddly_table'); SELECT table_ddl_command_array('fiddly_table');
table_ddl_command_array table_ddl_command_array
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE TABLE fiddly_table (hostname character(255) NOT NULL, os character(255) NOT NULL, ip_addr inet NOT NULL, traceroute text NOT NULL)","ALTER TABLE ONLY fiddly_table ALTER COLUMN hostname SET STORAGE PLAIN, ALTER COLUMN os SET STORAGE MAIN, ALTER COLUMN ip_addr SET STORAGE EXTENDED, ALTER COLUMN ip_addr SET STATISTICS 500, ALTER COLUMN traceroute SET STORAGE EXTERNAL"} {"CREATE TABLE public.fiddly_table (hostname character(255) NOT NULL, os character(255) NOT NULL, ip_addr inet NOT NULL, traceroute text NOT NULL)","ALTER TABLE ONLY fiddly_table ALTER COLUMN hostname SET STORAGE PLAIN, ALTER COLUMN os SET STORAGE MAIN, ALTER COLUMN ip_addr SET STORAGE EXTENDED, ALTER COLUMN ip_addr SET STATISTICS 500, ALTER COLUMN traceroute SET STORAGE EXTERNAL"}
(1 row) (1 row)
-- test foreign tables using fake FDW -- test foreign tables using fake FDW
@ -141,15 +141,15 @@ CREATE FOREIGN TABLE foreign_table (
) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true'); ) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true');
SELECT table_ddl_command_array('foreign_table'); SELECT table_ddl_command_array('foreign_table');
NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined
table_ddl_command_array table_ddl_command_array
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"CREATE SERVER fake_fdw_server FOREIGN DATA WRAPPER fake_fdw","CREATE FOREIGN TABLE foreign_table (id bigint NOT NULL, full_name text DEFAULT ''::text NOT NULL) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true')"} {"CREATE SERVER fake_fdw_server FOREIGN DATA WRAPPER fake_fdw","CREATE FOREIGN TABLE public.foreign_table (id bigint NOT NULL, full_name text DEFAULT ''::text NOT NULL) SERVER fake_fdw_server OPTIONS (encoding 'utf-8', compression 'true')"}
(1 row) (1 row)
-- propagating views is not supported -- propagating views is not supported
CREATE VIEW local_view AS SELECT * FROM simple_table; CREATE VIEW local_view AS SELECT * FROM simple_table;
SELECT table_ddl_command_array('local_view'); SELECT table_ddl_command_array('local_view');
ERROR: local_view is not a regular or foreign table ERROR: public.local_view is not a regular or foreign table
-- clean up -- clean up
DROP VIEW IF EXISTS local_view; DROP VIEW IF EXISTS local_view;
DROP FOREIGN TABLE IF EXISTS foreign_table; DROP FOREIGN TABLE IF EXISTS foreign_table;

View File

@ -12,9 +12,9 @@ SELECT part_storage_type, part_key, part_replica_count, part_max_size,
(1 row) (1 row)
SELECT * FROM master_get_table_ddl_events('lineitem'); SELECT * FROM master_get_table_ddl_events('lineitem');
master_get_table_ddl_events master_get_table_ddl_events
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE lineitem (l_orderkey bigint NOT NULL, l_partkey integer NOT NULL, l_suppkey integer NOT NULL, l_linenumber integer NOT NULL, l_quantity numeric(15,2) NOT NULL, l_extendedprice numeric(15,2) NOT NULL, l_discount numeric(15,2) NOT NULL, l_tax numeric(15,2) NOT NULL, l_returnflag character(1) NOT NULL, l_linestatus character(1) NOT NULL, l_shipdate date NOT NULL, l_commitdate date NOT NULL, l_receiptdate date NOT NULL, l_shipinstruct character(25) NOT NULL, l_shipmode character(10) NOT NULL, l_comment character varying(44) NOT NULL) CREATE TABLE public.lineitem (l_orderkey bigint NOT NULL, l_partkey integer NOT NULL, l_suppkey integer NOT NULL, l_linenumber integer NOT NULL, l_quantity numeric(15,2) NOT NULL, l_extendedprice numeric(15,2) NOT NULL, l_discount numeric(15,2) NOT NULL, l_tax numeric(15,2) NOT NULL, l_returnflag character(1) NOT NULL, l_linestatus character(1) NOT NULL, l_shipdate date NOT NULL, l_commitdate date NOT NULL, l_receiptdate date NOT NULL, l_shipinstruct character(25) NOT NULL, l_shipmode character(10) NOT NULL, l_comment character varying(44) NOT NULL)
CREATE INDEX lineitem_time_index ON lineitem USING btree (l_shipdate) CREATE INDEX lineitem_time_index ON lineitem USING btree (l_shipdate)
ALTER TABLE public.lineitem ADD CONSTRAINT lineitem_pkey PRIMARY KEY (l_orderkey, l_linenumber) ALTER TABLE public.lineitem ADD CONSTRAINT lineitem_pkey PRIMARY KEY (l_orderkey, l_linenumber)
(3 rows) (3 rows)

View File

@ -280,7 +280,7 @@ ALTER TABLE limit_orders_750000 RENAME TO renamed_orders;
\c - - - :master_port \c - - - :master_port
-- Fourth: Perform an INSERT on the remaining node -- Fourth: Perform an INSERT on the remaining node
INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
WARNING: relation "limit_orders_750000" does not exist WARNING: relation "public.limit_orders_750000" does not exist
CONTEXT: while executing command on localhost:57638 CONTEXT: while executing command on localhost:57638
-- Last: Verify the insert worked but the deleted placement is now unhealthy -- Last: Verify the insert worked but the deleted placement is now unhealthy
SELECT count(*) FROM limit_orders WHERE id = 276; SELECT count(*) FROM limit_orders WHERE id = 276;
@ -311,7 +311,7 @@ ALTER TABLE limit_orders_750000 RENAME TO renamed_orders;
\c - - - :master_port \c - - - :master_port
-- Fourth: Perform an INSERT on the remaining node -- Fourth: Perform an INSERT on the remaining node
INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67); INSERT INTO limit_orders VALUES (276, 'ADR', 140, '2007-07-02 16:32:15', 'sell', 43.67);
WARNING: relation "limit_orders_750000" does not exist WARNING: relation "public.limit_orders_750000" does not exist
CONTEXT: while executing command on localhost:57637 CONTEXT: while executing command on localhost:57637
ERROR: could not modify any active placements ERROR: could not modify any active placements
-- Last: Verify worker is still healthy -- Last: Verify worker is still healthy

View File

@ -45,6 +45,7 @@ my %dataTypes = ();
my %fdws = (); my %fdws = ();
my %fdwServers = (); my %fdwServers = ();
my %functions = (); my %functions = ();
my %operators = ();
GetOptions( GetOptions(
'bindir=s' => \$bindir, 'bindir=s' => \$bindir,
@ -112,7 +113,11 @@ for my $option (@userPgOptions)
'bug_status', ' ENUM (\'new\', \'open\', \'closed\')'); 'bug_status', ' ENUM (\'new\', \'open\', \'closed\')');
# define functions as signature->definition # define functions as signature->definition
%functions = ('fake_fdw_handler()', 'fdw_handler AS \'citus\' LANGUAGE C STRICT;'); %functions = ('fake_fdw_handler()', 'fdw_handler AS \'citus\' LANGUAGE C STRICT;',
'equal_test_composite_type_function(test_composite_type, test_composite_type)', 'boolean AS \'select $1.i = $2.i AND $1.i2 = $2.i2;\' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;');
%operators = ('=', '(LEFTARG = test_composite_type, RIGHTARG = test_composite_type, PROCEDURE = equal_test_composite_type_function, HASHES)');
#define fdws as name->handler name #define fdws as name->handler name
%fdws = ('fake_fdw', 'fake_fdw_handler'); %fdws = ('fake_fdw', 'fake_fdw_handler');
@ -257,6 +262,14 @@ for my $port (@workerPorts)
or die "Could not create FUNCTION $function on worker"; or die "Could not create FUNCTION $function on worker";
} }
foreach my $operator (keys %operators)
{
system("$bindir/psql",
('-h', $host, '-p', $port, '-U', $user, "regression",
'-c', "CREATE OPERATOR $operator $operators{$operator};")) == 0
or die "Could not create OPERATOR $operator on worker";
}
foreach my $fdw (keys %fdws) foreach my $fdw (keys %fdws)
{ {
system("$bindir/psql", system("$bindir/psql",