Ensure table name is schema qualified while running remote ANALYZE
authorPavan Deolasee <[email protected]>
Tue, 14 Aug 2018 08:59:53 +0000 (14:29 +0530)
committerPavan Deolasee <[email protected]>
Tue, 14 Aug 2018 08:59:53 +0000 (14:29 +0530)
While sending down ANALYZE (COORDINATOR) command to the remote coordinator, we
must ensure that the table name is properly schema qualified. Also add a few
tests to confirm that this works as expected in various scenarios.

Per report by Virendra Kumar.

src/backend/commands/analyze.c
src/test/regress/expected/xl_misc.out
src/test/regress/sql/xl_misc.sql

index c439ff6cd25d1b967523abded7929ffcea7399a8..44adb3494eede4a68b9cd2a7e427eac79b7ffe1f 100644 (file)
@@ -3634,7 +3634,8 @@ analyze_remote_coordinators(Relation onerel)
                return;
 
        initStringInfo(&sql);
-       appendStringInfo(&sql, "ANALYZE (COORDINATOR) %s",
+       appendStringInfo(&sql, "ANALYZE (COORDINATOR) %s.%s",
+                       quote_identifier(get_namespace_name(RelationGetNamespace(onerel))),
                        quote_identifier(RelationGetRelationName(onerel)));
 
        step = makeNode(RemoteQuery);
index 6a130357453cfcb890c4a12057aae113bcbd2295..1ac24603e8e781296afd12530ceeb97de0e1d726 100644 (file)
@@ -162,3 +162,47 @@ select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
 (1 row)
 
 drop table "XL.Schema"."XLTEST_type";
+-- test ANALYZE
+set search_path to default;
+create table test_a1 (a int, b int);
+insert into test_a1 values (1, 10);
+analyze test_a1;
+-- check temp table handling
+create temp table test_a2 (a int, b int);
+insert into test_a2 values (1, 10);
+analyze test_a2;
+-- check schema qualification
+create schema analyze_s1;
+create table analyze_s1.test_a1 (a int, b int);
+create table analyze_s1.test_a3 (a int, b int);
+insert into analyze_s1.test_a1 values (1, 10);
+insert into analyze_s1.test_a3 values (1, 10);
+analyze analyze_s1.test_a1;
+analyze test_a3;                               -- error
+ERROR:  relation "test_a3" does not exist
+set search_path = 'analyze_s1';
+analyze test_a3;                               -- ok
+-- schema names requiring quoating
+create schema "ANALYZE S2";
+set search_path = 'ANALYZE S2';
+create table "TEST A4" (a int, b int);
+insert into "TEST A4" values (1, 10);
+set search_path to default;
+analyze "TEST A4";                             -- error
+ERROR:  relation "TEST A4" does not exist
+analyze "ANALYZE S2"."TEST A4";
+set search_path = 'ANALYZE S2';
+analyze "TEST A4";
+-- check materialised view
+set search_path to default;
+create materialized view analyze_mv1 as select * from test_a1;
+analyze analyze_mv1;
+drop table test_a1 cascade;
+NOTICE:  drop cascades to materialized view analyze_mv1
+drop table test_a2;
+drop schema analyze_s1 cascade;
+NOTICE:  drop cascades to 2 other objects
+DETAIL:  drop cascades to table analyze_s1.test_a1
+drop cascades to table analyze_s1.test_a3
+drop schema "ANALYZE S2" cascade;
+NOTICE:  drop cascades to table "ANALYZE S2"."TEST A4"
index 3ad64c5b96ddcc6ac1ed4fc648a47c66169ba473..0e848d6ab1c14f413ea03df33a7e4953e66c1c51 100644 (file)
@@ -93,3 +93,45 @@ select array_agg(c.*) from "XLTEST_type" c where c.primary = 1;
 
 drop table "XL.Schema"."XLTEST_type";
 
+-- test ANALYZE
+set search_path to default;
+create table test_a1 (a int, b int);
+insert into test_a1 values (1, 10);
+analyze test_a1;
+
+-- check temp table handling
+create temp table test_a2 (a int, b int);
+insert into test_a2 values (1, 10);
+analyze test_a2;
+
+-- check schema qualification
+create schema analyze_s1;
+create table analyze_s1.test_a1 (a int, b int);
+create table analyze_s1.test_a3 (a int, b int);
+insert into analyze_s1.test_a1 values (1, 10);
+insert into analyze_s1.test_a3 values (1, 10);
+analyze analyze_s1.test_a1;
+analyze test_a3;                               -- error
+set search_path = 'analyze_s1';
+analyze test_a3;                               -- ok
+
+-- schema names requiring quoating
+create schema "ANALYZE S2";
+set search_path = 'ANALYZE S2';
+create table "TEST A4" (a int, b int);
+insert into "TEST A4" values (1, 10);
+set search_path to default;
+analyze "TEST A4";                             -- error
+analyze "ANALYZE S2"."TEST A4";
+set search_path = 'ANALYZE S2';
+analyze "TEST A4";
+
+-- check materialised view
+set search_path to default;
+create materialized view analyze_mv1 as select * from test_a1;
+analyze analyze_mv1;
+
+drop table test_a1 cascade;
+drop table test_a2;
+drop schema analyze_s1 cascade;
+drop schema "ANALYZE S2" cascade;