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,7 +229,20 @@ pg_get_tableschemadef_string(Oid tableRelationId)
AttrNumber constraintIndex = 0;
AttrNumber constraintCount = 0;
StringInfoData buffer = { NULL, 0, 0, 0 };
OverrideSearchPath *overridePath = NULL;
/*
* Set search_path to NIL so that all objects outside of pg_catalog will be
* schema-prefixed. pg_catalog will be added automatically when we call
* PushOverrideSearchPath(), since we set addCatalog to true;
*/
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
overridePath->schemas = NIL;
overridePath->addCatalog = true;
PushOverrideSearchPath(overridePath);
PG_TRY();
{
/*
* Instead of retrieving values from system catalogs as other functions in
* ruleutils.c do, we follow an unusual approach here: we open the relation,
@ -272,8 +285,11 @@ pg_get_tableschemadef_string(Oid tableRelationId)
const char *attributeName = NULL;
const char *attributeTypeName = NULL;
if (!attributeForm->attisdropped && attributeForm->attinhcount == 0)
if (attributeForm->attisdropped || attributeForm->attinhcount != 0)
{
continue;
}
if (firstAttributePrinted)
{
appendStringInfoString(&buffer, ", ");
@ -325,7 +341,6 @@ pg_get_tableschemadef_string(Oid tableRelationId)
appendStringInfoString(&buffer, " NOT NULL");
}
}
}
/*
* Now check if the table has any constraints. If it does, set the number of
@ -381,8 +396,20 @@ pg_get_tableschemadef_string(Oid tableRelationId)
appendStringInfo(&buffer, " SERVER %s", quote_identifier(serverName));
AppendOptionListToString(&buffer, foreignTable->options);
}
}
PG_CATCH();
{
/* close the connection */
relation_close(relation, AccessShareLock);
PopOverrideSearchPath();
PG_RE_THROW();
}
PG_END_TRY();
/* close the connection */
relation_close(relation, AccessShareLock);
PopOverrideSearchPath();
return (buffer.data);
}

View File

@ -1731,6 +1731,8 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
deparse_context context;
deparse_namespace dpns;
OverrideSearchPath *overridePath = NULL;
/* Guard against excessively long or deeply-nested queries */
CHECK_FOR_INTERRUPTS();
check_stack_depth();
@ -1746,6 +1748,18 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
*/
AcquireRewriteLocks(query, false, false);
/*
* Set search_path to NIL so that all objects outside of pg_catalog will be
* schema-prefixed. pg_catalog will be added automatically when we call
* PushOverrideSearchPath(), since we set addCatalog to true;
*/
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
overridePath->schemas = NIL;
overridePath->addCatalog = true;
PushOverrideSearchPath(overridePath);
PG_TRY();
{
context.buf = buf;
context.namespaces = lcons(&dpns, list_copy(parentnamespace));
context.windowClause = NIL;
@ -1791,6 +1805,16 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
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)
{
/* XXX: this is where we would--but don't yet--handle schema-prefixing */
relname = get_relation_name(relid);
if (shardid > 0)
{
Oid schemaOid = get_rel_namespace(relid);
char *schemaName = get_namespace_name(schemaOid);
AppendShardIdToName(&relname, shardid);
relname = (char *) quote_identifier(relname);
relname = quote_qualified_identifier(schemaName, relname);
}
}
else

View File

@ -1838,6 +1838,8 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
deparse_context context;
deparse_namespace dpns;
OverrideSearchPath *overridePath = NULL;
/* Guard against excessively long or deeply-nested queries */
CHECK_FOR_INTERRUPTS();
check_stack_depth();
@ -1853,6 +1855,18 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
*/
AcquireRewriteLocks(query, false, false);
/*
* Set search_path to NIL so that all objects outside of pg_catalog will be
* schema-prefixed. pg_catalog will be added automatically when we call
* PushOverrideSearchPath(), since we set addCatalog to true;
*/
overridePath = GetOverrideSearchPath(CurrentMemoryContext);
overridePath->schemas = NIL;
overridePath->addCatalog = true;
PushOverrideSearchPath(overridePath);
PG_TRY();
{
context.buf = buf;
context.namespaces = lcons(&dpns, list_copy(parentnamespace));
context.windowClause = NIL;
@ -1899,6 +1913,17 @@ get_query_def_extended(Query *query, StringInfo buf, List *parentnamespace,
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)
{
/* XXX: this is where we would--but don't yet--handle schema-prefixing */
relname = get_relation_name(relid);
if (shardid > 0)
{
Oid schemaOid = get_rel_namespace(relid);
char *schemaName = get_namespace_name(schemaOid);
AppendShardIdToName(&relname, shardid);
relname = (char *) quote_identifier(relname);
relname = quote_qualified_identifier(schemaName, relname);
}
}
else

View File

@ -18,8 +18,8 @@ CREATE TABLE simple_table (
);
SELECT table_ddl_command_array('simple_table');
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)
-- ensure not-null constraints are propagated
@ -29,8 +29,8 @@ CREATE TABLE not_null_table (
);
SELECT table_ddl_command_array('not_null_table');
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)
-- ensure tables not in search path are schema-prefixed
@ -51,8 +51,8 @@ CREATE TABLE column_constraint_table (
);
SELECT table_ddl_command_array('column_constraint_table');
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)
-- including table constraints
@ -64,8 +64,8 @@ CREATE TABLE table_constraint_table (
);
SELECT table_ddl_command_array('table_constraint_table');
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)
-- default values are supported
@ -75,8 +75,8 @@ CREATE TABLE default_value_table (
);
SELECT table_ddl_command_array('default_value_table');
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)
-- of course primary keys work...
@ -87,8 +87,8 @@ CREATE TABLE pkey_table (
);
SELECT table_ddl_command_array('pkey_table');
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)
-- as do unique indexes...
@ -98,8 +98,8 @@ CREATE TABLE unique_table (
);
SELECT table_ddl_command_array('unique_table');
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)
-- and indexes used for clustering
@ -111,8 +111,8 @@ CREATE INDEX clustered_time_idx ON clustered_table (received_at);
CLUSTER clustered_table USING clustered_time_idx;
SELECT table_ddl_command_array('clustered_table');
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)
-- fiddly things like storage type and statistics also work
@ -130,8 +130,8 @@ ALTER TABLE fiddly_table
ALTER ip_addr SET STATISTICS 500;
SELECT table_ddl_command_array('fiddly_table');
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)
-- test foreign tables using fake FDW
@ -142,14 +142,14 @@ CREATE FOREIGN TABLE foreign_table (
SELECT table_ddl_command_array('foreign_table');
NOTICE: foreign-data wrapper "fake_fdw" does not have an extension defined
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)
-- propagating views is not supported
CREATE VIEW local_view AS SELECT * FROM simple_table;
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
DROP VIEW IF EXISTS local_view;
DROP FOREIGN TABLE IF EXISTS foreign_table;

View File

@ -13,8 +13,8 @@ SELECT part_storage_type, part_key, part_replica_count, part_max_size,
SELECT * FROM master_get_table_ddl_events('lineitem');
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)
ALTER TABLE public.lineitem ADD CONSTRAINT lineitem_pkey PRIMARY KEY (l_orderkey, l_linenumber)
(3 rows)

View File

@ -280,7 +280,7 @@ ALTER TABLE limit_orders_750000 RENAME TO renamed_orders;
\c - - - :master_port
-- 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);
WARNING: relation "limit_orders_750000" does not exist
WARNING: relation "public.limit_orders_750000" does not exist
CONTEXT: while executing command on localhost:57638
-- Last: Verify the insert worked but the deleted placement is now unhealthy
SELECT count(*) FROM limit_orders WHERE id = 276;
@ -311,7 +311,7 @@ ALTER TABLE limit_orders_750000 RENAME TO renamed_orders;
\c - - - :master_port
-- 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);
WARNING: relation "limit_orders_750000" does not exist
WARNING: relation "public.limit_orders_750000" does not exist
CONTEXT: while executing command on localhost:57637
ERROR: could not modify any active placements
-- Last: Verify worker is still healthy

View File

@ -45,6 +45,7 @@ my %dataTypes = ();
my %fdws = ();
my %fdwServers = ();
my %functions = ();
my %operators = ();
GetOptions(
'bindir=s' => \$bindir,
@ -112,7 +113,11 @@ for my $option (@userPgOptions)
'bug_status', ' ENUM (\'new\', \'open\', \'closed\')');
# 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
%fdws = ('fake_fdw', 'fake_fdw_handler');
@ -257,6 +262,14 @@ for my $port (@workerPorts)
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)
{
system("$bindir/psql",