修复pg_partition_size()函数宕机问题。

当参数指定的表不是分区表或指定的分区不属于指定分区表的情况,报错。
This commit is contained in:
playrest
2023-06-21 12:14:17 +08:00
parent c5f1e68421
commit c3123e148f
7 changed files with 275 additions and 13 deletions

View File

@ -1508,6 +1508,13 @@ static int64 calculate_partition_size(Oid partTableOid, Oid partOid)
return 0;
}
if (!RelationIsPartitioned(partTableRel)) {
relation_close(partTableRel, AccessShareLock);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation %u is not a partitioned table", partTableOid)));
}
if (!RelationIsSubPartitioned(partTableRel)) {
partition = partitionOpen(partTableRel, partOid, AccessShareLock);
partRel = partitionGetRelation(partTableRel, partition);
@ -1629,6 +1636,13 @@ static int64 calculate_partition_indexes_size(Oid partTableOid, Oid partOid)
return 0;
}
if (!RelationIsPartitioned(partTableRel)) {
relation_close(partTableRel, AccessShareLock);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation %u is not a partitioned table", partTableOid)));
}
List *partOidList = NIL;
if (!RelationIsSubPartitioned(partTableRel)) {
partOidList = list_make1_oid(partOid);

View File

@ -9790,12 +9790,19 @@ Partition partitionOpen(Relation relation, Oid partitionOid, LOCKMODE lockmode,
errdetail("this partition may have already been dropped")));
}
Assert(RelationIsPartitioned(relation));
/* subpartition table open subpartition, which is judged by partitionOpen() */
if (RelationIsSubPartitioned(relation) && relation->rd_id != parentOid) {
/* partitionOid is subpartition oid */
p = SubPartitionOidGetPartition(relation, partitionOid, lockmode);
Assert(relation->rd_id == partid_get_parentid(p->pd_part->parentid));
return p;
}
if (relation->rd_id != parentOid)
ereport(ERROR,
(errcode(ERRCODE_PARTITION_ERROR),
errmsg("partition %u does not exist on relation \"%s\"", partitionOid,
RelationGetRelationName(relation))));
/*
* If we are executing select for update/share operation,
@ -9933,6 +9940,8 @@ Partition tryPartitionOpen(Relation relation, Oid partition_id, LOCKMODE lockmod
return NULL;
}
Assert(RelationIsPartitioned(relation));
/* subpartition table open subpartition, which is judged by tryPartitionOpen() */
if (RelationIsSubPartitioned(relation) && relation->rd_id != parentid) {
if (!SearchSysCacheExists1(PARTRELID, ObjectIdGetDatum(partition_id))) {
return NULL;
@ -9942,6 +9951,8 @@ Partition tryPartitionOpen(Relation relation, Oid partition_id, LOCKMODE lockmod
Assert(relation->rd_id == partid_get_parentid(p->pd_part->parentid));
return p;
}
if (relation->rd_id != parentid)
return NULL;
/*
* If we are executing select for update/share operation,

View File

@ -67,7 +67,6 @@ partition test_pg_index_size_ordinary_p2 values less than (4, 4)
create index test_pg_index_size_ordinary_index_a on test_pg_index_size_ordinary (a) local;
create index test_pg_index_size_ordinary_index_b on test_pg_index_size_ordinary (b) local;
create index test_pg_index_size_ordinary_index_hash on test_pg_index_size_ordinary using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_index_size_ordinary values (1, 1), (3, 3);
-- size: 294912 = 2*2*32768 + 2*81920
select pg_indexes_size('test_pg_index_size_ordinary') > 0;
@ -87,7 +86,6 @@ partition test_pg_index_size_index_toast_p2 values less than ('D', 'D')
create index test_pg_index_size_index_toast_a on test_pg_index_size_index_toast (a) local;
create index test_pg_index_size_index_toast_b on test_pg_index_size_index_toast (b) local;
create index test_pg_index_size_index_toast_hash on test_pg_index_size_index_toast using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_index_size_index_toast values ('A', 'A'), ('C', 'C');
-- size: 196608 = 2*2*24576 + 2*32768
select pg_indexes_size('test_pg_index_size_index_toast') > 0;
@ -123,7 +121,6 @@ partition test_pg_total_relation_size_index_p2 values less than (4)
);
create index test_pg_total_relation_size_index_a on test_pg_total_relation_size_index (a) local;
create index test_pg_total_relation_size_index_hash on test_pg_total_relation_size_index using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_total_relation_size_index values (1), (3);
-- size: 278528 = 2*24576 + 2*32768 + 2*81920
select pg_total_relation_size ('test_pg_total_relation_size_index') > 0;
@ -158,7 +155,6 @@ partition test_pg_total_relation_size_toast_index_p2 values less than ('D')
);
create index test_pg_total_relation_size_toast_index_a on test_pg_total_relation_size_toast_index (a) local;
create index test_pg_total_relation_size_toast_index_hash on test_pg_total_relation_size_toast_index using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_total_relation_size_toast_index values ('A'), ('C');
-- size: 262144 = 2*24576 + 2*24576 + 2*32768 + 2*32768
select pg_total_relation_size ('test_pg_total_relation_size_toast_index') > 0;
@ -194,7 +190,6 @@ partition test_pg_relation_size_index_p2 values less than (4)
);
create index test_pg_relation_size_index_a on test_pg_relation_size_index (a) local;
create index test_pg_relation_size_index_hash on test_pg_relation_size_index using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_relation_size_index values (1), (3);
-- size: 65536 = 2*32768
select pg_relation_size ('test_pg_relation_size_index_a') > 0;
@ -205,9 +200,11 @@ select pg_relation_size ('test_pg_relation_size_index_a') > 0;
-- size: 163840 = 2*81920
select pg_relation_size ('test_pg_relation_size_index_hash') > 0;
ERROR: relation "test_pg_relation_size_index_hash" does not exist
LINE 1: select pg_relation_size ('test_pg_relation_size_index_hash')...
^
?column?
----------
t
(1 row)
drop table test_pg_relation_size_index;
-- c. test table has toast
create table test_pg_relation_size_toast (a text)
@ -234,7 +231,6 @@ partition test_pg_relation_size_main_p1 values less than (4)
);
create index test_pg_relation_size_main_a on test_pg_relation_size_main (a) local;
create index test_pg_relation_size_main_hash on test_pg_relation_size_main using hash (a) local;
ERROR: access method "hash" does not support row store
insert into test_pg_relation_size_main values (1), (3);
-- size: 49152 = 2*24576
select pg_relation_size ('test_pg_relation_size_main', 'main') > 0;
@ -252,9 +248,11 @@ select pg_relation_size ('test_pg_relation_size_main_a', 'main') > 0;
-- size: 163840 = 2*81920
select pg_relation_size ('test_pg_relation_size_main_hash', 'main') > 0;
ERROR: relation "test_pg_relation_size_main_hash" does not exist
LINE 1: select pg_relation_size ('test_pg_relation_size_main_hash', ...
^
?column?
----------
t
(1 row)
drop table test_pg_relation_size_main;
-- 6. pg_partition_size
create table test_pg_partition_size (a int)
@ -283,6 +281,29 @@ LINE 1: select pg_partition_size('test_pg_partition_size', 19000)>0;
--ERROR
select pg_partition_size('test_pg_partition_size', 'test_pg_partition_size_p2')>0;
ERROR: partition "test_pg_partition_size_p2" does not exist
create table test_pg_partition_size2 (a int);
create table test_pg_partition_size3 (a int)
partition by range (a)
(
partition p1 values less than (4)
);
--ERROR regular table
select pg_partition_size('test_pg_partition_size2', 'test_pg_partition_size_p1')>0;
ERROR: partition "test_pg_partition_size_p1" does not exist
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_size'::regclass and relname='test_pg_partition_size_p1';
--?ERROR: relation .* is not a partitioned table
--ERROR partitioned table does not match the partition
select pg_partition_size('test_pg_partition_size3', 'test_pg_partition_size2')>0;
ERROR: partition "test_pg_partition_size2" does not exist
select pg_partition_size('test_pg_partition_size3', 'test_pg_partition_size_p1')>0;
ERROR: partition "test_pg_partition_size_p1" does not exist
select pg_partition_size('test_pg_partition_size3'::regclass::oid, 'test_pg_partition_size2'::regclass::oid)>0;
--?ERROR: partition .* does not exist on relation "test_pg_partition_size3" when find parent oid
DETAIL: this partition may have already been dropped
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_size'::regclass and relname='test_pg_partition_size_p1';
--?ERROR: partition .* does not exist on relation "test_pg_partition_size3"
drop table test_pg_partition_size3;
drop table test_pg_partition_size2;
drop table test_pg_partition_size;
-- 7. pg_partition_indexes_size
create table test_pg_partition_indexes_size (a int)
@ -312,6 +333,51 @@ LINE 1: select pg_partition_indexes_size('test_pg_partition_indexes_...
--ERROR
select pg_partition_indexes_size('test_pg_partition_indexes_size', 'test_pg_partition_indexes_size_p2')>0;
ERROR: partition "test_pg_partition_indexes_size_p2" does not exist
create table test_pg_partition_indexes_size2 (a int);
create table test_pg_partition_indexes_size3 (a int)
partition by range (a)
(
partition p1 values less than (4)
);
insert into test_pg_partition_indexes_size3 values (1);
-- no local partition index, return 0
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'p1');
pg_partition_indexes_size
---------------------------
0
(1 row)
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, 12345::oid);
pg_partition_indexes_size
---------------------------
0
(1 row)
create index test_pg_partition_indexes_size3_index on test_pg_partition_indexes_size3 (a) local;
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'p1')>0;
?column?
----------
t
(1 row)
--ERROR regular table
select pg_partition_indexes_size('test_pg_partition_indexes_size2', 'test_pg_partition_indexes_size_p1')>0;
ERROR: partition "test_pg_partition_indexes_size_p1" does not exist
select pg_partition_indexes_size('test_pg_partition_indexes_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_indexes_size'::regclass and relname='test_pg_partition_indexes_size_p1';
--?ERROR: relation .* is not a partitioned table
--ERROR partitioned table does not match the partition
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'test_pg_partition_indexes_size2')>0;
ERROR: partition "test_pg_partition_indexes_size2" does not exist
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'test_pg_partition_indexes_size_p1')>0;
ERROR: partition "test_pg_partition_indexes_size_p1" does not exist
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, 'test_pg_partition_indexes_size2'::regclass::oid)>0;
--?ERROR: The local index .* on the partition .* not exist.
HINT: In redistribution, local parititon index maybe not exists.
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_indexes_size'::regclass and relname='test_pg_partition_indexes_size_p1';
--?ERROR: The local index .* on the partition .* not exist.
HINT: In redistribution, local parititon index maybe not exists.
drop table test_pg_partition_indexes_size3;
drop table test_pg_partition_indexes_size2;
drop table test_pg_partition_indexes_size;
create table test_pg_table_size_toast_ord (a text);
create table test_pg_table_size_toast_rt (a text)

View File

@ -187,6 +187,15 @@ SELECT pg_partition_size('range_list_sales', 'customer1') =
t
(1 row)
-- (oid, oid)
SELECT (SELECT pg_partition_size('range_list_sales'::regclass::oid, oid) from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1')
=
(SELECT sum(pg_partition_size('range_list_sales'::regclass::oid, oid)) from pg_partition where parentid in (SELECT oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1'));
?column?
----------
t
(1 row)
-- should be equal
SELECT pg_partition_size('range_list_sales', 'customer4') = pg_partition_size('range_list_sales', 'customer4_channel1');
?column?
@ -198,6 +207,38 @@ SELECT pg_partition_size('range_list_sales', 'customer4') = pg_partition_size('r
SELECT pg_partition_size('range_list_sales', 'parttemp');
ERROR: partition "parttemp" does not exist
CONTEXT: referenced column: pg_partition_size
create table test_pg_partition_size2 (a int);
create table test_pg_partition_size3 (a int, b int)
partition by range (a)
subpartition by hash (b)
(
partition p1 values less than (4)
(subpartition sp1)
);
--ERROR regular table
select pg_partition_size('test_pg_partition_size2', 'customer1')>0;
ERROR: partition "customer1" does not exist
select pg_partition_size('test_pg_partition_size2', 'customer1_channel1')>0;
ERROR: partition "customer1_channel1" does not exist
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
--?ERROR: relation .* is not a partitioned table
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--?ERROR: relation .* is not a partitioned table
--ERROR partitioned table does not match the partition
select pg_partition_size('test_pg_partition_size3', 'range_list_sales')>0;
ERROR: partition "range_list_sales" does not exist
select pg_partition_size('test_pg_partition_size3', 'customer1')>0;
ERROR: partition "customer1" does not exist
select pg_partition_size('test_pg_partition_size3', 'customer1_channel1')>0;
ERROR: partition "customer1_channel1" does not exist
select pg_partition_size('test_pg_partition_size3'::regclass::oid, 'range_list_sales'::regclass::oid)>0;
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
-- 6. pg_partition_indexes_size
SELECT pg_partition_indexes_size('range_list_sales', 'customer1');
pg_partition_indexes_size
@ -234,6 +275,15 @@ SELECT pg_partition_indexes_size('range_list_sales', 'customer1') =
t
(1 row)
-- (oid, oid)
SELECT (SELECT pg_partition_indexes_size('range_list_sales'::regclass::oid, oid) from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1')
=
(SELECT sum(pg_partition_indexes_size('range_list_sales'::regclass::oid, oid)) from pg_partition where parentid in (SELECT oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1'));
?column?
----------
t
(1 row)
-- should be equal
SELECT pg_partition_indexes_size('range_list_sales', 'customer4') = pg_partition_indexes_size('range_list_sales', 'customer4_channel1');
?column?
@ -241,7 +291,35 @@ SELECT pg_partition_indexes_size('range_list_sales', 'customer4') = pg_partition
t
(1 row)
CREATE INDEX test_pg_partition_size2_idx ON test_pg_partition_size2(a);
CREATE INDEX test_pg_partition_size3_idx ON test_pg_partition_size3(a) LOCAL;
--ERROR regular table
select pg_partition_indexes_size('test_pg_partition_size2', 'customer1')>0;
ERROR: partition "customer1" does not exist
select pg_partition_indexes_size('test_pg_partition_size2', 'customer1_channel1')>0;
ERROR: partition "customer1_channel1" does not exist
select pg_partition_indexes_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
--?ERROR: relation .* is not a partitioned table
select pg_partition_indexes_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--?ERROR: relation .* is not a partitioned table
--ERROR partitioned table does not match the partition
select pg_partition_indexes_size('test_pg_partition_size3', 'range_list_sales')>0;
ERROR: partition "range_list_sales" does not exist
select pg_partition_indexes_size('test_pg_partition_size3', 'customer1')>0;
ERROR: partition "customer1" does not exist
select pg_partition_indexes_size('test_pg_partition_size3', 'customer1_channel1')>0;
ERROR: partition "customer1_channel1" does not exist
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, 'range_list_sales'::regclass::oid)>0;
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--?ERROR: .* is not a partition/subpartition of subpartitioned table .*
-- finish, clean
DROP TABLE test_pg_partition_size2;
DROP TABLE test_pg_partition_size3;
DROP TABLE range_list_sales;
DROP SCHEMA hw_subpartition_size CASCADE;
RESET CURRENT_SCHEMA;

View File

@ -90,7 +90,7 @@ test: single_node_sha
test: test_b_format_collate charset_b_format
# test subpartition
test: hw_subpartition_createtable hw_subpartition_scan hw_subpartition_select hw_subpartition_split hw_subpartition_truncate hw_subpartition_update hw_subpartition_gpi hw_subpartition_analyze_vacuum hw_subpartition_alter_table hw_subpartition_index hw_subpartition_add_drop_partition hw_subpartition_tablespace hw_subpartition_ddl_index hw_subpartition_size
test: hw_subpartition_createtable hw_subpartition_scan hw_subpartition_select hw_subpartition_split hw_subpartition_truncate hw_subpartition_update hw_subpartition_gpi hw_subpartition_analyze_vacuum hw_subpartition_alter_table hw_subpartition_index hw_subpartition_add_drop_partition hw_subpartition_tablespace hw_subpartition_ddl_index hw_subpartition_size hw_partition_size hw_cstore_partition_size
test: hw_subpartition_vacuum_partition hw_subpartition_tablespace_global
test: gs_dump_subpartition
test: partition_dml_operations partition_minmax partition_pruning hw_partitionno hw_partition_parallel

View File

@ -275,6 +275,23 @@ select pg_partition_size('test_pg_partition_size', 19000)>0;
--ERROR
select pg_partition_size('test_pg_partition_size', 'test_pg_partition_size_p2')>0;
create table test_pg_partition_size2 (a int);
create table test_pg_partition_size3 (a int)
partition by range (a)
(
partition p1 values less than (4)
);
--ERROR regular table
select pg_partition_size('test_pg_partition_size2', 'test_pg_partition_size_p1')>0;
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_size'::regclass and relname='test_pg_partition_size_p1';
--ERROR partitioned table does not match the partition
select pg_partition_size('test_pg_partition_size3', 'test_pg_partition_size2')>0;
select pg_partition_size('test_pg_partition_size3', 'test_pg_partition_size_p1')>0;
select pg_partition_size('test_pg_partition_size3'::regclass::oid, 'test_pg_partition_size2'::regclass::oid)>0;
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_size'::regclass and relname='test_pg_partition_size_p1';
drop table test_pg_partition_size3;
drop table test_pg_partition_size2;
drop table test_pg_partition_size;
@ -296,6 +313,32 @@ select pg_partition_indexes_size('test_pg_partition_indexes_size', 19000)>0;
--ERROR
select pg_partition_indexes_size('test_pg_partition_indexes_size', 'test_pg_partition_indexes_size_p2')>0;
create table test_pg_partition_indexes_size2 (a int);
create table test_pg_partition_indexes_size3 (a int)
partition by range (a)
(
partition p1 values less than (4)
);
insert into test_pg_partition_indexes_size3 values (1);
-- no local partition index, return 0
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'p1');
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, 12345::oid);
create index test_pg_partition_indexes_size3_index on test_pg_partition_indexes_size3 (a) local;
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'p1')>0;
--ERROR regular table
select pg_partition_indexes_size('test_pg_partition_indexes_size2', 'test_pg_partition_indexes_size_p1')>0;
select pg_partition_indexes_size('test_pg_partition_indexes_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_indexes_size'::regclass and relname='test_pg_partition_indexes_size_p1';
--ERROR partitioned table does not match the partition
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'test_pg_partition_indexes_size2')>0;
select pg_partition_indexes_size('test_pg_partition_indexes_size3', 'test_pg_partition_indexes_size_p1')>0;
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, 'test_pg_partition_indexes_size2'::regclass::oid)>0;
select pg_partition_indexes_size('test_pg_partition_indexes_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'test_pg_partition_indexes_size'::regclass and relname='test_pg_partition_indexes_size_p1';
drop table test_pg_partition_indexes_size3;
drop table test_pg_partition_indexes_size2;
drop table test_pg_partition_indexes_size;

View File

@ -100,12 +100,39 @@ SELECT pg_partition_size('range_list_sales', 'customer1') =
pg_partition_size('range_list_sales', 'customer1_channel2') +
pg_partition_size('range_list_sales', 'customer1_channel3') +
pg_partition_size('range_list_sales', 'customer1_channel4');
-- (oid, oid)
SELECT (SELECT pg_partition_size('range_list_sales'::regclass::oid, oid) from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1')
=
(SELECT sum(pg_partition_size('range_list_sales'::regclass::oid, oid)) from pg_partition where parentid in (SELECT oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1'));
-- should be equal
SELECT pg_partition_size('range_list_sales', 'customer4') = pg_partition_size('range_list_sales', 'customer4_channel1');
-- invalid parameter, error
SELECT pg_partition_size('range_list_sales', 'parttemp');
create table test_pg_partition_size2 (a int);
create table test_pg_partition_size3 (a int, b int)
partition by range (a)
subpartition by hash (b)
(
partition p1 values less than (4)
(subpartition sp1)
);
--ERROR regular table
select pg_partition_size('test_pg_partition_size2', 'customer1')>0;
select pg_partition_size('test_pg_partition_size2', 'customer1_channel1')>0;
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
select pg_partition_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--ERROR partitioned table does not match the partition
select pg_partition_size('test_pg_partition_size3', 'range_list_sales')>0;
select pg_partition_size('test_pg_partition_size3', 'customer1')>0;
select pg_partition_size('test_pg_partition_size3', 'customer1_channel1')>0;
select pg_partition_size('test_pg_partition_size3'::regclass::oid, 'range_list_sales'::regclass::oid)>0;
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
select pg_partition_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
-- 6. pg_partition_indexes_size
SELECT pg_partition_indexes_size('range_list_sales', 'customer1');
SELECT pg_partition_indexes_size('range_list_sales', 'customer2_channel1');
@ -122,10 +149,33 @@ SELECT pg_partition_indexes_size('range_list_sales', 'customer1') =
pg_partition_indexes_size('range_list_sales', 'customer1_channel2') +
pg_partition_indexes_size('range_list_sales', 'customer1_channel3') +
pg_partition_indexes_size('range_list_sales', 'customer1_channel4');
-- (oid, oid)
SELECT (SELECT pg_partition_indexes_size('range_list_sales'::regclass::oid, oid) from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1')
=
(SELECT sum(pg_partition_indexes_size('range_list_sales'::regclass::oid, oid)) from pg_partition where parentid in (SELECT oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1'));
-- should be equal
SELECT pg_partition_indexes_size('range_list_sales', 'customer4') = pg_partition_indexes_size('range_list_sales', 'customer4_channel1');
CREATE INDEX test_pg_partition_size2_idx ON test_pg_partition_size2(a);
CREATE INDEX test_pg_partition_size3_idx ON test_pg_partition_size3(a) LOCAL;
--ERROR regular table
select pg_partition_indexes_size('test_pg_partition_size2', 'customer1')>0;
select pg_partition_indexes_size('test_pg_partition_size2', 'customer1_channel1')>0;
select pg_partition_indexes_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
select pg_partition_indexes_size('test_pg_partition_size2'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
--ERROR partitioned table does not match the partition
select pg_partition_indexes_size('test_pg_partition_size3', 'range_list_sales')>0;
select pg_partition_indexes_size('test_pg_partition_size3', 'customer1')>0;
select pg_partition_indexes_size('test_pg_partition_size3', 'customer1_channel1')>0;
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, 'range_list_sales'::regclass::oid)>0;
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1';
select pg_partition_indexes_size('test_pg_partition_size3'::regclass::oid, oid)>0 from pg_partition where parentid =
(select oid from pg_partition where parentid = 'range_list_sales'::regclass and relname='customer1') and relname = 'customer1_channel1';
-- finish, clean
DROP TABLE test_pg_partition_size2;
DROP TABLE test_pg_partition_size3;
DROP TABLE range_list_sales;
DROP SCHEMA hw_subpartition_size CASCADE;
RESET CURRENT_SCHEMA;