summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2018-07-10 09:10:56 +0000
committerPavan Deolasee2018-07-27 08:00:00 +0000
commitb3c5a42ed842984318e88c296454c194c4c0a60d (patch)
tree6bbb5c06485bbba59068f863e52aa722a3f84533
parenta6ea0d32baf68e696f17c6696a82c17b2f232871 (diff)
Ensure that typename is schema qualified while sending row description
A row description messages contains the type information for the attributes in the column. But if the type does not exist in the search_path then the coordinator fails to parse the typename back to the type. So the datanode must send the schema name along with the type name. Per report and test case by Hengbing Wang @ Microfun. Added a new test file and a few test cases to cover this area.
-rw-r--r--src/backend/access/common/printtup.c10
-rw-r--r--src/backend/catalog/namespace.c1
-rw-r--r--src/backend/pgxc/pool/execRemote.c11
-rw-r--r--src/test/regress/expected/xl_misc.out164
-rw-r--r--src/test/regress/parallel_schedule2
-rw-r--r--src/test/regress/sql/xl_misc.sql95
6 files changed, 280 insertions, 3 deletions
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index 78704dafd9..e89484aac3 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -215,8 +215,16 @@ SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
*/
if (IsConnFromCoord())
{
- char *typename;
+ char *typename, *typeschema_name;
+ Oid typeschema_oid;
+
typename = get_typename(atttypid);
+ typeschema_oid = get_typ_namespace(atttypid);
+ typeschema_name = isTempNamespace(typeschema_oid) ?
+ "pg_temp" :
+ get_namespace_name(typeschema_oid);
+
+ pq_sendstring(&buf, typeschema_name);
pq_sendstring(&buf, typename);
}
#endif
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index cd03f2b6bf..c8033f5054 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -29,6 +29,7 @@
#endif
#include "access/xlog.h"
#include "catalog/dependency.h"
+#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_collation.h"
diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c
index b9337d70e5..1b547b21be 100644
--- a/src/backend/pgxc/pool/execRemote.c
+++ b/src/backend/pgxc/pool/execRemote.c
@@ -24,6 +24,7 @@
#include "access/transam.h"
#include "access/xact.h"
#include "access/relscan.h"
+#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "catalog/pgxc_node.h"
#include "commands/prepare.h"
@@ -309,8 +310,10 @@ create_tuple_desc(char *msg_body, size_t len)
AttrNumber attnum;
char *attname;
char *typname;
+ char *typschema;
Oid oidtypeid;
int32 typemode, typmod;
+ List *namelist = NIL;
attnum = (AttrNumber) i;
@@ -318,8 +321,14 @@ create_tuple_desc(char *msg_body, size_t len)
attname = msg_body;
msg_body += strlen(attname) + 1;
+ /* type schema name */
+ typschema = msg_body;
+ namelist = lappend(namelist, makeString(typschema));
+ msg_body += strlen(typschema) + 1;
+
/* type name */
typname = msg_body;
+ namelist = lappend(namelist, makeString(typname));
msg_body += strlen(typname) + 1;
/* table OID, ignored */
@@ -343,7 +352,7 @@ create_tuple_desc(char *msg_body, size_t len)
msg_body += 2;
/* Get the OID type and mode type from typename */
- parseTypeString(quote_identifier(typname), &oidtypeid, NULL, false);
+ parseTypeString(NameListToQuotedString(namelist), &oidtypeid, NULL, false);
TupleDescInitEntry(result, attnum, attname, oidtypeid, typmod, 0);
}
diff --git a/src/test/regress/expected/xl_misc.out b/src/test/regress/expected/xl_misc.out
new file mode 100644
index 0000000000..6a13035745
--- /dev/null
+++ b/src/test/regress/expected/xl_misc.out
@@ -0,0 +1,164 @@
+-- try a special column name
+create table xltest_type ("primary" integer, b integer);
+insert into xltest_type values(1, 11);
+insert into xltest_type values(2, 12);
+insert into xltest_type values(3, 13);
+select count(*) from xltest_type;
+ count
+-------
+ 3
+(1 row)
+
+set enable_fast_query_shipping to false;
+select count(*) from xltest_type;
+ count
+-------
+ 3
+(1 row)
+
+select * from xltest_type order by "primary";
+ primary | b
+---------+----
+ 1 | 11
+ 2 | 12
+ 3 | 13
+(3 rows)
+
+drop table xltest_type;
+-- repeat with a temp table
+set enable_fast_query_shipping to default;
+create temp table xltest_type ("primary" integer, b integer);
+insert into xltest_type values(1, 11);
+insert into xltest_type values(2, 12);
+insert into xltest_type values(3, 13);
+select count(*) from xltest_type;
+ count
+-------
+ 3
+(1 row)
+
+set enable_fast_query_shipping to false;
+select count(*) from xltest_type;
+ count
+-------
+ 3
+(1 row)
+
+select * from xltest_type order by "primary";
+ primary | b
+---------+----
+ 1 | 11
+ 2 | 12
+ 3 | 13
+(3 rows)
+
+drop table xltest_type;
+-- try a special table name
+set enable_fast_query_shipping to default;
+create table "XLTEST_type" ("primary" integer, b integer);
+-- fail
+insert into xltest_type values(1, 11);
+ERROR: relation "xltest_type" does not exist
+LINE 1: insert into xltest_type values(1, 11);
+ ^
+-- fail
+insert into XLTEST_type values(1, 11);
+ERROR: relation "xltest_type" does not exist
+LINE 1: insert into XLTEST_type values(1, 11);
+ ^
+-- ok
+insert into "XLTEST_type" values(1, 11);
+insert into "XLTEST_type" values(2, 12);
+insert into "XLTEST_type" values(3, 13);
+-- fail
+select count(*) from XLTEST_type;
+ERROR: relation "xltest_type" does not exist
+LINE 1: select count(*) from XLTEST_type;
+ ^
+-- ok
+select count(*) from "XLTEST_type";
+ count
+-------
+ 3
+(1 row)
+
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+ array_agg
+------------
+ {"(1,11)"}
+(1 row)
+
+set enable_fast_query_shipping to false;
+-- fail
+select count(*) from XLTEST_type;
+ERROR: relation "xltest_type" does not exist
+LINE 1: select count(*) from XLTEST_type;
+ ^
+-- ok
+select count(*) from "XLTEST_type";
+ count
+-------
+ 3
+(1 row)
+
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+ array_agg
+------------
+ {"(1,11)"}
+(1 row)
+
+-- fail
+drop table xltest_type;
+ERROR: table "xltest_type" does not exist
+-- fail
+drop table XLTEST_type;
+ERROR: table "xltest_type" does not exist
+-- fail
+drop table "XLTEST_TYPE";
+ERROR: table "XLTEST_TYPE" does not exist
+-- ok
+drop table "XLTEST_type";
+-- try schema qualification for simple schema name
+set enable_fast_query_shipping to default;
+create schema xltypeschema;
+create table xltypeschema."XLTEST_type" ("primary" integer, b integer);
+insert into xltypeschema."XLTEST_type" values(1, 11);
+insert into xltypeschema."XLTEST_type" values(2, 12);
+insert into xltypeschema."XLTEST_type" values(3, 13);
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+ERROR: relation "XLTEST_type" does not exist
+LINE 1: select array_agg(c.*) from "XLTEST_type" c where c.primary =...
+ ^
+select array_agg(c.*) from xltypeschema."XLTEST_type" c where c.primary = 1;
+ array_agg
+------------
+ {"(1,11)"}
+(1 row)
+
+drop table xltypeschema."XLTEST_type";
+-- try schema qualification for special schema name
+create schema "XL.Schema";
+create table "XL.Schema"."XLTEST_type" ("primary" integer, b integer);
+insert into "XL.Schema"."XLTEST_type" values(1, 11);
+insert into "XL.Schema"."XLTEST_type" values(2, 12);
+insert into "XL.Schema"."XLTEST_type" values(3, 13);
+select array_agg(c.*) from "XL.Schema"."XLTEST_type" c where c.primary = 1;
+ array_agg
+------------
+ {"(1,11)"}
+(1 row)
+
+-- without schema, fail
+select array_agg(c.*) from "XLTEST_type" c;
+ERROR: relation "XLTEST_type" does not exist
+LINE 1: select array_agg(c.*) from "XLTEST_type" c;
+ ^
+set search_path = "XL.Schema";
+-- should work
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+ array_agg
+------------
+ {"(1,11)"}
+(1 row)
+
+drop table "XL.Schema"."XLTEST_type";
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index ac09824d43..1bcbf3b5ef 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -150,4 +150,4 @@ test: xc_prepared_xacts
test: xc_notrans_block
# This runs XL specific tests
-test: xl_primary_key xl_foreign_key xl_distribution_column_types xl_alter_table xl_distribution_column_types_modulo xl_plan_pushdown xl_functions xl_limitations xl_user_defined_functions xl_join xl_distributed_xact xl_create_table
+test: xl_misc xl_primary_key xl_foreign_key xl_distribution_column_types xl_alter_table xl_distribution_column_types_modulo xl_plan_pushdown xl_functions xl_limitations xl_user_defined_functions xl_join xl_distributed_xact xl_create_table
diff --git a/src/test/regress/sql/xl_misc.sql b/src/test/regress/sql/xl_misc.sql
new file mode 100644
index 0000000000..3ad64c5b96
--- /dev/null
+++ b/src/test/regress/sql/xl_misc.sql
@@ -0,0 +1,95 @@
+
+-- try a special column name
+create table xltest_type ("primary" integer, b integer);
+insert into xltest_type values(1, 11);
+insert into xltest_type values(2, 12);
+insert into xltest_type values(3, 13);
+
+select count(*) from xltest_type;
+set enable_fast_query_shipping to false;
+select count(*) from xltest_type;
+select * from xltest_type order by "primary";
+
+drop table xltest_type;
+
+
+-- repeat with a temp table
+set enable_fast_query_shipping to default;
+create temp table xltest_type ("primary" integer, b integer);
+insert into xltest_type values(1, 11);
+insert into xltest_type values(2, 12);
+insert into xltest_type values(3, 13);
+
+select count(*) from xltest_type;
+set enable_fast_query_shipping to false;
+select count(*) from xltest_type;
+select * from xltest_type order by "primary";
+
+drop table xltest_type;
+
+
+-- try a special table name
+set enable_fast_query_shipping to default;
+create table "XLTEST_type" ("primary" integer, b integer);
+-- fail
+insert into xltest_type values(1, 11);
+-- fail
+insert into XLTEST_type values(1, 11);
+-- ok
+insert into "XLTEST_type" values(1, 11);
+insert into "XLTEST_type" values(2, 12);
+insert into "XLTEST_type" values(3, 13);
+
+-- fail
+select count(*) from XLTEST_type;
+-- ok
+select count(*) from "XLTEST_type";
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+
+set enable_fast_query_shipping to false;
+-- fail
+select count(*) from XLTEST_type;
+-- ok
+select count(*) from "XLTEST_type";
+
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+
+-- fail
+drop table xltest_type;
+-- fail
+drop table XLTEST_type;
+-- fail
+drop table "XLTEST_TYPE";
+-- ok
+drop table "XLTEST_type";
+
+-- try schema qualification for simple schema name
+set enable_fast_query_shipping to default;
+create schema xltypeschema;
+create table xltypeschema."XLTEST_type" ("primary" integer, b integer);
+insert into xltypeschema."XLTEST_type" values(1, 11);
+insert into xltypeschema."XLTEST_type" values(2, 12);
+insert into xltypeschema."XLTEST_type" values(3, 13);
+
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+select array_agg(c.*) from xltypeschema."XLTEST_type" c where c.primary = 1;
+
+drop table xltypeschema."XLTEST_type";
+
+-- try schema qualification for special schema name
+create schema "XL.Schema";
+create table "XL.Schema"."XLTEST_type" ("primary" integer, b integer);
+insert into "XL.Schema"."XLTEST_type" values(1, 11);
+insert into "XL.Schema"."XLTEST_type" values(2, 12);
+insert into "XL.Schema"."XLTEST_type" values(3, 13);
+
+select array_agg(c.*) from "XL.Schema"."XLTEST_type" c where c.primary = 1;
+
+-- without schema, fail
+select array_agg(c.*) from "XLTEST_type" c;
+set search_path = "XL.Schema";
+-- should work
+select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
+
+drop table "XL.Schema"."XLTEST_type";
+