From: Pavan Deolasee Date: Mon, 20 Aug 2018 10:47:31 +0000 (+0530) Subject: Fix an oversight in 32025718755c4bbf100563fdc88e96225fc1b250 X-Git-Tag: XL_10_R1BETA1~29 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=e76fcc24391d8f940acc3a7b37b94cb7d1a7acde;p=postgres-xl.git Fix an oversight in 32025718755c4bbf100563fdc88e96225fc1b250 In passing, add test cases and fix other issues around fetching table sizes from remote nodes. For example, temp handling and names requiring quoting was broken for long too. Per report by Virendra Kumar and further tests by me. --- diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c index 6d5fe23c5f..d2f6c947f6 100644 --- a/src/backend/utils/adt/dbsize.c +++ b/src/backend/utils/adt/dbsize.c @@ -346,6 +346,9 @@ calculate_relation_size(RelFileNode *rfn, BackendId backend, ForkNumber forknum) char pathname[MAXPGPATH]; unsigned int segcount = 0; + if (OidIsValid(MyCoordId)) + backend = InvalidBackendId; + relationpath = relpathbackend(*rfn, backend, forknum); for (segcount = 0;; segcount++) @@ -1353,7 +1356,7 @@ pgxc_exec_sizefunc(Oid relOid, char *funcname, char *extra_arg) { int numnodes; Oid *nodelist; - char *relname = NULL; + const char *relname = NULL; StringInfoData buf; Relation rel; bool istemp; @@ -1361,20 +1364,25 @@ pgxc_exec_sizefunc(Oid relOid, char *funcname, char *extra_arg) rel = relation_open(relOid, AccessShareLock); istemp = (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP); + /* get relation name including any needed schema prefix and quoting */ + if (rel->rd_locator_info) + relname = RelationGetRelationName(rel); + initStringInfo(&buf); /* get relation name including any needed schema prefix and quoting */ if (!extra_arg) appendStringInfo(&buf, "SELECT pg_catalog.%s(c.oid) " "FROM pg_class c JOIN pg_namespace nc " - " ON c.oid = nc.oid ", funcname); + " ON c.relnamespace = nc.oid ", funcname); else appendStringInfo(&buf, "SELECT pg_catalog.%s(c.oid, '%s') " "FROM pg_class c JOIN pg_namespace nc " - " ON c.oid = nc.oid ", funcname, extra_arg); + " ON c.relnamespace = nc.oid ", funcname, extra_arg); if (!istemp) appendStringInfo(&buf, "WHERE relname = '%s' AND nc.nspname = '%s'", - relname, get_namespace_name(rel->rd_rel->relnamespace)); + relname, + get_namespace_name(rel->rd_rel->relnamespace)); else appendStringInfo(&buf, "WHERE relname = '%s' AND " " nc.oid = pg_my_temp_schema()", relname); diff --git a/src/test/regress/expected/xl_misc.out b/src/test/regress/expected/xl_misc.out index 1ac24603e8..e3202e39c0 100644 --- a/src/test/regress/expected/xl_misc.out +++ b/src/test/regress/expected/xl_misc.out @@ -206,3 +206,128 @@ 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" +-- size functions +create table tabsize (a int); +insert into tabsize values (1); +select pg_relation_size('tabsize'); -- only one node should have one heap page + pg_relation_size +------------------ + 8192 +(1 row) + +select pg_total_relation_size('tabsize'); -- no indexes or toast + pg_total_relation_size +------------------------ + 8192 +(1 row) + +insert into tabsize values (2), (3); +select pg_relation_size('tabsize'); -- both nodes should have one heap page each + pg_relation_size +------------------ + 16384 +(1 row) + +select pg_total_relation_size('tabsize'); -- no indexes or toast + pg_total_relation_size +------------------------ + 16384 +(1 row) + +create index testindx ON tabsize(a); +select pg_total_relation_size('tabsize'); -- index size gets added + pg_total_relation_size +------------------------ + 49152 +(1 row) + +alter table tabsize add column b text default 'x'; -- toast table +select pg_total_relation_size('tabsize'); -- toast table size gets added + pg_total_relation_size +------------------------ + 65536 +(1 row) + +create index testindx_b ON tabsize(b); +select pg_total_relation_size('tabsize'); -- another index on the table + pg_total_relation_size +------------------------ + 98304 +(1 row) + +-- check materialized view +create materialized view tabsize_mv1 as select a from tabsize; +select pg_total_relation_size('tabsize_mv1'); + pg_total_relation_size +------------------------ + 8192 +(1 row) + +create materialized view tabsize_mv2 as select a, b from tabsize; +select pg_total_relation_size('tabsize_mv2'); + pg_total_relation_size +------------------------ + 16384 +(1 row) + +drop table tabsize cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to materialized view tabsize_mv1 +drop cascades to materialized view tabsize_mv2 +-- check temp table +create temp table tabsize (a int); +insert into tabsize values (1), (2), (3); +select pg_relation_size('tabsize'); -- both nodes should have one heap page each + pg_relation_size +------------------ + 16384 +(1 row) + +select pg_total_relation_size('tabsize'); -- no indexes or toast + pg_total_relation_size +------------------------ + 16384 +(1 row) + +create index testindx ON tabsize(a); +select pg_total_relation_size('tabsize'); -- index size gets added + pg_total_relation_size +------------------------ + 49152 +(1 row) + +drop table tabsize; +-- check replicated tables +create table tabsize (a int) distribute by replication; +insert into tabsize values (1), (2), (3); +select pg_relation_size('tabsize'); + pg_relation_size +------------------ + 16384 +(1 row) + +select pg_total_relation_size('tabsize'); + pg_total_relation_size +------------------------ + 16384 +(1 row) + +drop table tabsize; +-- check schema qualified, special names etc +create schema "schema_SIZE"; +create table "schema_SIZE"."tab_SIZE" (a int); +insert into "schema_SIZE"."tab_SIZE" values (1), (2), (3); +select pg_relation_size('"schema_SIZE"."tab_SIZE"'); + pg_relation_size +------------------ + 16384 +(1 row) + +set search_path to "schema_SIZE"; +select pg_relation_size('"tab_SIZE"'); + pg_relation_size +------------------ + 16384 +(1 row) + +drop table "schema_SIZE"."tab_SIZE"; diff --git a/src/test/regress/sql/xl_misc.sql b/src/test/regress/sql/xl_misc.sql index 0e848d6ab1..30351efe9f 100644 --- a/src/test/regress/sql/xl_misc.sql +++ b/src/test/regress/sql/xl_misc.sql @@ -135,3 +135,54 @@ drop table test_a1 cascade; drop table test_a2; drop schema analyze_s1 cascade; drop schema "ANALYZE S2" cascade; + +-- size functions +create table tabsize (a int); +insert into tabsize values (1); +select pg_relation_size('tabsize'); -- only one node should have one heap page +select pg_total_relation_size('tabsize'); -- no indexes or toast +insert into tabsize values (2), (3); +select pg_relation_size('tabsize'); -- both nodes should have one heap page each +select pg_total_relation_size('tabsize'); -- no indexes or toast + +create index testindx ON tabsize(a); +select pg_total_relation_size('tabsize'); -- index size gets added + +alter table tabsize add column b text default 'x'; -- toast table +select pg_total_relation_size('tabsize'); -- toast table size gets added +create index testindx_b ON tabsize(b); +select pg_total_relation_size('tabsize'); -- another index on the table + +-- check materialized view +create materialized view tabsize_mv1 as select a from tabsize; +select pg_total_relation_size('tabsize_mv1'); +create materialized view tabsize_mv2 as select a, b from tabsize; +select pg_total_relation_size('tabsize_mv2'); + +drop table tabsize cascade; + +-- check temp table +create temp table tabsize (a int); +insert into tabsize values (1), (2), (3); +select pg_relation_size('tabsize'); -- both nodes should have one heap page each +select pg_total_relation_size('tabsize'); -- no indexes or toast + +create index testindx ON tabsize(a); +select pg_total_relation_size('tabsize'); -- index size gets added +drop table tabsize; + +-- check replicated tables +create table tabsize (a int) distribute by replication; +insert into tabsize values (1), (2), (3); +select pg_relation_size('tabsize'); +select pg_total_relation_size('tabsize'); +drop table tabsize; + +-- check schema qualified, special names etc +create schema "schema_SIZE"; +create table "schema_SIZE"."tab_SIZE" (a int); +insert into "schema_SIZE"."tab_SIZE" values (1), (2), (3); +select pg_relation_size('"schema_SIZE"."tab_SIZE"'); +set search_path to "schema_SIZE"; +select pg_relation_size('"tab_SIZE"'); +drop table "schema_SIZE"."tab_SIZE";