char pathname[MAXPGPATH];
unsigned int segcount = 0;
+ if (OidIsValid(MyCoordId))
+ backend = InvalidBackendId;
+
relationpath = relpathbackend(*rfn, backend, forknum);
for (segcount = 0;; segcount++)
{
int numnodes;
Oid *nodelist;
- char *relname = NULL;
+ const char *relname = NULL;
StringInfoData buf;
Relation rel;
bool istemp;
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);
(1 row)
drop table "XL.Schema"."XLTEST_type";
+-- 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";
drop table "XL.Schema"."XLTEST_type";
+-- 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";