Skip to content

Commit

Permalink
Schema qualify UDTs in multi-node
Browse files Browse the repository at this point in the history
"create_distributed_hypertable" fails on the datanodes if the columns
involved in the underlying non-default schema-qualified PG table are
using user defined types (UDTs) from another non-standard schema.

This happens because we explicitly set the namespace during the table
creation on the datanode which doesn't allow us to lookup other
schemas. We now unconditionally schema-qualify the UDT while sending
the SQL from access node to the datanode to avoid this.

Includes test case changes.

Issue reported by and general fix provided by @phemmer

Fixes #3543
  • Loading branch information
nikkhils committed Sep 30, 2021
1 parent 5b16ac0 commit 9b395d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tsl/src/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,22 @@ deparse_columns(StringInfo stmt, Relation rel)
{
int dim_idx;
Form_pg_attribute attr = TupleDescAttr(rel_desc, att_idx);
bits16 flags = FORMAT_TYPE_TYPEMOD_GIVEN;

if (attr->attisdropped)
continue;

/*
* if it's not a builtin type then schema qualify the same. There's a function
* deparse_type_name in fdw, but we don't want cross linking unnecessarily
*/
if (attr->atttypid >= FirstBootstrapObjectId)
flags |= FORMAT_TYPE_FORCE_QUALIFY;

appendStringInfo(stmt,
"\"%s\" %s",
NameStr(attr->attname),
format_type_with_typemod(attr->atttypid, attr->atttypmod));
format_type_extended(attr->atttypid, attr->atttypmod, flags));

if (attr->attnotnull)
appendStringInfoString(stmt, " NOT NULL");
Expand Down
21 changes: 20 additions & 1 deletion tsl/test/t/001_simple_multinode.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use AccessNode;
use DataNode;
use TestLib;
use Test::More tests => 9;
use Test::More tests => 12;

#Initialize all the multi-node instances
my $an = AccessNode->create('an');

my $dn1 = DataNode->create('dn1');
my $dn2 = DataNode->create('dn2');

Expand Down Expand Up @@ -51,6 +52,24 @@
"_timescaledb_internal._dist_hyper_1_2_chunk",
'DN2 shows correct set of chunks');

# Check that distributed tables in non-default schema and also containing user created types
# in another schema are created properly
$query = q[CREATE SCHEMA myschema];
$an->safe_psql('postgres', "$query; CALL distributed_exec('$query');");
$query = q[CREATE TYPE public.full_address AS (city VARCHAR(90), street VARCHAR(90))];
$an->safe_psql('postgres', "$query; CALL distributed_exec('$query');");

# Create a table in the myschema schema using this unqualified UDT. Should work
$an->safe_psql('postgres', "CREATE TABLE myschema.test (time timestamp, a full_address);");

# A distributed table creation followed by sample INSERT should succeed now
$an->safe_psql('postgres', "SELECT create_distributed_hypertable('myschema.test', 'time');");
$an->safe_psql('postgres', "INSERT INTO myschema.test VALUES ('2018-03-02 1:00', ('Kilimanjaro', 'Diamond St'));");
$an->psql_is(
'postgres', "SELECT * from myschema.test", q[2018-03-02 01:00:00|(Kilimanjaro,"Diamond St")],
'AN shows correct data with UDT from different schema'
);

done_testing();

1;

0 comments on commit 9b395d7

Please sign in to comment.