提交 9537bfa7 编写于 作者: F Fenggang 提交者: Haisheng Yuan

minirepro: dump all the children relid of partition table

上级 6c1f1a7c
......@@ -14,6 +14,7 @@
#include "postgres_fe.h"
#include "funcapi.h"
#include "optimizer/prep.h"
#include "utils/builtins.h"
#include "rewrite/rewriteHandler.h"
#include "tcop/tcopprot.h"
......@@ -24,6 +25,25 @@ Datum gp_dump_query_oids(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(gp_dump_query_oids);
/*
* Find all child table relids including inheritances, interior and leaf
* partitions of given root table oid, append them into string buffer.
*/
static void
appendChildrenRelids(StringInfoData *relbuf, Oid relid)
{
List *relids = find_all_inheritors(relid);
if (list_length(relids) <= 1)
return;
relids = list_delete_first(relids);
ListCell *lc;
foreach(lc, relids)
{
appendStringInfo(relbuf, ",%u", lfirst_oid(lc));
}
}
static void
traverseQueryOids
(
......@@ -53,6 +73,7 @@ traverseQueryOids
if (relbuf->len != 0)
appendStringInfo(relbuf, "%s", ",");
appendStringInfo(relbuf, "%u", relid);
appendChildrenRelids(relbuf, relid);
}
}
}
......
......@@ -42,3 +42,83 @@ ERROR: syntax error at or near "with syntax"
LINE 1: SELECT with syntax error
^
QUERY: SELECT with syntax error
-- Test partition and inherited tables
CREATE TABLE minirepro_partition_test (id int, info json);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE foo (id int, year int, a int, b int, c int, d int, region text)
DISTRIBUTED BY (id)
PARTITION BY RANGE (year)
SUBPARTITION BY RANGE (a)
SUBPARTITION TEMPLATE (
START (1) END (2) EVERY (1),
DEFAULT SUBPARTITION other_a )
SUBPARTITION BY RANGE (b)
SUBPARTITION TEMPLATE (
START (1) END (2) EVERY (1),
DEFAULT SUBPARTITION other_b )
( START (2002) END (2003) EVERY (1),
DEFAULT PARTITION outlying_years );
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years" for table "foo"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_other_a" for table "foo_1_prt_outlying_years"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_other_a_3_prt_other_b" for table "foo_1_prt_outlying_years_2_prt_other_a"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_other_a_3_prt_2" for table "foo_1_prt_outlying_years_2_prt_other_a"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_2" for table "foo_1_prt_outlying_years"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_2_3_prt_other_b" for table "foo_1_prt_outlying_years_2_prt_2"
NOTICE: CREATE TABLE will create partition "foo_1_prt_outlying_years_2_prt_2_3_prt_2" for table "foo_1_prt_outlying_years_2_prt_2"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2" for table "foo"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_other_a" for table "foo_1_prt_2"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_other_a_3_prt_other_b" for table "foo_1_prt_2_2_prt_other_a"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_other_a_3_prt_2" for table "foo_1_prt_2_2_prt_other_a"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_2" for table "foo_1_prt_2"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_2_3_prt_other_b" for table "foo_1_prt_2_2_prt_2"
NOTICE: CREATE TABLE will create partition "foo_1_prt_2_2_prt_2_3_prt_2" for table "foo_1_prt_2_2_prt_2"
CREATE TABLE ptable (c1 text, c2 float);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c1' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE ctable (c3 char(2)) INHERITS (ptable);
NOTICE: Table has parent, setting distribution columns to match parent table
CREATE TABLE cctable (c4 char(2)) INHERITS (ctable);
NOTICE: Table has parent, setting distribution columns to match parent table
INSERT INTO minirepro_partition_test VALUES (1, (select gp_dump_query_oids('SELECT * FROM foo') ) :: json);
INSERT INTO minirepro_partition_test VALUES (2, (select gp_dump_query_oids('SELECT * FROM ptable') ) :: json);
INSERT INTO minirepro_partition_test VALUES (3, (select gp_dump_query_oids('SELECT * FROM pg_class') ) :: json);
SELECT array['foo'::regclass::oid::text,
'foo_1_prt_outlying_years'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a_3_prt_2'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2_3_prt_2'::regclass::oid::text,
'foo_1_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a_3_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_2_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_2_2_prt_2_3_prt_2'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 1),','));
?column?
----------
t
(1 row)
SELECT array['ptable'::regclass::oid::text,
'ctable'::regclass::oid::text,
'cctable'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 2),','));
?column?
----------
t
(1 row)
SELECT array['pg_class'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 3),','));
?column?
----------
t
(1 row)
DROP TABLE foo;
DROP TABLE cctable;
DROP TABLE ctable;
DROP TABLE ptable;
DROP TABLE minirepro_partition_test;
......@@ -12,3 +12,49 @@ SELECT gp_dump_query_oids('SELECT length(proname) FROM pg_proc; SELECT abs(relpa
-- Test error reporting on an invalid query.
SELECT gp_dump_query_oids('SELECT * FROM nonexistent_table');
SELECT gp_dump_query_oids('SELECT with syntax error');
-- Test partition and inherited tables
CREATE TABLE minirepro_partition_test (id int, info json);
CREATE TABLE foo (id int, year int, a int, b int, c int, d int, region text)
DISTRIBUTED BY (id)
PARTITION BY RANGE (year)
SUBPARTITION BY RANGE (a)
SUBPARTITION TEMPLATE (
START (1) END (2) EVERY (1),
DEFAULT SUBPARTITION other_a )
SUBPARTITION BY RANGE (b)
SUBPARTITION TEMPLATE (
START (1) END (2) EVERY (1),
DEFAULT SUBPARTITION other_b )
( START (2002) END (2003) EVERY (1),
DEFAULT PARTITION outlying_years );
CREATE TABLE ptable (c1 text, c2 float);
CREATE TABLE ctable (c3 char(2)) INHERITS (ptable);
CREATE TABLE cctable (c4 char(2)) INHERITS (ctable);
INSERT INTO minirepro_partition_test VALUES (1, (select gp_dump_query_oids('SELECT * FROM foo') ) :: json);
INSERT INTO minirepro_partition_test VALUES (2, (select gp_dump_query_oids('SELECT * FROM ptable') ) :: json);
INSERT INTO minirepro_partition_test VALUES (3, (select gp_dump_query_oids('SELECT * FROM pg_class') ) :: json);
SELECT array['foo'::regclass::oid::text,
'foo_1_prt_outlying_years'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_other_a_3_prt_2'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_outlying_years_2_prt_2_3_prt_2'::regclass::oid::text,
'foo_1_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_2_2_prt_other_a_3_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_2'::regclass::oid::text,
'foo_1_prt_2_2_prt_2_3_prt_other_b'::regclass::oid::text,
'foo_1_prt_2_2_prt_2_3_prt_2'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 1),','));
SELECT array['ptable'::regclass::oid::text,
'ctable'::regclass::oid::text,
'cctable'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 2),','));
SELECT array['pg_class'::regclass::oid::text] <@ (string_to_array((SELECT info->>'relids' FROM minirepro_partition_test WHERE id = 3),','));
DROP TABLE foo;
DROP TABLE cctable;
DROP TABLE ctable;
DROP TABLE ptable;
DROP TABLE minirepro_partition_test;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册