You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2025/01/02 03:12:08 UTC
(cloudberry) branch main updated (47fe6d9aa5 -> 4bd2d57baa)
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
from 47fe6d9aa5 Clean some typos about IVM (#825)
new b0b1c36713 Dump number of segments during minirepro and gpsd (#14225)
new 32221f4499 Forward complete QE notice messages (#11563)
new c66c184aca Fix incorrect sortOp and eqOp generated by IsCorrelatedEqualityOpExpr. (#14108)
new f2245856fd Fix dependency bug with minirepro and materialized views (#14223)
new 765c9ed7eb Fix: Ensure Smgr Relation is Opened Before Accessing AO Segment Files
new f819916fea pg_upgrade: Resolve FIXME for spclocation column
new b1a6c602cf pg_upgrade: Resolve test FIXME
new e45481b276 Removed unnecessary variable assignment.
new bb5d05287f fix crash on get_ao_compression_ratio of heap table (#14205)
new a2d8a0ec6b Tests of VACUUM (SKIP_LOCKED) (#14265)
new 8e3de84113 Bring back cdbsubselect_drop_distinct from 5X branch. (#14258)
new cd258f3392 Remove fixme in qp_correlated_query. (#14314)
new 173864a37c Change FIXME to note in join_hash case.
new 60eb05436a Support ONLY keyword for GRANT/REVOKE
new ff57b4890e Remove FIXME in bfv_olap_optimizer.out. (#14319)
new 495309595a Rename UpdateSerializableCommandId() to UpdateCommandIdInSnapshot()
new 5330213a81 Add tests for ALTER TABLE ONLY ... SET TABLESPACE
new 19f2e32575 Fix gpload regress case failure when OS user is not gpadmin (#14301)
new ede16fd9b9 Bring back cdbsubselect_drop_distinct. (#14322)
new 0e4928cd83 gp_replica_check: cosmetic changes to output
new e6e665ea07 gp_replica_check: resolve FIXMEs
new a1353bb7a8 make headerfile accessible to pxf extension (#14046)
new ca2123f6b9 Fix typo. (#14290)
new 33e08725fb fix gp_gettmid to return correct startup timestamp. (#14204)
new 4be1bf50ea Remove unnecessary code that dealt with locus of UNION plans. (#10879)
new 2f4bafda0d fix upgrading external tables with dropped cols
new ed1d76f4fa ao/co: Refactor DML states
new 74c48c597d ao/co: Remove FIXME for DML state mechanism
new 2c3ad98952 ao/co: Move unique index DML tests to new group
new 680a0197b3 Fix makefile to remove tablespace-step target all
new 0f9ea5e85f Refactor to extract SET_VAR to gp_bash_functions.sh
new e8c2b52cfb Workaround flaky test "dispatch" (#14429)
new fce2c29055 Fix range tables opening's locking issue inside ExecInitModifyTable(). (#14418)
new f770fbb757 Check with assert if AO table's toast table kept existing relfrozenxid unchanged. (#13499)
new 32be1d074e Fix gpcheckcat partition distribution policy check
new 276d6a855a Add numsegments check for gpcheckcat
new 2c238f6fc3 Make gpactivatestandby do retry loop after standby promote
new 142596d584 fix ic-proxy mis-disconnect addrs after reload config file (#14415)
new f2764ef4c6 ao/co: don't dereference dangling pointers (#14468)
new 96d06cafad Resolve a FIXME in merge_leaf_stats()
new 4bd2d57baa Fix test cases of cherry-pick.
The 41 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
contrib/interconnect/proxy/ic_proxy_addr.c | 5 +
gpMgmt/bin/gpactivatestandby | 30 +-
gpMgmt/bin/gpcheckcat | 73 ++++-
gpMgmt/bin/gpinitsystem | 23 --
.../bin/gpload_test/gpload2/TEST_local_config.py | 2 +-
gpMgmt/bin/gppylib/operations/startSegments.py | 2 +-
gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py | 2 +-
gpMgmt/bin/gppylib/system/configurationImplGpdb.py | 2 +-
gpMgmt/bin/gpsd | 19 +-
gpMgmt/bin/lib/gp_bash_functions.sh | 23 ++
gpMgmt/bin/lib/gpcreateseg.sh | 23 --
gpMgmt/bin/minirepro | 23 +-
gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature | 62 ++++
.../gpcheckcat/create_multilevel_partition.sql | 14 +
gpcontrib/gp_exttable_fdw/Makefile | 2 +
gpcontrib/gp_replica_check/Makefile | 7 +-
gpcontrib/gp_replica_check/gp_replica_check.c | 58 ++--
gpcontrib/gp_replica_check/gp_replica_check.py | 19 +-
src/backend/access/aocs/aocs_compaction.c | 2 -
src/backend/access/aocs/aocsam.c | 2 +
src/backend/access/aocs/aocsam_handler.c | 147 +++++-----
src/backend/access/appendonly/aosegfiles.c | 14 +-
.../access/appendonly/appendonlyam_handler.c | 148 +++++-----
src/backend/catalog/aclchk.c | 6 +-
src/backend/cdb/cdbsubselect.c | 78 ++++-
src/backend/cdb/dispatcher/cdbconn.c | 30 +-
src/backend/commands/analyze.c | 14 +-
src/backend/commands/cluster.c | 32 +-
src/backend/executor/instrument.c | 24 +-
src/backend/executor/nodeModifyTable.c | 13 +-
src/backend/{commands => executor}/test/Makefile | 8 +-
src/backend/executor/test/instrument_test.c | 64 ++++
src/backend/optimizer/plan/subselect.c | 14 +
src/backend/optimizer/prep/prepunion.c | 24 +-
src/backend/parser/gram.y | 27 +-
src/backend/rewrite/rewriteHandler.c | 6 +-
src/backend/storage/ipc/procarray.c | 3 +-
src/backend/utils/adt/gp_dump_oids.c | 11 +-
src/backend/utils/time/snapmgr.c | 6 +-
src/bin/pg_dump/pg_dump.c | 15 +-
src/bin/pg_upgrade/info.c | 1 -
src/bin/pg_upgrade/test_gpdb_pre.sql | 10 -
src/include/cdb/cdbsubselect.h | 3 +
src/include/nodes/parsenodes.h | 2 +
src/include/storage/procarray.h | 2 +-
src/include/utils/rel.h | 3 +-
src/test/isolation/expected/vacuum-skip-locked.out | 148 ++++++++++
src/test/isolation/specs/vacuum-skip-locked.spec | 66 ++++-
src/test/isolation2/expected/lockmodes.out | 61 ++++
.../isolation2/expected/lockmodes_optimizer.out | 61 ++++
.../expected/vacuum_skip_locked_onseg.out | 53 ++++
src/test/isolation2/isolation2_schedule | 1 +
src/test/isolation2/sql/lockmodes.sql | 28 ++
.../isolation2/sql/vacuum_skip_locked_onseg.sql | 41 +++
src/test/regress/GNUmakefile | 8 +-
src/test/regress/expected/AORO_Compression.out | 12 +
src/test/regress/expected/bfv_olap_optimizer.out | 3 -
src/test/regress/expected/bfv_partition.out | 1 +
src/test/regress/expected/delete.out | 8 +
src/test/regress/expected/gp_dump_query_oids.out | 17 ++
src/test/regress/expected/join_hash.out | 5 +-
src/test/regress/expected/join_hash_optimizer.out | 5 +-
src/test/regress/expected/minirepro.out | 12 +-
src/test/regress/expected/notin.out | 34 +--
src/test/regress/expected/notin_optimizer.out | 34 +--
src/test/regress/expected/partition.out | 89 ++++++
src/test/regress/expected/partition_optimizer.out | 89 ++++++
.../regress/expected/pg_dump_binary_upgrade.out | 18 ++
.../expected/qp_correlated_query_optimizer.out | 3 -
src/test/regress/expected/rpt.out | 114 +++-----
src/test/regress/expected/subselect.out | 10 +-
src/test/regress/expected/subselect_gp.out | 292 ++++++++++++++++++-
.../regress/expected/subselect_gp_optimizer.out | 322 +++++++++++++++++++--
src/test/regress/expected/subselect_optimizer.out | 8 +-
src/test/regress/expected/with_clause.out | 28 +-
src/test/regress/greenplum_schedule | 7 +-
src/test/regress/input/tablespace.source | 19 ++
src/test/regress/output/tablespace.source | 25 ++
src/test/regress/sql/AORO_Compression.sql | 11 +
src/test/regress/sql/bfv_partition.sql | 1 +
src/test/regress/sql/delete.sql | 7 +
src/test/regress/sql/gp_dump_query_oids.sql | 9 +
src/test/regress/sql/join_hash.sql | 6 +-
src/test/regress/sql/partition.sql | 32 ++
src/test/regress/sql/pg_dump_binary_upgrade.sql | 20 ++
src/test/regress/sql/subselect_gp.sql | 108 +++++++
src/test/singlenode_regress/expected/subselect.out | 7 +-
.../singlenode_regress/expected/subselect_gp.out | 16 +-
88 files changed, 2347 insertions(+), 590 deletions(-)
create mode 100644 gpMgmt/test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql
copy src/backend/{commands => executor}/test/Makefile (62%)
create mode 100644 src/backend/executor/test/instrument_test.c
create mode 100644 src/test/isolation2/expected/vacuum_skip_locked_onseg.out
create mode 100644 src/test/isolation2/sql/vacuum_skip_locked_onseg.sql
create mode 100644 src/test/regress/expected/pg_dump_binary_upgrade.out
create mode 100644 src/test/regress/sql/pg_dump_binary_upgrade.sql
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 14/41: Support ONLY keyword for GRANT/REVOKE
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 60eb05436a23474ea3afbbebe211587f0c77ec4e
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Wed Oct 19 13:08:15 2022 -0700
Support ONLY keyword for GRANT/REVOKE
Historically in GPDB6, when executing GRANT/REVOKE on a partition
root, we will recurse into its child tables. We have decided to
keep this behavior for 7X, but to also support the ONLY keyword
so that users can choose to grant/revoke just the partition root,
without recursion. The syntax is e.g.:
GRANT SELECT ON ONLY foo_par TO role;
Discussion: https://groups.google.com/a/greenplum.org/g/gpdb-dev/c/ImJrvQEECwA
---
src/backend/catalog/aclchk.c | 6 +-
src/backend/parser/gram.y | 27 ++++++-
src/test/regress/expected/partition.out | 89 +++++++++++++++++++++++
src/test/regress/expected/partition_optimizer.out | 89 +++++++++++++++++++++++
src/test/regress/sql/partition.sql | 32 ++++++++
5 files changed, 238 insertions(+), 5 deletions(-)
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index d6a496aaf8..ccb5eeba9a 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -740,9 +740,11 @@ objectNamesToOids(ObjectType objtype, List *objnames)
* GPDB: If we the object is a partitioned relation, also
* recurse to the child partitions. It is different from
* PostgreSQL, but it is how GRANT has historically worked on
- * GPDB.
+ * GPDB. Unless it is indicated that we should not recurse
+ * (e.g. by specifying the 'ONLY' keyword), in which case
+ * don't bother finding the inheritors.
*/
- if (objtype == OBJECT_TABLE)
+ if (objtype == OBJECT_TABLE && relvar->inh)
{
HeapTuple tp;
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 06540bd216..c93b839acd 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -463,7 +463,7 @@ static void check_expressions_in_partition_key(PartitionSpec *spec, core_yyscan_
sort_clause opt_sort_clause sortby_list index_params stats_params
opt_include opt_c_include index_including_params
name_list role_list from_clause from_list opt_array_bounds
- qualified_name_list any_name any_name_list type_name_list
+ qualified_name_list qualified_name_list_with_only any_name any_name_list type_name_list
any_operator expr_list attrs
distinct_clause opt_distinct_clause
target_list opt_target_list insert_column_list set_target_list
@@ -10474,7 +10474,7 @@ privilege: SELECT opt_column_list
* opt_table. You're going to get conflicts.
*/
privilege_target:
- qualified_name_list
+ qualified_name_list_with_only
{
PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
n->targtype = ACL_TARGET_OBJECT;
@@ -10482,7 +10482,7 @@ privilege_target:
n->objs = $1;
$$ = n;
}
- | TABLE qualified_name_list
+ | TABLE qualified_name_list_with_only
{
PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
n->targtype = ACL_TARGET_OBJECT;
@@ -19062,6 +19062,27 @@ qualified_name_list:
| qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
;
+qualified_name_list_with_only:
+ qualified_name
+ {
+ $$ = list_make1($1);
+ }
+ | ONLY qualified_name
+ {
+ $2->inh = false;
+ $$ = list_make1($2);
+ }
+ | qualified_name_list ',' qualified_name
+ {
+ $$ = lappend($1, $3);
+ }
+ | qualified_name_list ',' ONLY qualified_name
+ {
+ $4->inh = false;
+ $$ = lappend($1, $4);
+ }
+ ;
+
/*
* The production for a qualified relation name has to exactly match the
* production for a qualified func_name, because in a FROM clause we cannot
diff --git a/src/test/regress/expected/partition.out b/src/test/regress/expected/partition.out
index 895897a4c7..207450c719 100755
--- a/src/test/regress/expected/partition.out
+++ b/src/test/regress/expected/partition.out
@@ -283,9 +283,98 @@ select has_table_privilege('part_role', 'bar_p'::regclass, 'select');
t
(1 row)
+-- the ONLY keyword will affect just the partition root for both grant/revoke
+create role part_role2;
+grant select on only foo_p to part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+grant select on foo_p to part_role2;
+revoke select on only foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+revoke select on foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+create table foo_p2 (a int, b int) partition by range(a) (start(1) end(10) every(1));
+grant select on foo_p, only foo_p2 to part_role2; -- multiple tables in same statement
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p2'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p2_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+-- more cases
+revoke all on foo_p from part_role2;
+revoke all on foo_p2 from part_role2;
+grant select on only public.foo_p to part_role2; -- with schema
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+grant update(b) on only foo_p2 to part_role2; -- column level priviledge
+select relname, has_column_privilege('part_role2', oid, 'b', 'update') from pg_class
+where relname = 'foo_p2' or relname = 'foo_p2_1_prt_6';
+ relname | has_column_privilege
+----------------+----------------------
+ foo_p2 | t
+ foo_p2_1_prt_6 | f
+(2 rows)
+
drop table foo_p;
+drop table foo_p2;
drop table bar_p;
drop role part_role;
+drop role part_role2;
-- validation
create table foo_p (i int) partition by range(i)
(start(1) end(10) every(1));
diff --git a/src/test/regress/expected/partition_optimizer.out b/src/test/regress/expected/partition_optimizer.out
index 805ea62439..ef4861238b 100755
--- a/src/test/regress/expected/partition_optimizer.out
+++ b/src/test/regress/expected/partition_optimizer.out
@@ -283,9 +283,98 @@ select has_table_privilege('part_role', 'bar_p'::regclass, 'select');
t
(1 row)
+-- the ONLY keyword will affect just the partition root for both grant/revoke
+create role part_role2;
+grant select on only foo_p to part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+grant select on foo_p to part_role2;
+revoke select on only foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+revoke select on foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+create table foo_p2 (a int, b int) partition by range(a) (start(1) end(10) every(1));
+grant select on foo_p, only foo_p2 to part_role2; -- multiple tables in same statement
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p2'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p2_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+-- more cases
+revoke all on foo_p from part_role2;
+revoke all on foo_p2 from part_role2;
+grant select on only public.foo_p to part_role2; -- with schema
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+ has_table_privilege
+---------------------
+ t
+(1 row)
+
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+ has_table_privilege
+---------------------
+ f
+(1 row)
+
+grant update(b) on only foo_p2 to part_role2; -- column level priviledge
+select relname, has_column_privilege('part_role2', oid, 'b', 'update') from pg_class
+where relname = 'foo_p2' or relname = 'foo_p2_1_prt_6';
+ relname | has_column_privilege
+----------------+----------------------
+ foo_p2 | t
+ foo_p2_1_prt_6 | f
+(2 rows)
+
drop table foo_p;
+drop table foo_p2;
drop table bar_p;
drop role part_role;
+drop role part_role2;
-- validation
create table foo_p (i int) partition by range(i)
(start(1) end(10) every(1));
diff --git a/src/test/regress/sql/partition.sql b/src/test/regress/sql/partition.sql
index cebff356e2..90dccbe00d 100644
--- a/src/test/regress/sql/partition.sql
+++ b/src/test/regress/sql/partition.sql
@@ -209,9 +209,41 @@ alter table foo_p exchange partition for(6) with table bar_p;
select has_table_privilege('part_role', 'foo_p_1_prt_6'::regclass, 'select');
select has_table_privilege('part_role', 'bar_p'::regclass, 'select');
+-- the ONLY keyword will affect just the partition root for both grant/revoke
+create role part_role2;
+grant select on only foo_p to part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+
+grant select on foo_p to part_role2;
+revoke select on only foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+revoke select on foo_p from part_role2;
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+
+create table foo_p2 (a int, b int) partition by range(a) (start(1) end(10) every(1));
+grant select on foo_p, only foo_p2 to part_role2; -- multiple tables in same statement
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p2'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p2_1_prt_6'::regclass, 'select');
+
+-- more cases
+revoke all on foo_p from part_role2;
+revoke all on foo_p2 from part_role2;
+grant select on only public.foo_p to part_role2; -- with schema
+select has_table_privilege('part_role2', 'foo_p'::regclass, 'select');
+select has_table_privilege('part_role2', 'foo_p_1_prt_6'::regclass, 'select');
+grant update(b) on only foo_p2 to part_role2; -- column level priviledge
+select relname, has_column_privilege('part_role2', oid, 'b', 'update') from pg_class
+where relname = 'foo_p2' or relname = 'foo_p2_1_prt_6';
+
drop table foo_p;
+drop table foo_p2;
drop table bar_p;
drop role part_role;
+drop role part_role2;
-- validation
create table foo_p (i int) partition by range(i)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 01/41: Dump number of segments during minirepro and gpsd (#14225)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit b0b1c36713845d82c1c3ad1e84d9595d3a66640b
Author: Chris Hajas <ch...@vmware.com>
AuthorDate: Thu Oct 6 10:54:00 2022 -0700
Dump number of segments during minirepro and gpsd (#14225)
This commit includes a couple improvements when dumping minirepros and gpsd:
1. Dump the number of segments. This is needed to replicate the plan,
and often we have to ask users/customers this separately. Instead just
retrieve it during the minirepro
2. Output a `set optimizer=off` for when the minirepro is being
restored. The short insert statements are much faster (~10X) using
planner than Orca, especially if done in debug buiild. Output this by
default so I don't have to modify this manually.
---
gpMgmt/bin/gpsd | 19 ++++++++++++++++++-
gpMgmt/bin/minirepro | 23 +++++++++++++++++++----
src/test/regress/expected/minirepro.out | 12 ++++++++----
3 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/gpMgmt/bin/gpsd b/gpMgmt/bin/gpsd
index ad61a1e3de..fe877a38de 100755
--- a/gpMgmt/bin/gpsd
+++ b/gpMgmt/bin/gpsd
@@ -35,10 +35,19 @@ def ResultIter(cursor, arraysize=1000):
def getVersion(envOpts):
cmd = subprocess.Popen('psql --pset footer -Atqc "select version()" template1', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=envOpts)
if cmd.wait() != 0:
- sys.stderr.write('\nError while trying to find HAWQ/GPDB version.\n\n' + cmd.communicate()[1].decode('ascii') + '\n\n')
+ sys.stderr.write('\nError while trying to find GPDB version.\n\n' + cmd.communicate()[1].decode('ascii') + '\n\n')
sys.exit(1)
return cmd.communicate()[0].decode('ascii')
+def get_num_segments(cursor):
+ query = "select count(*) from gp_segment_configuration where role='p' and content >=0;"
+ try:
+ cursor.execute(query)
+ except pgdb.DatabaseError as e:
+ sys.stderr.write('\nError while trying to retrieve number of segments.\n\n' + str(e) + '\n\n')
+ sys.exit(1)
+ vals = cursor.fetchone()
+ return vals[0]
def dumpSchema(connectionInfo, envOpts):
dump_cmd = 'pg_dump -h {host} -p {port} -U {user} -s -x -O {database}'.format(**connectionInfo)
@@ -133,6 +142,7 @@ def main():
version = getVersion(envOpts)
+
timestamp = datetime.datetime.today()
connectionInfo = {
@@ -142,9 +152,14 @@ def main():
'database': db,
'options': pgoptions
}
+ num_segments = 0
+ with closing(pgdb.connect(**connectionInfo)) as connection:
+ with closing(connection.cursor()) as cursor:
+ num_segments = get_num_segments(cursor)
sys.stdout.writelines(['\n-- Greenplum database Statistics Dump',
'\n-- Copyright (C) 2007 - 2014 Pivotal'
'\n-- Database: ' + db,
+ '\n-- Num Segments: ' + str(num_segments),
'\n-- Date: ' + timestamp.date().isoformat(),
'\n-- Time: ' + timestamp.time().isoformat(),
'\n-- CmdLine: ' + ' '.join(sys.argv),
@@ -168,6 +183,8 @@ def main():
'\n-- Allow system table modifications',
'\n-- ',
'\nset allow_system_table_mods=true;\n\n'])
+ # turn off optimizer when loading stats. Orca adds a bit of overhead, but it's significant when small insrt queries take 1 vs .1ms
+ sys.stdout.writelines('set optimizer to off;\n\n')
sys.stdout.flush()
try:
diff --git a/gpMgmt/bin/minirepro b/gpMgmt/bin/minirepro
index 5342dcf175..cf3c28115e 100755
--- a/gpMgmt/bin/minirepro
+++ b/gpMgmt/bin/minirepro
@@ -97,11 +97,21 @@ def get_server_version(cursor):
query = "select version()"
try:
cursor.execute(query)
- vals = cursor.fetchone()
- return vals[0]
except pgdb.DatabaseError as e:
- sys.stderr.write('\nError while trying to find HAWQ/GPDB version.\n\n' + str(e) + '\n\n')
+ sys.stderr.write('\nError while trying to find GPDB version.\n\n' + str(e) + '\n\n')
sys.exit(1)
+ vals = cursor.fetchone()
+ return vals[0]
+
+def get_num_segments(cursor):
+ query = "select count(*) from gp_segment_configuration where role='p' and content >=0;"
+ try:
+ cursor.execute(query)
+ except pgdb.DatabaseError as e:
+ sys.stderr.write('\nError while trying to retrieve number of segments.\n\n' + str(e) + '\n\n')
+ sys.exit(1)
+ vals = cursor.fetchone()
+ return vals[0]
def parse_cmd_line():
p = OptionParser(usage='Usage: %prog <database> [options]', version='%prog '+version, conflict_handler="resolve", epilog="WARNING: This tool collects statistics about your data, including most common values, which requires some data elements to be included in the output file. Please review output file to ensure it is within corporate policy to transport the output file.")
@@ -295,6 +305,8 @@ def main():
# get server version, which is dumped to minirepro output file
server_ver = get_server_version(cursor)
+ num_segments = get_num_segments(cursor)
+
"""
invoke gp_toolkit UDF, dump object oids as json text
input: query file name
@@ -329,6 +341,8 @@ def main():
# make sure we connect with the right database
f_out.writelines('\\connect ' + db + '\n\n')
+ # turn off optimizer when loading stats. Orca adds a bit of overhead, but it's significant when small insrt queries take 1 vs .1ms
+ f_out.writelines('set optimizer to off;\n\n')
# first create schema DDLs
print("Writing schema DDLs ...")
@@ -362,7 +376,8 @@ def main():
f_out.writelines(['\n-- ',
'\n-- Query text',
'\n-- \n\n'])
-
+ line = 'set optimizer_segments = ' + str(num_segments) + ';'
+ f_out.writelines('\n-- ' + line + '\n')
with open(query_file, 'r') as query_f:
for line in query_f:
f_out.writelines('-- ' + line)
diff --git a/src/test/regress/expected/minirepro.out b/src/test/regress/expected/minirepro.out
index 79d67481f9..0b4a8e5a06 100644
--- a/src/test/regress/expected/minirepro.out
+++ b/src/test/regress/expected/minirepro.out
@@ -64,6 +64,7 @@ SET
SET
SET
SET
+SET
SET
set_config
------------
@@ -146,6 +147,7 @@ SET
SET
SET
SET
+SET
SET
set_config
------------
@@ -230,6 +232,7 @@ SET
SET
SET
SET
+SET
SET
set_config
------------
@@ -271,6 +274,7 @@ SET
SET
SET
SET
+SET
SET
set_config
------------
@@ -283,10 +287,10 @@ SET
SET
SET
SET
-psql:data/minirepro.sql:46: ERROR: only shared relations can be placed in pg_global tablespace
-psql:data/minirepro.sql:48: ERROR: permission denied: "pg_tablespace" is a system catalog
-psql:data/minirepro.sql:56: ERROR: permission denied: "pg_tablespace" is a system catalog
-psql:data/minirepro.sql:64: ERROR: permission denied: "pg_tablespace" is a system catalog
+psql:data/minirepro.sql:48: ERROR: only shared relations can be placed in pg_global tablespace
+psql:data/minirepro.sql:50: ERROR: permission denied: "pg_tablespace" is a system catalog
+psql:data/minirepro.sql:58: ERROR: permission denied: "pg_tablespace" is a system catalog
+psql:data/minirepro.sql:66: ERROR: permission denied: "pg_tablespace" is a system catalog
SET
UPDATE 1
DELETE 1
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 02/41: Forward complete QE notice messages (#11563)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 32221f4499a32504e6b356a8fe05f0269fc812db
Author: dh-cloud <60...@users.noreply.github.com>
AuthorDate: Mon Oct 10 10:24:53 2022 +0800
Forward complete QE notice messages (#11563)
The QE notice message might be truncated because MPPnoticeReceiver()
limited message length about 800 bytes sent to the client. The client
should not see an incomplete notice message.
This commit changes its behaviour, it allows QE messages of any length
(include QE identifier) to send to the client.
---
src/backend/cdb/dispatcher/cdbconn.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/backend/cdb/dispatcher/cdbconn.c b/src/backend/cdb/dispatcher/cdbconn.c
index 1e06bff4c5..ead6301ab5 100644
--- a/src/backend/cdb/dispatcher/cdbconn.c
+++ b/src/backend/cdb/dispatcher/cdbconn.c
@@ -526,6 +526,7 @@ struct QENotice
char line[10];
char *func;
char *message;
+ char *whoami;
char *detail;
char *hint;
char *context;
@@ -558,11 +559,11 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
char *file = "";
char *line = NULL;
char *func = "";
- char message[1024];
+ char *message= "missing error text";
char *detail = NULL;
char *hint = NULL;
char *context = NULL;
-
+ char whoami[200] = { 0 };
SegmentDatabaseDescriptor *segdbDesc = (SegmentDatabaseDescriptor *) arg;
/*
@@ -572,7 +573,8 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
if (!res || MyProcPort == NULL)
return;
- strcpy(message, "missing error text");
+ if (segdbDesc && segdbDesc->whoami)
+ snprintf(whoami, sizeof(whoami), " (%s)", segdbDesc->whoami);
for (pfield = res->errFields; pfield != NULL; pfield = pfield->next)
{
@@ -602,14 +604,7 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
sqlstate = pfield->contents;
break;
case PG_DIAG_MESSAGE_PRIMARY:
- strncpy(message, pfield->contents, 800);
- message[800] = '\0';
- if (segdbDesc && segdbDesc->whoami && strlen(segdbDesc->whoami) < 200)
- {
- strcat(message, " (");
- strcat(message, segdbDesc->whoami);
- strcat(message, ")");
- }
+ message = pfield->contents;
break;
case PG_DIAG_MESSAGE_DETAIL:
detail = pfield->contents;
@@ -652,10 +647,11 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
char *bufptr;
int file_len;
int func_len;
- int message_len;
int detail_len;
int hint_len;
int context_len;
+ int message_len;
+ int whoami_len;
/*
* We use malloc(), because we are in a libpq callback, and we CANNOT
@@ -680,10 +676,11 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
size = offsetof(QENotice, buf);
SIZE_VARLEN_FIELD(file);
SIZE_VARLEN_FIELD(func);
- SIZE_VARLEN_FIELD(message);
SIZE_VARLEN_FIELD(detail);
SIZE_VARLEN_FIELD(hint);
SIZE_VARLEN_FIELD(context);
+ SIZE_VARLEN_FIELD(message);
+ SIZE_VARLEN_FIELD(whoami);
/*
* Perform the allocation. Put a limit on the max size, as a sanity
@@ -721,12 +718,15 @@ MPPnoticeReceiver(void *arg, const PGresult *res)
COPY_VARLEN_FIELD(file);
strlcpy(notice->line, line, sizeof(notice->line));
COPY_VARLEN_FIELD(func);
- COPY_VARLEN_FIELD(message);
COPY_VARLEN_FIELD(detail);
COPY_VARLEN_FIELD(hint);
COPY_VARLEN_FIELD(context);
+ /* Concatenate message and whoami string together */
+ COPY_VARLEN_FIELD(message);
+ bufptr--; /* lets whoami overwrite '\0' byte of message body */
+ COPY_VARLEN_FIELD(whoami);
- Assert(bufptr - (char *) notice == size);
+ Assert(bufptr - (char *) notice == (size - 1));
/* Link it to the queue */
notice->next = NULL;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 07/41: pg_upgrade: Resolve test FIXME
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit b1a6c602cf442da95fc8222e0ada5d811fd6464b
Author: Brent Doil <bd...@vmware.com>
AuthorDate: Thu Sep 8 15:59:24 2022 -0400
pg_upgrade: Resolve test FIXME
We don't drop partitioned tables with indexes for the pg_upgrade regression test on GPDB7.
Remove the commented out commands and FIXME.
Authored-by: Brent Doil <bd...@vmware.com>
---
src/bin/pg_upgrade/test_gpdb_pre.sql | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/src/bin/pg_upgrade/test_gpdb_pre.sql b/src/bin/pg_upgrade/test_gpdb_pre.sql
index c08102acc4..9327c97746 100644
--- a/src/bin/pg_upgrade/test_gpdb_pre.sql
+++ b/src/bin/pg_upgrade/test_gpdb_pre.sql
@@ -3,16 +3,6 @@
-- exist at the time of running upgrades. If objects are to be manipulated
-- in other databases, make sure to change to the correct database first.
--- GPDB_12_MERGE_FIXME: We don't need to drop partitioned table with indexes
--- anymore, do we?
---partition tables with indexes requires dropping for now
---NOTE: 'isolation2test' and 'regression' database must already exist
---\c isolation2test;
---\i test_gpdb_pre_drop_partition_indices.sql;
-
---\c regression;
---\i test_gpdb_pre_drop_partition_indices.sql;
-
-- The isolation tests are run in utility mode, and the objects left behind
-- are not consistent between the QD and QEs.
DROP DATABASE IF EXISTS isolation_regression;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 37/41: Make gpactivatestandby do retry loop after standby promote
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 2c238f6fc37c96acdb1e8e40bc7d4f426c4ab0fe
Author: Jimmy Yih <jy...@vmware.com>
AuthorDate: Thu Sep 22 16:53:58 2022 -0700
Make gpactivatestandby do retry loop after standby promote
The pg_ctl promote wait logic checks for IN_PRODUCTION state in the
promoted coordinator's control file to determine if the standby
coordinator has successfully been promoted or not. Unfortunately, that
IN_PRODUCTION state does not guarantee that the promoted coordinator
is ready to accept database connections yet. Make gpactivatestandby do
a retry loop on its forced CHECKPOINT logic to guarantee that the
CHECKPOINT goes through and immediately reflects the new timeline
id. With this patch, intermittent gpactivatestandby Behave test
flakes seen frequently in the Concourse pipeline are resolved.
The logic in this patch is also actually somewhat of a revert to
previous logic as we used to do the very same retry loop. The retry
loop was removed because we wrongly assumed pg_ctl promote wait logic
would wait until database connections were ready to be accepted. The
try/catch would actually catch the error but it was being ignored
(which was intentional from the previous retry logic but wrong in the
non-retry logic).
GPDB commit references:
https://github.com/greenplum-db/gpdb/commit/1fe901d4bb9b141fd6931977eb93515982ac6edd
https://github.com/greenplum-db/gpdb/commit/5868160a73ba9cfcebdb61820635301bfb8cc0c1
---
gpMgmt/bin/gpactivatestandby | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/gpMgmt/bin/gpactivatestandby b/gpMgmt/bin/gpactivatestandby
index 4aa5e8a97d..ee180022e6 100755
--- a/gpMgmt/bin/gpactivatestandby
+++ b/gpMgmt/bin/gpactivatestandby
@@ -327,15 +327,25 @@ def promote_standby(coordinator_data_dir):
# written to the pg_control file. This happens in async way in
# server since pg_ctl promote uses fast_promote. Given gpstart
# depends on TLI to be reflect after right after promotion mainly
- # for testing we force CHECKPOINT here.
+ # for testing we force CHECKPOINT here. We loop here since the
+ # pg_ctl promote wait logic simply checks for IN_PRODUCTION in the
+ # promoted coordinator's control file but the coordinator's
+ # postmaster will actually not be ready yet to accept database
+ # connections for a small period of time. Use the same
+ # MIRROR_PROMOTION_TIMEOUT of 10 minutes here as well.
logger.debug('forcing CHECKPOINT to reflect new TimeLineID...')
- try:
- dburl = dbconn.DbURL()
- conn = dbconn.connect(dburl, utility=True, logConn=False)
- dbconn.execSQL(conn, 'CHECKPOINT')
- conn.close()
- except pygresql.InternalError as e:
- pass
+ for i in range(600):
+ try:
+ dburl = dbconn.DbURL()
+ conn = dbconn.connect(dburl, utility=True, logConn=False)
+ dbconn.execSQL(conn, 'CHECKPOINT')
+ conn.close()
+ return True
+ except pygresql.InternalError as e:
+ pass
+ time.sleep(1)
+
+ return False
#-------------------------------------------------------------------------
# Main
@@ -367,7 +377,9 @@ try:
# promote standby, only if the standby is running in recovery
if not requires_restart:
- promote_standby(options_.coordinator_data_dir)
+ res = promote_standby(options_.coordinator_data_dir)
+ if not res:
+ raise GpActivateStandbyException('Timed out waiting for promoted coordinator to accept database connections.')
# now we can access the catalog. promote action has already updated
# catalog, so array.coordinator is the old (promoted) standby at this point.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 20/41: gp_replica_check: cosmetic changes to output
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 0e4928cd83eed173f80a1840f7347e14d5eb62e4
Author: Ashwin Agrawal <aa...@vmware.com>
AuthorDate: Tue Oct 25 15:47:42 2022 -0700
gp_replica_check: cosmetic changes to output
Added code to print thread id for passed or failed status to easily
correlate the message result with the data directory. Some minor
formatting along the way.
---
gpcontrib/gp_replica_check/gp_replica_check.py | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/gpcontrib/gp_replica_check/gp_replica_check.py b/gpcontrib/gp_replica_check/gp_replica_check.py
index 0e92d9b320..5d4a3b41e8 100755
--- a/gpcontrib/gp_replica_check/gp_replica_check.py
+++ b/gpcontrib/gp_replica_check/gp_replica_check.py
@@ -54,9 +54,9 @@ class ReplicaCheck(threading.Thread):
self.lock = threading.Lock()
def __str__(self):
- return '(%s) Host: %s, Port: %s, Database: %s\n\
-Primary Data Directory Location: %s\n\
-Mirror Data Directory Location: %s' % (self.getName(), self.host, self.port, self.datname,
+ return '\n(%s) ---------\nHost: %s, Port: %s, Database: %s\n\
+Primary Location: %s\n\
+Mirror Location: %s' % (self.getName(), self.host, self.port, self.datname,
self.ploc, self.mloc)
def wait_for_wal_sync(self):
@@ -102,7 +102,7 @@ Mirror Data Directory Location: %s' % (self.getName(), self.host, self.port, sel
def run(self):
- self.wait_for_wal_sync();
+ self.wait_for_wal_sync()
cmd = '''PGOPTIONS='-c gp_role=utility' psql -h %s -p %s -c "select * from gp_replica_check('%s', '%s', '%s')" %s''' % (self.host, self.port,
self.ploc, self.mloc,
self.relation_types,
@@ -115,11 +115,12 @@ Mirror Data Directory Location: %s' % (self.getName(), self.host, self.port, sel
self.result = True if res.strip().split('\n')[-2].strip() == 't' else False
with self.lock:
print(self)
- print (res)
- if not self.result:
- print("replica check failed")
-
- except subprocess.CalledProcessError as e:
+ if self.result:
+ print("(%s) ** passed **" % (self.getName()))
+ else:
+ print("(%s) --> failed <--" % (self.getName()))
+ print (res)
+ except:
with self.lock:
print(self)
print('returncode: (%s), cmd: (%s), output: (%s)' % (e.returncode, e.cmd, e.output))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 18/41: Fix gpload regress case failure when OS user is not gpadmin (#14301)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 19f2e32575c5cd38128e99417a9f77f1a6542232
Author: dreamedcheng <dr...@gmail.com>
AuthorDate: Mon Oct 24 11:30:40 2022 +0800
Fix gpload regress case failure when OS user is not gpadmin (#14301)
Gpload regression case #50 would fail,
if OS user that installed gpdb cluster is not gpadmin.
Since it specified a hardcode user gpadmin,
we need to use PGUSER instead to fix it.
Co-authored-by: wuchengwen <wc...@alibaba-inc.com>
---
gpMgmt/bin/gpload_test/gpload2/TEST_local_config.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gpMgmt/bin/gpload_test/gpload2/TEST_local_config.py b/gpMgmt/bin/gpload_test/gpload2/TEST_local_config.py
index 01a48779f5..6c530c4ac8 100644
--- a/gpMgmt/bin/gpload_test/gpload2/TEST_local_config.py
+++ b/gpMgmt/bin/gpload_test/gpload2/TEST_local_config.py
@@ -38,7 +38,7 @@ def test_49_gpload_config_wrong_d():
copy_data('external_file_01.txt', 'data_file.txt')
write_config_file(database="", format='text',file='data_file.txt',table='texttable')
-@prepare_before_test(num=50, cmd="-U gpadmin")
+@prepare_before_test(num=50, cmd="-U "+str(PGUSER))
def test_50_gpload_config_U():
"50 gpload command config test -U username"
copy_data('external_file_01.txt', 'data_file.txt')
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 21/41: gp_replica_check: resolve FIXMEs
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit e6e665ea07ba84b6ee907cd6e31d3e00858c65ae
Author: Ashwin Agrawal <aa...@vmware.com>
AuthorDate: Tue Oct 25 15:47:48 2022 -0700
gp_replica_check: resolve FIXMEs
FIXMEs were related to adding support for checking dynamic access
methods. Given we are far away from supporting all built-in access
methods, dynamic support is not on the radar at all. Plus, having a
new access method is not a common act at all. So, we can cross the
bridge of converting RelationTypeData to a dynamic array instead of
the static array when we get there. Hence, for now, resolving the
FIXME by manually updating the static array to reflect all the current
access methods.
Note: with this change now "ao" gets split into ao_row and
ao_column. This is nice as can run more granular checking if desired.
Also, converted GPDB_94_MERGE_FIXME to GPDB_FEATURE_NOT_SUPPORTED in
Makefile. As we are yet to test/validate/enable this tool for various
index access methods - which we should do separately.
---
gpcontrib/gp_replica_check/Makefile | 7 ++--
gpcontrib/gp_replica_check/gp_replica_check.c | 58 ++++++++++++---------------
2 files changed, 29 insertions(+), 36 deletions(-)
diff --git a/gpcontrib/gp_replica_check/Makefile b/gpcontrib/gp_replica_check/Makefile
index db6fadcc99..4476b2db01 100644
--- a/gpcontrib/gp_replica_check/Makefile
+++ b/gpcontrib/gp_replica_check/Makefile
@@ -14,7 +14,8 @@ include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
-# GPDB_94_MERGE_FIXME: Enable btree, gin and gist when physical and logical
-# order is equivalent.
+# GPDB_FEATURE_NOT_SUPPORTED: Enable btree, gin and gist as physical
+# and logical order is equivalent now. Also, enable brin, spgist,
+# bitmap. Basically, "all" option should be functional for this tool.
installcheck: install
- gp_replica_check.py -r="heap, sequence, ao"
+ gp_replica_check.py -r="heap, ao_row, ao_column"
diff --git a/gpcontrib/gp_replica_check/gp_replica_check.c b/gpcontrib/gp_replica_check/gp_replica_check.c
index f3ecaece51..defef980a8 100644
--- a/gpcontrib/gp_replica_check/gp_replica_check.c
+++ b/gpcontrib/gp_replica_check/gp_replica_check.c
@@ -81,28 +81,28 @@ typedef struct RelationTypeData
bool include;
} RelationTypeData;
-#define MAX_INCLUDE_RELATION_TYPES 8
+#define MAX_INCLUDE_RELATION_TYPES 10
/*
- * GPDB_12_MERGE_FIXME: new access methods can be defined, which cannot be
- * checked using the current way by comparing predefined access method OIDs.
- * The AM handler functions need to be looked up and compared instead.
- * E.g. to tell if it's an appendoptimized row oriented table, look up the
- * handler function for that table's AM in pg_am_handler and compare it with
- * F_AO_ROW_TABLEAM_HANDLER.
+ * This is a static pre-defined array for now as currently, this tool works
+ * only for pre-defined access methods. As most likely will need masking
+ * functions to perform proper comparisons for newer access methods. Plus,
+ * having on the fly access methods is not at all common phenomenon. If and
+ * when in future new access method is added, can update this array or enhance
+ * the tool to dynamically create this array based on pg_am table.
*
- * If the tool is desired to be used against pre-defined access methods only,
- * then no change would be needed.
*/
static RelationTypeData relation_types[MAX_INCLUDE_RELATION_TYPES+1] = {
+ {"heap", false},
{"btree", false},
{"hash", false},
{"gist", false},
{"gin", false},
+ {"ao_row", false},
+ {"ao_column", false},
+ {"brin", false},
+ {"spgist", false},
{"bitmap", false},
- {"heap", false},
- {"sequence", false},
- {"ao", false},
{"unknown relam", false}
};
@@ -171,29 +171,28 @@ init_relation_types(char *include_relation_types)
static RelationTypeData
get_relation_type_data(Oid relam, int relkind)
{
- /* GPDB_12_MERGE_FIXME: Why doesn't this just look up the AM name from pg_am? */
switch(relam)
{
- case BTREE_AM_OID:
+ case HEAP_TABLE_AM_OID:
return relation_types[0];
- case HASH_AM_OID:
+ case BTREE_AM_OID:
return relation_types[1];
- case GIST_AM_OID:
+ case HASH_AM_OID:
return relation_types[2];
- case GIN_AM_OID:
+ case GIST_AM_OID:
return relation_types[3];
- case BITMAP_AM_OID:
+ case GIN_AM_OID:
return relation_types[4];
-
- case HEAP_TABLE_AM_OID:
- if (relkind == RELKIND_SEQUENCE)
- return relation_types[6];
- else
- return relation_types[5];
case AO_ROW_TABLE_AM_OID:
+ return relation_types[5];
case AO_COLUMN_TABLE_AM_OID:
+ return relation_types[6];
+ case BRIN_AM_OID:
return relation_types[7];
-
+ case SPGIST_AM_OID:
+ return relation_types[8];
+ case BITMAP_AM_OID:
+ return relation_types[9];
default:
return relation_types[MAX_INCLUDE_RELATION_TYPES];
}
@@ -538,15 +537,8 @@ get_relfilenode_map()
{
Form_pg_class classtuple = (Form_pg_class) GETSTRUCT(tup);
- /* GPDB_12_MERGE_FIXME: What was the point of the relstorage test here? */
if ((classtuple->relkind == RELKIND_VIEW
- || classtuple->relkind == RELKIND_COMPOSITE_TYPE)
- /* || (classtuple->relstorage != RELSTORAGE_HEAP
- && !relstorage_is_ao(classtuple->relstorage)) */)
- continue;
-
- /* unlogged tables do not propagate to replica servers */
- if (classtuple->relpersistence == RELPERSISTENCE_UNLOGGED)
+ || classtuple->relkind == RELKIND_COMPOSITE_TYPE))
continue;
RelfilenodeEntry *rentry;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 22/41: make headerfile accessible to pxf extension (#14046)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit a1353bb7a8b3adfff7f52f2e29c0f4b3245daf14
Author: Himanshu Pandey <pa...@vmware.com>
AuthorDate: Thu Oct 27 10:55:02 2022 -0700
make headerfile accessible to pxf extension (#14046)
---
gpcontrib/gp_exttable_fdw/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gpcontrib/gp_exttable_fdw/Makefile b/gpcontrib/gp_exttable_fdw/Makefile
index de1dbec550..0441a36609 100644
--- a/gpcontrib/gp_exttable_fdw/Makefile
+++ b/gpcontrib/gp_exttable_fdw/Makefile
@@ -11,6 +11,8 @@ DATA = gp_exttable_fdw--1.0.sql
HEADERS = extaccess.h
REGRESS =
+HEADERS = extaccess.h
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 19/41: Bring back cdbsubselect_drop_distinct. (#14322)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ede16fd9b9ae429847be8f3942b0a6bf9a1b574d
Author: Aegeaner <gj...@vmware.com>
AuthorDate: Thu Oct 27 17:08:47 2022 +0800
Bring back cdbsubselect_drop_distinct. (#14322)
Previous commit ebb691a03 is to fix ANY sublink contains distinct-on
syntax on partial exprs in the target list of subselect. That fix
method simply not to drop distinct or order-by clause and might lead
to some sublink cannot be pulled up and bad performance, below is an
example of such regression:
select a from t where a in (select b from t1 group by b)
For the above SQL, if we do not drop the group-by clause, then later
planner will take the subselect as not simple and fail to pull it up
to a join.
This commit fixes the regression by:
1. revert the logic of ebb691a03
2. fix the issue #12656 using a correct way: if
the distinct on clause's length is not the
same as the length of subselect's targetlist,
we do not drop the distinct clause.
Authored-by: Jian Guo <gj...@vmware.com>
Co-authored-by: Zhenghua Lyu <ka...@gmail.com>
---
src/backend/cdb/cdbsubselect.c | 22 +++-
src/backend/optimizer/plan/subselect.c | 28 ++---
src/test/regress/expected/notin.out | 34 +++---
src/test/regress/expected/notin_optimizer.out | 34 +++---
src/test/regress/expected/rpt.out | 114 +++++++++------------
src/test/regress/expected/rpt_optimizer.out | 21 ++--
src/test/regress/expected/subselect.out | 10 +-
src/test/regress/expected/subselect_gp.out | 35 +++++--
.../regress/expected/subselect_gp_optimizer.out | 64 ++++++++----
src/test/regress/expected/subselect_optimizer.out | 8 +-
src/test/regress/sql/subselect_gp.sql | 7 ++
src/test/singlenode_regress/expected/subselect.out | 7 +-
.../singlenode_regress/expected/subselect_gp.out | 16 +--
13 files changed, 213 insertions(+), 187 deletions(-)
diff --git a/src/backend/cdb/cdbsubselect.c b/src/backend/cdb/cdbsubselect.c
index ae305e1e4b..9622aa2d74 100644
--- a/src/backend/cdb/cdbsubselect.c
+++ b/src/backend/cdb/cdbsubselect.c
@@ -466,7 +466,9 @@ cdbsubselect_drop_distinct(Query *subselect)
subselect->limitOffset == NULL)
{
/* Delete DISTINCT. */
- subselect->distinctClause = NIL;
+ if (!subselect->hasDistinctOn ||
+ list_length(subselect->distinctClause) == list_length(subselect->targetList))
+ subselect->distinctClause = NIL;
/* Delete GROUP BY if subquery has no aggregates and no HAVING. */
if (!subselect->hasAggs &&
@@ -485,7 +487,9 @@ cdbsubselect_drop_orderby(Query *subselect)
subselect->limitOffset == NULL)
{
/* Delete ORDER BY. */
- subselect->sortClause = NIL;
+ if (!subselect->hasDistinctOn ||
+ list_length(subselect->distinctClause) == list_length(subselect->targetList))
+ subselect->sortClause = NIL;
}
} /* cdbsubselect_drop_orderby */
@@ -1500,6 +1504,20 @@ convert_IN_to_antijoin(PlannerInfo *root, SubLink *sublink,
if (safe_to_convert_NOTIN(root, sublink, available_rels))
{
+ /* Delete ORDER BY and DISTINCT.
+ *
+ * There is no need to do the group-by or order-by inside the
+ * subquery, if we have decided to pull up the sublink. For the
+ * group-by case, after the sublink pull-up, there will be a semi-join
+ * plan node generated in top level, which will weed out duplicate
+ * tuples naturally. For the order-by case, after the sublink pull-up,
+ * the subquery will become a jointree, inside which the tuples' order
+ * doesn't matter. In a summary, it's safe to elimate the group-by or
+ * order-by causes here.
+ */
+ cdbsubselect_drop_orderby(subselect);
+ cdbsubselect_drop_distinct(subselect);
+
int subq_indx = add_notin_subquery_rte(parse, subselect);
List *inner_exprs = NIL;
List *outer_exprs = NIL;
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 4975d2cc6b..538e3da6e8 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -1538,6 +1538,20 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
Assert(sublink->subLinkType == ANY_SUBLINK);
Assert(IsA(subselect, Query));
+ /* Delete ORDER BY and DISTINCT.
+ *
+ * There is no need to do the group-by or order-by inside the
+ * subquery, if we have decided to pull up the sublink. For the
+ * group-by case, after the sublink pull-up, there will be a semi-join
+ * plan node generated in top level, which will weed out duplicate
+ * tuples naturally. For the order-by case, after the sublink pull-up,
+ * the subquery will become a jointree, inside which the tuples' order
+ * doesn't matter. In a summary, it's safe to elimate the group-by or
+ * order-by causes here.
+ */
+ cdbsubselect_drop_orderby(subselect);
+ cdbsubselect_drop_distinct(subselect);
+
/*
* If uncorrelated, and no Var nodes on lhs, the subquery will be executed
* only once. It should become an InitPlan, but make_subplan() doesn't
@@ -1548,20 +1562,6 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
if (correlated)
{
- /* Delete ORDER BY and DISTINCT.
- *
- * There is no need to do the group-by or order-by inside the
- * subquery, if we have decided to pull up the sublink (when the
- * subquery is correlated). For the group-by case, after the sublink
- * pull-up, there will be a semi-join plan node generated in top
- * level, which will weed out duplicate tuples naturally. For the
- * order-by case, after the sublink pull-up, the subquery will become
- * a jointree, inside which the tuples' order doesn't matter. In a
- * summary, it's safe to elimate the group-by or order-by causes here.
- */
- cdbsubselect_drop_orderby(subselect);
- cdbsubselect_drop_distinct(subselect);
-
/*
* Under certain conditions, we cannot pull up the subquery as a join.
*/
diff --git a/src/test/regress/expected/notin.out b/src/test/regress/expected/notin.out
index 97ce4dce01..7baac477d8 100644
--- a/src/test/regress/expected/notin.out
+++ b/src/test/regress/expected/notin.out
@@ -400,30 +400,26 @@ select a,b from g1 where (a,b) not in
--
explain select x,y from l1 where (x,y) not in
(select distinct y, sum(x) from l1 group by y having y < 4 order by y) order by 1,2;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.35..10000000002.40 rows=3 width=8)
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice3; segments: 3) (cost=10000000008.02..10000000008.03 rows=4 width=8)
Merge Key: l1.x, l1.y
-> Sort (cost=10000000002.35..10000000002.36 rows=1 width=8)
Sort Key: l1.x, l1.y
- -> Nested Loop Left Anti Semi (Not-In) Join (cost=10000000001.07..10000000002.34 rows=1 width=8)
+ -> Nested Loop Left Anti Semi (Not-In) Join (cost=10000000003.25..10000000007.99 rows=2 width=8)
Join Filter: ((l1.x = "NotIn_SUBQUERY".y) AND (l1.y = "NotIn_SUBQUERY".sum))
- -> Seq Scan on l1 (cost=0.00..1.03 rows=3 width=8)
- -> Materialize (cost=1.09..1.16 rows=3 width=12)
- -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=1.09..1.15 rows=3 width=12)
- -> Subquery Scan on "NotIn_SUBQUERY" (cost=1.09..1.11 rows=1 width=12)
- -> Unique (cost=1.09..1.10 rows=1 width=16)
- Group Key: l1_1.y, (sum(l1_1.x))
- -> Sort (cost=1.09..1.09 rows=1 width=16)
- Sort Key: l1_1.y, (sum(l1_1.x))
- -> HashAggregate (cost=1.07..1.08 rows=1 width=16)
- Group Key: l1_1.y
- -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.06 rows=1 width=8)
- Hash Key: l1_1.y
- -> Seq Scan on l1 l1_1 (cost=0.00..1.04 rows=1 width=8)
- Filter: (y < 4)
+ -> Seq Scan on l1 (cost=0.00..3.10 rows=4 width=8)
+ -> Materialize (cost=3.25..3.47 rows=3 width=12)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=3.25..3.43 rows=3 width=12)
+ -> Subquery Scan on "NotIn_SUBQUERY" (cost=3.25..3.31 rows=1 width=12)
+ -> HashAggregate (cost=3.25..3.28 rows=1 width=16)
+ Group Key: l1_1.y
+ -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=3.14..3.20 rows=1 width=12)
+ Hash Key: l1_1.y
+ -> Seq Scan on l1 l1_1 (cost=0.00..3.12 rows=2 width=8)
+ Filter: (y < 4)
Optimizer: Postgres query optimizer
-(21 rows)
+(17 rows)
select x,y from l1 where (x,y) not in
(select distinct y, sum(x) from l1 group by y having y < 4 order by y) order by 1,2;
diff --git a/src/test/regress/expected/notin_optimizer.out b/src/test/regress/expected/notin_optimizer.out
index 02a114d083..46052b7e4f 100644
--- a/src/test/regress/expected/notin_optimizer.out
+++ b/src/test/regress/expected/notin_optimizer.out
@@ -407,30 +407,26 @@ select a,b from g1 where (a,b) not in
--
explain select x,y from l1 where (x,y) not in
(select distinct y, sum(x) from l1 group by y having y < 4 order by y) order by 1,2;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.35..10000000002.40 rows=3 width=8)
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice3; segments: 3) (cost=10000000008.02..10000000008.03 rows=4 width=8)
Merge Key: l1.x, l1.y
-> Sort (cost=10000000002.35..10000000002.36 rows=1 width=8)
Sort Key: l1.x, l1.y
- -> Nested Loop Left Anti Semi (Not-In) Join (cost=10000000001.07..10000000002.34 rows=1 width=8)
+ -> Nested Loop Left Anti Semi (Not-In) Join (cost=10000000003.25..10000000007.99 rows=2 width=8)
Join Filter: ((l1.x = "NotIn_SUBQUERY".y) AND (l1.y = "NotIn_SUBQUERY".sum))
- -> Seq Scan on l1 (cost=0.00..1.03 rows=3 width=8)
- -> Materialize (cost=1.09..1.16 rows=3 width=12)
- -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=1.09..1.15 rows=3 width=12)
- -> Subquery Scan on "NotIn_SUBQUERY" (cost=1.09..1.11 rows=1 width=12)
- -> Unique (cost=1.09..1.10 rows=1 width=16)
- Group Key: l1_1.y, (sum(l1_1.x))
- -> Sort (cost=1.09..1.09 rows=1 width=16)
- Sort Key: l1_1.y, (sum(l1_1.x))
- -> HashAggregate (cost=1.07..1.08 rows=1 width=16)
- Group Key: l1_1.y
- -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.06 rows=1 width=8)
- Hash Key: l1_1.y
- -> Seq Scan on l1 l1_1 (cost=0.00..1.04 rows=1 width=8)
- Filter: (y < 4)
+ -> Seq Scan on l1 (cost=0.00..3.10 rows=4 width=8)
+ -> Materialize (cost=3.25..3.47 rows=3 width=12)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=3.25..3.43 rows=3 width=12)
+ -> Subquery Scan on "NotIn_SUBQUERY" (cost=3.25..3.31 rows=1 width=12)
+ -> HashAggregate (cost=3.25..3.28 rows=1 width=16)
+ Group Key: l1_1.y
+ -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=3.14..3.20 rows=1 width=12)
+ Hash Key: l1_1.y
+ -> Seq Scan on l1 l1_1 (cost=0.00..3.12 rows=2 width=8)
+ Filter: (y < 4)
Optimizer: Postgres query optimizer
-(21 rows)
+(19 rows)
select x,y from l1 where (x,y) not in
(select distinct y, sum(x) from l1 group by y having y < 4 order by y) order by 1,2;
diff --git a/src/test/regress/expected/rpt.out b/src/test/regress/expected/rpt.out
index 367ebd5b40..389a5f63c0 100644
--- a/src/test/regress/expected/rpt.out
+++ b/src/test/regress/expected/rpt.out
@@ -1104,15 +1104,13 @@ explain select b from dist_tab where b in (select distinct c from rep_tab);
---------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.16..10000000021.44 rows=4 width=4)
-> Nested Loop (cost=10000000001.16..10000000021.39 rows=1 width=4)
- -> Unique (cost=10000000001.03..10000000001.04 rows=2 width=4)
+ -> HashAggregate (cost=10000000001.02..10000000001.03 rows=2 width=4)
Group Key: rep_tab.c
- -> Sort (cost=10000000001.03..10000000001.03 rows=2 width=4)
- Sort Key: rep_tab.c
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
-> Index Only Scan using idx on dist_tab (cost=0.13..10.16 rows=1 width=4)
Index Cond: (b = rep_tab.c)
Optimizer: Postgres query optimizer
-(10 rows)
+(8 rows)
select b from dist_tab where b in (select distinct c from rep_tab);
b
@@ -1135,20 +1133,16 @@ analyze rand_tab;
--
-- join derives EdtHashed
explain select c from rep_tab where c in (select distinct c from rep_tab);
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
- Gather Motion 1:1 (slice1; segments: 1) (cost=20000000002.14..20000000002.14 rows=3 width=4)
- -> Hash Join (cost=20000000001.08..20000000002.14 rows=3 width=4)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------
+ Gather Motion 1:1 (slice1; segments: 1) (cost=20000000001.05..20000000002.11 rows=4 width=4)
+ -> Hash Semi Join (cost=20000000001.05..20000000002.11 rows=4 width=4)
Hash Cond: (rep_tab.c = rep_tab_1.c)
-> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
- -> Hash (cost=10000000001.06..10000000001.06 rows=2 width=4)
- -> Unique (cost=10000000001.03..10000000001.04 rows=2 width=4)
- Group Key: rep_tab_1.c
- -> Sort (cost=10000000001.03..10000000001.03 rows=2 width=4)
- Sort Key: rep_tab_1.c
- -> Seq Scan on rep_tab rep_tab_1 (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Hash (cost=10000000001.02..10000000001.02 rows=1 width=4)
+ -> Seq Scan on rep_tab rep_tab_1 (cost=10000000000.00..10000000001.02 rows=2 width=4)
Optimizer: Postgres query optimizer
-(11 rows)
+(7 rows)
select c from rep_tab where c in (select distinct c from rep_tab);
c
@@ -1163,20 +1157,16 @@ select c from rep_tab where c in (select distinct c from rep_tab);
--
-- join derives EdtHashed
explain select a from dist_tab where a in (select distinct c from rep_tab);
- QUERY PLAN
----------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.08..20000000002.17 rows=4 width=4)
- -> Hash Join (cost=20000000001.08..20000000002.12 rows=1 width=4)
+ QUERY PLAN
+------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.05..20000000003.14 rows=4 width=4)
+ -> Hash Semi Join (cost=20000000001.05..20000000003.14 rows=2 width=4)
Hash Cond: (dist_tab.a = rep_tab.c)
- -> Seq Scan on dist_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
- -> Hash (cost=10000000001.06..10000000001.06 rows=2 width=4)
- -> Unique (cost=10000000001.03..10000000001.04 rows=2 width=4)
- Group Key: rep_tab.c
- -> Sort (cost=10000000001.03..10000000001.03 rows=2 width=4)
- Sort Key: rep_tab.c
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Seq Scan on dist_tab (cost=10000000000.00..10000000002.04 rows=2 width=4)
+ -> Hash (cost=10000000001.02..10000000001.02 rows=1 width=4)
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
Optimizer: Postgres query optimizer
-(11 rows)
+(7 rows)
select a from dist_tab where a in (select distinct c from rep_tab);
a
@@ -1193,20 +1183,16 @@ select a from dist_tab where a in (select distinct c from rep_tab);
--
-- join derives EdtRandom
explain select d from rand_tab where d in (select distinct c from rep_tab);
- QUERY PLAN
----------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.08..20000000002.15 rows=3 width=4)
- -> Hash Join (cost=20000000001.08..20000000002.11 rows=1 width=4)
+ QUERY PLAN
+------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.05..20000000002.11 rows=4 width=4)
+ -> Hash Semi Join (cost=20000000001.05..20000000002.11 rows=2 width=4)
Hash Cond: (rand_tab.d = rep_tab.c)
- -> Seq Scan on rand_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
- -> Hash (cost=10000000001.06..10000000001.06 rows=2 width=4)
- -> Unique (cost=10000000001.03..10000000001.04 rows=2 width=4)
- Group Key: rep_tab.c
- -> Sort (cost=10000000001.03..10000000001.03 rows=2 width=4)
- Sort Key: rep_tab.c
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Seq Scan on rand_tab (cost=10000000000.00..10000000001.02 rows=1 width=4)
+ -> Hash (cost=10000000001.02..10000000001.02 rows=1 width=4)
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
Optimizer: Postgres query optimizer
-(11 rows)
+(7 rows)
select d from rand_tab where d in (select distinct c from rep_tab);
d
@@ -1221,20 +1207,18 @@ select d from rand_tab where d in (select distinct c from rep_tab);
--
-- join derives EdtHashed
explain select c from rep_tab where c in (select distinct a from dist_tab);
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.05..20000000002.14 rows=3 width=4)
- -> Hash Join (cost=20000000001.05..20000000002.09 rows=1 width=4)
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.03..20000000002.14 rows=3 width=4)
+ -> Hash Semi Join (cost=20000000001.03..20000000002.09 rows=1 width=4)
Hash Cond: (rep_tab.c = dist_tab.a)
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
- -> Hash (cost=10000000001.04..10000000001.04 rows=1 width=4)
- -> Unique (cost=10000000001.02..10000000001.03 rows=1 width=4)
- Group Key: dist_tab.a
- -> Sort (cost=10000000001.02..10000000001.03 rows=1 width=4)
- Sort Key: dist_tab.a
- -> Seq Scan on dist_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
+ -> Redistribute Motion 1:3 (slice2; segments: 1) (cost=10000000000.00..10000000001.05 rows=1 width=4)
+ Hash Key: rep_tab.c
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Hash (cost=10000000001.01..10000000001.01 rows=1 width=4)
+ -> Seq Scan on dist_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
Optimizer: Postgres query optimizer
-(11 rows)
+(9 rows)
select c from rep_tab where c in (select distinct a from dist_tab);
c
@@ -1249,22 +1233,20 @@ select c from rep_tab where c in (select distinct a from dist_tab);
--
-- join derives EdtHashed
explain select c from rep_tab where c in (select distinct d from rand_tab);
- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.07..20000000002.15 rows=3 width=4)
- -> Hash Join (cost=20000000001.07..20000000002.11 rows=1 width=4)
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=20000000001.04..20000000002.15 rows=3 width=4)
+ -> Hash Semi Join (cost=20000000001.04..20000000002.11 rows=1 width=4)
Hash Cond: (rep_tab.c = rand_tab.d)
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
- -> Hash (cost=10000000001.06..10000000001.06 rows=1 width=4)
- -> Unique (cost=10000000001.04..10000000001.05 rows=1 width=4)
- Group Key: rand_tab.d
- -> Sort (cost=10000000001.04..10000000001.05 rows=1 width=4)
- Sort Key: rand_tab.d
- -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=10000000000.00..10000000001.03 rows=1 width=4)
- Hash Key: rand_tab.d
- -> Seq Scan on rand_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
+ -> Redistribute Motion 1:3 (slice2; segments: 1) (cost=10000000000.00..10000000001.05 rows=1 width=4)
+ Hash Key: rep_tab.c
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Hash (cost=10000000001.03..10000000001.03 rows=1 width=4)
+ -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=10000000000.00..10000000001.03 rows=1 width=4)
+ Hash Key: rand_tab.d
+ -> Seq Scan on rand_tab (cost=10000000000.00..10000000001.01 rows=1 width=4)
Optimizer: Postgres query optimizer
-(13 rows)
+(11 rows)
select c from rep_tab where c in (select distinct d from rand_tab);
c
diff --git a/src/test/regress/expected/rpt_optimizer.out b/src/test/regress/expected/rpt_optimizer.out
index 62a9fe489a..5585b29b56 100644
--- a/src/test/regress/expected/rpt_optimizer.out
+++ b/src/test/regress/expected/rpt_optimizer.out
@@ -1092,20 +1092,17 @@ set optimizer_enable_hashjoin=off;
set enable_hashjoin=off;
set enable_nestloop=on;
explain select b from dist_tab where b in (select distinct c from rep_tab);
- QUERY PLAN
----------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..443.00 rows=4 width=4)
- -> Nested Loop (cost=0.00..443.00 rows=2 width=4)
- Join Filter: true
- -> GroupAggregate (cost=0.00..431.00 rows=2 width=4)
+ QUERY PLAN
+------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.15..10000000021.42 rows=4 width=4)
+ -> Nested Loop (cost=10000000001.15..10000000021.36 rows=1 width=4)
+ -> HashAggregate (cost=10000000001.02..10000000001.03 rows=2 width=4)
Group Key: rep_tab.c
- -> Sort (cost=0.00..431.00 rows=2 width=4)
- Sort Key: rep_tab.c
- -> Seq Scan on rep_tab (cost=0.00..431.00 rows=2 width=4)
- -> Index Scan using idx on dist_tab (cost=0.00..12.00 rows=1 width=4)
+ -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
+ -> Index Only Scan using idx on dist_tab (cost=0.13..10.16 rows=1 width=4)
Index Cond: (b = rep_tab.c)
- Optimizer: Pivotal Optimizer (GPORCA)
-(11 rows)
+ Optimizer: Postgres query optimizer
+(8 rows)
select b from dist_tab where b in (select distinct c from rep_tab);
b
diff --git a/src/test/regress/expected/subselect.out b/src/test/regress/expected/subselect.out
index 427fdf060d..f4517c9b58 100644
--- a/src/test/regress/expected/subselect.out
+++ b/src/test/regress/expected/subselect.out
@@ -1358,16 +1358,10 @@ select * from int4_tbl o where (f1, f1) in
Output: i.f1, ((generate_series(1, 50)) / 10)
-> ProjectSet
Output: generate_series(1, 50), i.f1
- -> GroupAggregate
+ -> Seq Scan on public.int4_tbl i
Output: i.f1
- Group Key: i.f1
- -> Sort
- Output: i.f1
- Sort Key: i.f1
- -> Seq Scan on public.int4_tbl i
- Output: i.f1
Optimizer: Postgres query optimizer
-(25 rows)
+(20 rows)
select * from int4_tbl o where (f1, f1) in
(select f1, generate_series(1,50) / 10 g from int4_tbl i group by f1);
diff --git a/src/test/regress/expected/subselect_gp.out b/src/test/regress/expected/subselect_gp.out
index 3dc5dcdfa7..9aff68f249 100644
--- a/src/test/regress/expected/subselect_gp.out
+++ b/src/test/regress/expected/subselect_gp.out
@@ -1763,11 +1763,9 @@ EXPLAIN select count(*) from
Group Key: b.hundred
-> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..389.00 rows=3334 width=4)
Hash Key: b.hundred
- -> HashAggregate (cost=70.67..71.67 rows=100 width=4)
- Group Key: b.hundred
-> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4)
Optimizer: Postgres query optimizer
-(15 rows)
+(13 rows)
EXPLAIN select count(distinct ss.ten) from
(select ten from tenk1 a
@@ -1791,9 +1789,7 @@ EXPLAIN select count(distinct ss.ten) from
Group Key: b.hundred
-> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..389.00 rows=3334 width=4)
Hash Key: b.hundred
- -> HashAggregate (cost=70.67..71.67 rows=100 width=4)
- Group Key: b.hundred
- -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4)
+ -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4)
Optimizer: Postgres query optimizer
(19 rows)
@@ -3053,6 +3049,33 @@ select * from issue_12656 where (i, j) in (select distinct on (i) i, j from issu
1 | 10002
(1 row)
+-- case 3, check correlated DISTINCT ON
+explain select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..895.00 rows=43050 width=8)
+ -> Seq Scan on issue_12656 a (cost=0.00..321.00 rows=14350 width=8)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Unique (cost=9818.00..10033.25 rows=1000 width=8)
+ -> Sort (cost=9818.00..10033.25 rows=86100 width=8)
+ Sort Key: b.j
+ -> Result (cost=0.00..2760.50 rows=86100 width=8)
+ Filter: (a.i = b.i)
+ -> Materialize (cost=0.00..1899.50 rows=86100 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..1469.00 rows=86100 width=8)
+ -> Seq Scan on issue_12656 b (cost=0.00..321.00 rows=28700 width=8)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
+select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+ i | j
+---+-------
+ 1 | 10001
+(1 row)
+
---
--- Test param info is preserved when bringing a path to OuterQuery locus
---
diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out
index e9a83655cd..a8bca6365f 100644
--- a/src/test/regress/expected/subselect_gp_optimizer.out
+++ b/src/test/regress/expected/subselect_gp_optimizer.out
@@ -1775,27 +1775,22 @@ EXPLAIN select count(distinct ss.ten) from
EXPLAIN select count(*) from
(select 1 from tenk1 a
where unique1 IN (select distinct hundred from tenk1 b)) ss;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
- Finalize Aggregate (cost=0.00..431.98 rows=1 width=8)
- -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.98 rows=1 width=8)
- -> Partial Aggregate (cost=0.00..431.98 rows=1 width=8)
- -> Nested Loop (cost=0.00..431.98 rows=34 width=1)
- Join Filter: true
- -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.94 rows=100 width=4)
- -> GroupAggregate (cost=0.00..431.94 rows=34 width=4)
- Group Key: tenk1.hundred
- -> Sort (cost=0.00..431.94 rows=34 width=4)
- Sort Key: tenk1.hundred
- -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..431.94 rows=34 width=4)
- Hash Key: tenk1.hundred
- -> Streaming HashAggregate (cost=0.00..431.94 rows=34 width=4)
- Group Key: tenk1.hundred
- -> Seq Scan on tenk1 (cost=0.00..431.51 rows=3334 width=4)
- -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (cost=0.00..0.04 rows=1 width=1)
- Index Cond: (unique1 = tenk1.hundred)
- Optimizer: Pivotal Optimizer (GPORCA) version 2.75.0
-(17 rows)
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------
+ Finalize Aggregate (cost=210.51..210.52 rows=1 width=8)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=210.45..210.50 rows=3 width=8)
+ -> Partial Aggregate (cost=210.45..210.46 rows=1 width=8)
+ -> Hash Join (cost=138.92..210.37 rows=33 width=0)
+ Hash Cond: (a.unique1 = b.hundred)
+ -> Seq Scan on tenk1 a (cost=0.00..62.33 rows=3333 width=4)
+ -> Hash (cost=137.67..137.67 rows=100 width=4)
+ -> HashAggregate (cost=137.33..137.67 rows=100 width=4)
+ Group Key: b.hundred
+ -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..129.00 rows=3333 width=4)
+ Hash Key: b.hundred
+ -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4)
+ Optimizer: Postgres query optimizer
+(13 rows)
EXPLAIN select count(distinct ss.ten) from
(select ten from tenk1 a
@@ -3146,6 +3141,33 @@ select * from issue_12656 where (i, j) in (select distinct on (i) i, j from issu
1 | 10002
(1 row)
+-- case 3, check correlated DISTINCT ON
+explain select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..895.00 rows=43050 width=8)
+ -> Seq Scan on issue_12656 a (cost=0.00..321.00 rows=14350 width=8)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Unique (cost=9818.00..10033.25 rows=1000 width=8)
+ -> Sort (cost=9818.00..10033.25 rows=86100 width=8)
+ Sort Key: b.j
+ -> Result (cost=0.00..2760.50 rows=86100 width=8)
+ Filter: (a.i = b.i)
+ -> Materialize (cost=0.00..1899.50 rows=86100 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..1469.00 rows=86100 width=8)
+ -> Seq Scan on issue_12656 b (cost=0.00..321.00 rows=28700 width=8)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
+select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+ i | j
+---+-------
+ 1 | 10001
+(1 row)
+
---
--- Test param info is preserved when bringing a path to OuterQuery locus
---
diff --git a/src/test/regress/expected/subselect_optimizer.out b/src/test/regress/expected/subselect_optimizer.out
index 3855edf1b9..c56ad50a3b 100644
--- a/src/test/regress/expected/subselect_optimizer.out
+++ b/src/test/regress/expected/subselect_optimizer.out
@@ -1410,14 +1410,8 @@ select * from int4_tbl o where (f1, f1) in
Output: i.f1, ((generate_series(1, 50)) / 10)
-> ProjectSet
Output: generate_series(1, 50), i.f1
- -> GroupAggregate
+ -> Seq Scan on public.int4_tbl i
Output: i.f1
- Group Key: i.f1
- -> Sort
- Output: i.f1
- Sort Key: i.f1
- -> Seq Scan on public.int4_tbl i
- Output: i.f1
Optimizer: Postgres query optimizer
(19 rows)
diff --git a/src/test/regress/sql/subselect_gp.sql b/src/test/regress/sql/subselect_gp.sql
index f83ddf6456..bdc4346274 100644
--- a/src/test/regress/sql/subselect_gp.sql
+++ b/src/test/regress/sql/subselect_gp.sql
@@ -1209,6 +1209,13 @@ select * from issue_12656 where (i, j) in (select distinct on (i) i, j from issu
select * from issue_12656 where (i, j) in (select distinct on (i) i, j from issue_12656 order by i, j desc);
+-- case 3, check correlated DISTINCT ON
+explain select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+
+select * from issue_12656 a where (i, j) in
+(select distinct on (i) i, j from issue_12656 b where a.i=b.i order by i, j asc);
+
---
--- Test param info is preserved when bringing a path to OuterQuery locus
---
diff --git a/src/test/singlenode_regress/expected/subselect.out b/src/test/singlenode_regress/expected/subselect.out
index 54a2ba10ac..d2b4222e2d 100644
--- a/src/test/singlenode_regress/expected/subselect.out
+++ b/src/test/singlenode_regress/expected/subselect.out
@@ -1356,13 +1356,10 @@ select * from int4_tbl o where (f1, f1) in
Output: i.f1, ((generate_series(1, 50)) / 10)
-> ProjectSet
Output: generate_series(1, 50), i.f1
- -> HashAggregate
+ -> Seq Scan on public.int4_tbl i
Output: i.f1
- Group Key: i.f1
- -> Seq Scan on public.int4_tbl i
- Output: i.f1
Optimizer: Postgres query optimizer
-(20 rows)
+(17 rows)
select * from int4_tbl o where (f1, f1) in
(select f1, generate_series(1,50) / 10 g from int4_tbl i group by f1);
diff --git a/src/test/singlenode_regress/expected/subselect_gp.out b/src/test/singlenode_regress/expected/subselect_gp.out
index 83cbeb2f5e..7538ea4b4d 100644
--- a/src/test/singlenode_regress/expected/subselect_gp.out
+++ b/src/test/singlenode_regress/expected/subselect_gp.out
@@ -1512,12 +1512,12 @@ EXPLAIN select count(*) from
where unique1 IN (select distinct hundred from tenk1 b)) ss;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
- Aggregate (cost=410.03..410.04 rows=1 width=8)
- -> Hash Join (cost=197.53..409.78 rows=100 width=0)
+ Aggregate (cost=410.15..410.16 rows=1 width=8)
+ -> Hash Join (cost=197.53..409.90 rows=100 width=0)
Hash Cond: (a.unique1 = b.hundred)
-> Seq Scan on tenk1 a (cost=0.00..185.00 rows=10000 width=4)
-> Hash (cost=196.28..196.28 rows=100 width=4)
- -> Unique (cost=0.29..195.28 rows=100 width=4)
+ -> HashAggregate (cost=195.28..196.28 rows=100 width=4)
Group Key: b.hundred
-> Index Only Scan using tenk1_hundred on tenk1 b (cost=0.29..170.28 rows=10000 width=4)
Optimizer: Postgres query optimizer
@@ -1528,12 +1528,12 @@ EXPLAIN select count(distinct ss.ten) from
where unique1 IN (select distinct hundred from tenk1 b)) ss;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
- Aggregate (cost=410.03..410.04 rows=1 width=8)
- -> Hash Join (cost=197.53..409.78 rows=100 width=4)
+ Aggregate (cost=410.15..410.16 rows=1 width=8)
+ -> Hash Join (cost=197.53..409.90 rows=100 width=4)
Hash Cond: (a.unique1 = b.hundred)
-> Seq Scan on tenk1 a (cost=0.00..185.00 rows=10000 width=8)
-> Hash (cost=196.28..196.28 rows=100 width=4)
- -> Unique (cost=0.29..195.28 rows=100 width=4)
+ -> HashAggregate (cost=195.28..196.28 rows=100 width=4)
Group Key: b.hundred
-> Index Only Scan using tenk1_hundred on tenk1 b (cost=0.29..170.28 rows=10000 width=4)
Optimizer: Postgres query optimizer
@@ -2187,7 +2187,7 @@ select * from foo left outer join baz on (select bar.i from bar where bar.i = fo
Output: bar.i
Filter: (bar.i = foo.i)
Optimizer: Postgres query optimizer
-(15 rows)
+(14 rows)
select * from foo left outer join baz on (select bar.i from bar where bar.i = foo.i) + 1 = baz.j;
i | j | i | j
@@ -2230,7 +2230,7 @@ select * from foo where
-> Seq Scan on subselect_gp.baz b
Output: b.i
Optimizer: Postgres query optimizer
-(14 rows)
+(13 rows)
select * from foo where
(case when foo.i in (select a.i from baz a) then foo.i else null end) in
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 11/41: Bring back cdbsubselect_drop_distinct from 5X branch. (#14258)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 8e3de84113e06200c1096e85a21e6a5cc41c533b
Author: Aegeaner <gj...@vmware.com>
AuthorDate: Wed Oct 19 11:50:05 2022 +0800
Bring back cdbsubselect_drop_distinct from 5X branch. (#14258)
In GP's convert_ANY_sublink_to_join() now, there is no simplification of
origin subquery, as a result sometimes the sublink cannot be pulled up,
which produced a bad query plan. In GP5, there is a subquery simplify
step which helped sublink pull-up, but we lose this simplification since
version 6X until master, which caused the sublink pull-up doesn't work as
only simple subquery is allowed to be pulled up. By this commit we brought
back cdbsubselect_drop_distinct and cdbsubselect_drop_orderby, then we can
got simplified subquery again and do the sublink pull-up optimization on it
which produced a better plan.
---
src/backend/cdb/cdbsubselect.c | 31 +++++++++
src/backend/optimizer/plan/subselect.c | 14 ++++
src/include/cdb/cdbsubselect.h | 3 +
src/test/regress/expected/subselect_gp.out | 71 ++++++++++++++++++++
.../regress/expected/subselect_gp_optimizer.out | 75 ++++++++++++++++++++++
src/test/regress/sql/subselect_gp.sql | 18 ++++++
6 files changed, 212 insertions(+)
diff --git a/src/backend/cdb/cdbsubselect.c b/src/backend/cdb/cdbsubselect.c
index 6180441c3e..ae305e1e4b 100644
--- a/src/backend/cdb/cdbsubselect.c
+++ b/src/backend/cdb/cdbsubselect.c
@@ -456,7 +456,38 @@ SubqueryToJoinWalker(Node *node, ConvertSubqueryToJoinContext *context)
return;
}
+/*
+ * cdbsubselect_drop_distinct
+ */
+void
+cdbsubselect_drop_distinct(Query *subselect)
+{
+ if (subselect->limitCount == NULL &&
+ subselect->limitOffset == NULL)
+ {
+ /* Delete DISTINCT. */
+ subselect->distinctClause = NIL;
+
+ /* Delete GROUP BY if subquery has no aggregates and no HAVING. */
+ if (!subselect->hasAggs &&
+ subselect->havingQual == NULL)
+ subselect->groupClause = NIL;
+ }
+} /* cdbsubselect_drop_distinct */
+/*
+ * cdbsubselect_drop_orderby
+ */
+void
+cdbsubselect_drop_orderby(Query *subselect)
+{
+ if (subselect->limitCount == NULL &&
+ subselect->limitOffset == NULL)
+ {
+ /* Delete ORDER BY. */
+ subselect->sortClause = NIL;
+ }
+} /* cdbsubselect_drop_orderby */
/**
* Safe to convert expr sublink to a join
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 41ecf8dbb1..4975d2cc6b 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -1548,6 +1548,20 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
if (correlated)
{
+ /* Delete ORDER BY and DISTINCT.
+ *
+ * There is no need to do the group-by or order-by inside the
+ * subquery, if we have decided to pull up the sublink (when the
+ * subquery is correlated). For the group-by case, after the sublink
+ * pull-up, there will be a semi-join plan node generated in top
+ * level, which will weed out duplicate tuples naturally. For the
+ * order-by case, after the sublink pull-up, the subquery will become
+ * a jointree, inside which the tuples' order doesn't matter. In a
+ * summary, it's safe to elimate the group-by or order-by causes here.
+ */
+ cdbsubselect_drop_orderby(subselect);
+ cdbsubselect_drop_distinct(subselect);
+
/*
* Under certain conditions, we cannot pull up the subquery as a join.
*/
diff --git a/src/include/cdb/cdbsubselect.h b/src/include/cdb/cdbsubselect.h
index 5cf3f85442..41df4f539c 100644
--- a/src/include/cdb/cdbsubselect.h
+++ b/src/include/cdb/cdbsubselect.h
@@ -24,4 +24,7 @@ extern bool is_simple_subquery(PlannerInfo *root, Query *subquery, RangeTblEntry
JoinExpr *lowest_outer_join);
extern JoinExpr *convert_IN_to_antijoin(PlannerInfo *root, SubLink *sublink, Relids available_rels);
+extern void cdbsubselect_drop_orderby(Query *subselect);
+extern void cdbsubselect_drop_distinct(Query *subselect);
+
#endif /* CDBSUBSELECT_H */
diff --git a/src/test/regress/expected/subselect_gp.out b/src/test/regress/expected/subselect_gp.out
index 2995f52a6d..3dc5dcdfa7 100644
--- a/src/test/regress/expected/subselect_gp.out
+++ b/src/test/regress/expected/subselect_gp.out
@@ -1626,6 +1626,77 @@ EXPLAIN SELECT '' AS five, f1 AS "Correlated Field"
Optimizer: Postgres query optimizer
(13 rows)
+-- Test simplify group-by/order-by inside subquery if sublink pull-up is possible
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2);
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=1.05..2.13 rows=3 width=40)
+ -> Hash Semi Join (cost=1.05..2.09 rows=1 width=40)
+ Hash Cond: (upper.f1 = subselect_tbl.f1)
+ -> Seq Scan on subselect_tbl upper (cost=0.00..1.03 rows=3 width=8)
+ -> Hash (cost=1.03..1.03 rows=1 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1.03 rows=1 width=8)
+ Filter: (f1 = f2)
+ Optimizer: Postgres query optimizer
+(8 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2 LIMIT 3);
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1.08 rows=4 width=40)
+ -> Seq Scan on subselect_tbl upper (cost=0.00..1.03 rows=1 width=40)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Limit (cost=1.27..1.30 rows=3 width=4)
+ -> HashAggregate (cost=1.27..1.33 rows=6 width=4)
+ Group Key: subselect_tbl.f2
+ -> Result (cost=0.00..1.25 rows=8 width=4)
+ Filter: (subselect_tbl.f1 = upper.f1)
+ -> Materialize (cost=0.00..1.17 rows=8 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..1.13 rows=8 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1.03 rows=3 width=8)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2);
+ QUERY PLAN
+-------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=1.05..2.13 rows=3 width=40)
+ -> Hash Semi Join (cost=1.05..2.09 rows=1 width=40)
+ Hash Cond: (upper.f1 = subselect_tbl.f1)
+ -> Seq Scan on subselect_tbl upper (cost=0.00..1.03 rows=3 width=8)
+ -> Hash (cost=1.03..1.03 rows=1 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1.03 rows=1 width=8)
+ Filter: (f1 = f2)
+ Optimizer: Postgres query optimizer
+(8 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2 LIMIT 3);
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1.08 rows=4 width=40)
+ -> Seq Scan on subselect_tbl upper (cost=0.00..1.03 rows=1 width=40)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Limit (cost=1.36..1.36 rows=3 width=4)
+ -> Sort (cost=1.36..1.38 rows=8 width=4)
+ Sort Key: subselect_tbl.f2
+ -> Result (cost=0.00..1.25 rows=8 width=4)
+ Filter: (subselect_tbl.f1 = upper.f1)
+ -> Materialize (cost=0.00..1.17 rows=8 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..1.13 rows=8 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1.03 rows=3 width=8)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
--
-- Test cases to catch unpleasant interactions between IN-join processing
-- and subquery pullup.
diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out
index 8aba40fb65..e9a83655cd 100644
--- a/src/test/regress/expected/subselect_gp_optimizer.out
+++ b/src/test/regress/expected/subselect_gp_optimizer.out
@@ -1642,6 +1642,81 @@ EXPLAIN SELECT '' AS five, f1 AS "Correlated Field"
Optimizer: Postgres query optimizer
(13 rows)
+-- Test simplify group-by/order-by inside subquery if sublink pull-up is possible
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Result (cost=0.00..862.00 rows=8 width=16)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.00 rows=8 width=8)
+ -> Hash Semi Join (cost=0.00..862.00 rows=3 width=8)
+ Hash Cond: ((subselect_tbl.f1 = subselect_tbl_1.f1) AND (subselect_tbl.f1 = subselect_tbl_1.f2))
+ -> Seq Scan on subselect_tbl (cost=0.00..431.00 rows=3 width=8)
+ -> Hash (cost=431.00..431.00 rows=3 width=8)
+ -> Seq Scan on subselect_tbl subselect_tbl_1 (cost=0.00..431.00 rows=3 width=8)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(8 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2 LIMIT 3);
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------
+ Result (cost=0.00..1324038.55 rows=8 width=16)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1324038.55 rows=8 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1324038.55 rows=3 width=8)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Limit (cost=0.00..431.01 rows=1 width=4)
+ -> GroupAggregate (cost=0.00..431.01 rows=1 width=4)
+ Group Key: subselect_tbl_1.f2
+ -> Sort (cost=0.00..431.01 rows=1 width=4)
+ Sort Key: subselect_tbl_1.f2
+ -> Result (cost=0.00..431.01 rows=1 width=4)
+ Filter: (subselect_tbl_1.f1 = subselect_tbl.f1)
+ -> Materialize (cost=0.00..431.00 rows=8 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.00 rows=8 width=8)
+ -> Seq Scan on subselect_tbl subselect_tbl_1 (cost=0.00..431.00 rows=3 width=8)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(16 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Result (cost=0.00..862.00 rows=8 width=16)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.00 rows=8 width=8)
+ -> Hash Semi Join (cost=0.00..862.00 rows=3 width=8)
+ Hash Cond: ((subselect_tbl.f1 = subselect_tbl_1.f1) AND (subselect_tbl.f1 = subselect_tbl_1.f2))
+ -> Seq Scan on subselect_tbl (cost=0.00..431.00 rows=3 width=8)
+ -> Hash (cost=431.00..431.00 rows=3 width=8)
+ -> Seq Scan on subselect_tbl subselect_tbl_1 (cost=0.00..431.00 rows=3 width=8)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(8 rows)
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2 LIMIT 3);
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------
+ Result (cost=0.00..1324038.57 rows=8 width=16)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1324038.57 rows=8 width=8)
+ -> Seq Scan on subselect_tbl (cost=0.00..1324038.57 rows=3 width=8)
+ Filter: (SubPlan 1)
+ SubPlan 1
+ -> Limit (cost=0.00..431.01 rows=1 width=4)
+ -> Sort (cost=0.00..431.01 rows=1 width=4)
+ Sort Key: subselect_tbl_1.f2
+ -> Result (cost=0.00..431.01 rows=1 width=4)
+ Filter: (subselect_tbl_1.f1 = subselect_tbl.f1)
+ -> Materialize (cost=0.00..431.00 rows=8 width=8)
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.00 rows=8 width=8)
+ -> Seq Scan on subselect_tbl subselect_tbl_1 (cost=0.00..431.00 rows=3 width=8)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(14 rows)
+
--
-- Test cases to catch unpleasant interactions between IN-join processing
-- and subquery pullup.
diff --git a/src/test/regress/sql/subselect_gp.sql b/src/test/regress/sql/subselect_gp.sql
index de95b3d355..f83ddf6456 100644
--- a/src/test/regress/sql/subselect_gp.sql
+++ b/src/test/regress/sql/subselect_gp.sql
@@ -745,6 +745,24 @@ EXPLAIN SELECT '' AS five, f1 AS "Correlated Field"
WHERE (f1, f2) IN (SELECT f2, CAST(f3 AS int4) FROM SUBSELECT_TBL
WHERE f3 IS NOT NULL) ORDER BY 2;
+-- Test simplify group-by/order-by inside subquery if sublink pull-up is possible
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2);
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 GROUP BY f2 LIMIT 3);
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2);
+
+EXPLAIN SELECT '' AS six, f1 AS "Correlated Field", f2 AS "Second Field"
+ FROM SUBSELECT_TBL upper
+ WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL WHERE f1 = upper.f1 ORDER BY f2 LIMIT 3);
+
+
--
-- Test cases to catch unpleasant interactions between IN-join processing
-- and subquery pullup.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 35/41: Fix gpcheckcat partition distribution policy check
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 32be1d074ef252399988f77e78db421fa096400a
Author: Nihal Jain <jn...@jnihal-a01.vmware.com>
AuthorDate: Wed Nov 2 13:43:28 2022 +0530
Fix gpcheckcat partition distribution policy check
Earlier gpcheckcat used to error out when root partition has different distribution policy than child partition. But commit a45be43489294386c23c5fa068ce071ec068d0d8 introduces a new statement `ALTER TABLE EXPAND PARTITION PREPARE` which modifies the distribution policy of the leaf partitions to be randomly distributed. Based on this a policy is good if the following conditions are satisfied:
- numsegments value is equal for all root, middle and leaf level partitions
- if a root is randomly distributed, then all middle, leaf level partitions must also be randomly distributed
- if a root is hash distributed, then middle level should be same as root and leaf level partition can be hash on same key or randomly distributed
This commit modifies the existing SQL query such that whenever a parent is hash distributed, the child can be randomly distributed if and only if it is a leaf level partition.
Also added a few behave test cases for the same.
---
gpMgmt/bin/gpcheckcat | 10 +++--
gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature | 45 ++++++++++++++++++++++
.../gpcheckcat/create_multilevel_partition.sql | 14 +++++++
3 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/gpMgmt/bin/gpcheckcat b/gpMgmt/bin/gpcheckcat
index ecdd2d383f..da0d56479b 100755
--- a/gpMgmt/bin/gpcheckcat
+++ b/gpMgmt/bin/gpcheckcat
@@ -563,8 +563,10 @@ def checkPartitionIntegrity():
err = []
db = connect()
- # MPP-11120: check for child partitions with different
- # distribution policies.
+ # Check for the distribution policy of parent and child partitions based on the following conditions:
+ # 1. If a root is randomly distributed, then all middle, leaf level partitions must also be randomly distributed
+ # 2. If a root is hash distributed, then middle level should be same as root and
+ # leaf level partition can be hash on same key or randomly distributed
qry = '''
select inhparent::regclass, inhrelid::regclass,
pg_get_table_distributedby(inhparent) as dby_parent,
@@ -572,7 +574,9 @@ def checkPartitionIntegrity():
from pg_inherits inner join pg_partitioned_table on (pg_inherits.inhparent = pg_partitioned_table.partrelid)
where pg_get_table_distributedby(inhrelid) is distinct from pg_get_table_distributedby(inhparent)
and not (pg_get_table_distributedby(inhparent) = 'DISTRIBUTED RANDOMLY' and pg_get_table_distributedby(inhrelid) = '')
- and not (inhrelid in (select ftrelid from pg_catalog.pg_foreign_table) and pg_get_table_distributedby(inhrelid) = '');
+ and not (inhrelid in (select ftrelid from pg_catalog.pg_foreign_table) and pg_get_table_distributedby(inhrelid) = '')
+ and not (pg_get_table_distributedby(inhparent) like 'DISTRIBUTED BY%' and pg_get_table_distributedby(inhrelid) = 'DISTRIBUTED RANDOMLY'
+ and (select isleaf from pg_partition_tree(inhparent) where relid = inhrelid));
'''
try:
curs = db.query(qry)
diff --git a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
index ff8108362d..8645f720db 100644
--- a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
+++ b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
@@ -187,6 +187,51 @@ Feature: gpcheckcat tests
Then the user runs "dropdb policy_db"
And the path "gpcheckcat.repair.*" is removed from current working directory
+ Scenario: gpcheckcat should not report when parent is hash distributed and child is randomly distributed and child is a leaf level partition
+ Given database "policy_db" is dropped and recreated
+ And the user runs "psql policy_db -f test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql"
+ And the user runs sql "set allow_system_table_mods=true; update gp_distribution_policy set distkey = '', distclass='' where localoid='sales_1_prt_2_2_prt_asia'::regclass::oid;" in "policy_db" on all the segments
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 0
+ And gpcheckcat should not print "child partition\(s\) are distributed differently from the root partition, and must be manually redistributed, for some tables" to stdout
+ And gpcheckcat should not print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+ And the user runs "dropdb policy_db"
+
+ Scenario: gpcheckcat should report when parent is hash distributed and child is randomly distributed and child is a middle level partition
+ Given database "policy_db" is dropped and recreated
+ And the user runs "psql policy_db -f test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql"
+ And the user runs sql "set allow_system_table_mods=true; update gp_distribution_policy set distkey = '', distclass='' where localoid='sales_1_prt_2'::regclass::oid;" in "policy_db" on all the segments
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 1
+ And gpcheckcat should print "child partition\(s\) are distributed differently from the root partition, and must be manually redistributed, for some tables" to stdout
+ And gpcheckcat should print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+ And the user runs "dropdb policy_db"
+
+ Scenario: gpcheckcat should report when parent is randomly distributed and child is hash distributed
+ Given database "policy_db" is dropped and recreated
+ And the user runs "psql policy_db -f test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql"
+ And the user runs sql "set allow_system_table_mods=true; update gp_distribution_policy set distkey = '', distclass='' where localoid='sales'::regclass::oid;" in "policy_db" on all the segments
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 1
+ And gpcheckcat should print "child partition\(s\) are distributed differently from the root partition, and must be manually redistributed, for some tables" to stdout
+ And gpcheckcat should print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+ And the user runs "dropdb policy_db"
+
+ Scenario: gpcheckcat should not report part_integrity errors from readable external partitions
+ Given database "policy_db" is dropped and recreated
+ And the user runs "psql policy_db -c "create table part(a int) partition by list(a); create table p1(a int); create external web table p2_ext (like p1) EXECUTE 'cat something.txt' FORMAT 'TEXT';""
+ And the user runs "psql policy_db -c "alter table part attach partition p1 for values in (1); alter table part attach partition p2_ext for values in (2);""
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 0
+ And gpcheckcat should not print "child partition\(s\) have different numsegments value from the root partition" to stdout
+ And gpcheckcat should not print "child partition\(s\) are distributed differently from the root partition, and must be manually redistributed, for some tables" to stdout
+ And gpcheckcat should not print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+ And the user runs "dropdb policy_db"
+
Scenario: gpcheckcat foreign key check should report missing catalog entries. Also test missing_extraneous for the same case.
Given database "fkey_db" is dropped and recreated
And the path "gpcheckcat.repair.*" is removed from current working directory
diff --git a/gpMgmt/test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql b/gpMgmt/test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql
new file mode 100644
index 0000000000..f55d0c6896
--- /dev/null
+++ b/gpMgmt/test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql
@@ -0,0 +1,14 @@
+CREATE TABLE sales (trans_id int, date date, amount
+decimal(9,2), region text)
+DISTRIBUTED BY (trans_id)
+PARTITION BY RANGE (date)
+SUBPARTITION BY LIST (region)
+SUBPARTITION TEMPLATE
+( SUBPARTITION usa VALUES ('usa'),
+ SUBPARTITION asia VALUES ('asia'),
+ SUBPARTITION europe VALUES ('europe'),
+ DEFAULT SUBPARTITION other_regions)
+ (START (date '2011-01-01') INCLUSIVE
+ END (date '2012-01-01') EXCLUSIVE
+ EVERY (INTERVAL '1 month'),
+ DEFAULT PARTITION outlying_dates );
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 27/41: ao/co: Refactor DML states
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ed1d76f4fa6e3bf0a90c4fb46729177696121ff1
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Sat Oct 29 15:58:23 2022 -0700
ao/co: Refactor DML states
This commit makes the DML state nomenclature more canonical, cleans up
struct declarations etc.
---
src/backend/access/aocs/aocsam_handler.c | 115 ++++++++++----------
.../access/appendonly/appendonlyam_handler.c | 116 +++++++++------------
2 files changed, 109 insertions(+), 122 deletions(-)
diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c
index 6ebe7402b3..0fc06c4ad9 100644
--- a/src/backend/access/aocs/aocsam_handler.c
+++ b/src/backend/access/aocs/aocsam_handler.c
@@ -122,23 +122,16 @@ static void reset_state_cb(void *arg);
* a memory context that should be long lived enough and is
* responsible for reseting the state via its reset cb
*/
-static struct AOCOLocal
+typedef struct AOCODMLStates
{
AOCODMLState *last_used_state;
- HTAB *dmlDescriptorTab;
+ HTAB *state_table;
MemoryContext stateCxt;
MemoryContextCallback cb;
-} aocoLocal = {
- .last_used_state = NULL,
- .dmlDescriptorTab = NULL,
-
- .stateCxt = NULL,
- .cb = {
- .func = reset_state_cb,
- .arg = NULL
- },
-};
+} AOCODMLStates;
+
+static AOCODMLStates aocoDMLStates;
/*
* There are two cases that we are called from, during context destruction
@@ -150,32 +143,42 @@ static struct AOCOLocal
static void
reset_state_cb(void *arg)
{
- aocoLocal.dmlDescriptorTab = NULL;
- aocoLocal.last_used_state = NULL;
- aocoLocal.stateCxt = NULL;
+ aocoDMLStates.state_table = NULL;
+ aocoDMLStates.last_used_state = NULL;
+ aocoDMLStates.stateCxt = NULL;
}
+
+/*
+ * Initialize the backend local AOCODMLStates object for this backend for the
+ * current DML or DML-like command (if not already initialized).
+ *
+ * This function should be called with a current memory context whose life
+ * span is enough to last until the end of this command execution.
+ */
static void
-init_dml_local_state(void)
+init_aoco_dml_states()
{
HASHCTL hash_ctl;
- if (!aocoLocal.dmlDescriptorTab)
+ if (!aocoDMLStates.state_table)
{
- Assert(aocoLocal.stateCxt == NULL);
- aocoLocal.stateCxt = AllocSetContextCreate(
+ Assert(aocoDMLStates.stateCxt == NULL);
+ aocoDMLStates.stateCxt = AllocSetContextCreate(
CurrentMemoryContext,
"AppendOnly DML State Context",
ALLOCSET_SMALL_SIZES);
- MemoryContextRegisterResetCallback(
- aocoLocal.stateCxt,
- &aocoLocal.cb);
+
+ aocoDMLStates.cb.func = reset_state_cb;
+ aocoDMLStates.cb.arg = NULL;
+ MemoryContextRegisterResetCallback(aocoDMLStates.stateCxt,
+ &aocoDMLStates.cb);
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(AOCODMLState);
- hash_ctl.hcxt = aocoLocal.stateCxt;
- aocoLocal.dmlDescriptorTab =
+ hash_ctl.hcxt = aocoDMLStates.stateCxt;
+ aocoDMLStates.state_table =
hash_create("AppendOnly DML state", 128, &hash_ctl,
HASH_CONTEXT | HASH_ELEM | HASH_BLOBS);
}
@@ -187,19 +190,18 @@ init_dml_local_state(void)
*
* Should be called exactly once per relation.
*/
-static inline AOCODMLState *
-enter_dml_state(const Oid relationOid)
+static inline void
+init_dml_state(const Oid relationOid)
{
AOCODMLState *state;
bool found;
- Assert(aocoLocal.dmlDescriptorTab);
+ Assert(aocoDMLStates.state_table);
- state = (AOCODMLState *) hash_search(
- aocoLocal.dmlDescriptorTab,
- &relationOid,
- HASH_ENTER,
- &found);
+ state = (AOCODMLState *) hash_search(aocoDMLStates.state_table,
+ &relationOid,
+ HASH_ENTER,
+ &found);
state->insertDesc = NULL;
state->deleteDesc = NULL;
@@ -210,8 +212,7 @@ enter_dml_state(const Oid relationOid)
Assert(!found);
- aocoLocal.last_used_state = state;
- return state;
+ aocoDMLStates.last_used_state = state;
}
/*
@@ -222,21 +223,20 @@ static inline AOCODMLState *
find_dml_state(const Oid relationOid)
{
AOCODMLState *state;
- Assert(aocoLocal.dmlDescriptorTab);
+ Assert(aocoDMLStates.state_table);
- if (aocoLocal.last_used_state &&
- aocoLocal.last_used_state->relationOid == relationOid)
- return aocoLocal.last_used_state;
+ if (aocoDMLStates.last_used_state &&
+ aocoDMLStates.last_used_state->relationOid == relationOid)
+ return aocoDMLStates.last_used_state;
- state = (AOCODMLState *) hash_search(
- aocoLocal.dmlDescriptorTab,
- &relationOid,
- HASH_FIND,
- NULL);
+ state = (AOCODMLState *) hash_search(aocoDMLStates.state_table,
+ &relationOid,
+ HASH_FIND,
+ NULL);
Assert(state);
- aocoLocal.last_used_state = state;
+ aocoDMLStates.last_used_state = state;
return state;
}
@@ -250,20 +250,19 @@ static inline AOCODMLState *
remove_dml_state(const Oid relationOid)
{
AOCODMLState *state;
- Assert(aocoLocal.dmlDescriptorTab);
+ Assert(aocoDMLStates.state_table);
- state = (AOCODMLState *) hash_search(
- aocoLocal.dmlDescriptorTab,
- &relationOid,
- HASH_REMOVE,
- NULL);
+ state = (AOCODMLState *) hash_search(aocoDMLStates.state_table,
+ &relationOid,
+ HASH_REMOVE,
+ NULL);
if (!state)
return NULL;
- if (aocoLocal.last_used_state &&
- aocoLocal.last_used_state->relationOid == relationOid)
- aocoLocal.last_used_state = NULL;
+ if (aocoDMLStates.last_used_state &&
+ aocoDMLStates.last_used_state->relationOid == relationOid)
+ aocoDMLStates.last_used_state = NULL;
return state;
}
@@ -277,8 +276,8 @@ remove_dml_state(const Oid relationOid)
void
aoco_dml_init(Relation relation, CmdType operation)
{
- init_dml_local_state();
- (void) enter_dml_state(RelationGetRelid(relation));
+ init_aoco_dml_states();
+ init_dml_state(RelationGetRelid(relation));
}
/*
@@ -372,7 +371,7 @@ get_insert_descriptor(const Relation relation)
MemoryContext oldcxt;
state = find_dml_state(RelationGetRelid(relation));
- oldcxt = MemoryContextSwitchTo(aocoLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(aocoDMLStates.stateCxt);
if (state->insertDesc == NULL)
{
@@ -490,7 +489,7 @@ get_delete_descriptor(const Relation relation, bool forUpdate)
errmsg("deletes on append-only tables are not supported in serializable transactions")));
}
- oldcxt = MemoryContextSwitchTo(aocoLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(aocoDMLStates.stateCxt);
state->deleteDesc = aocs_delete_init(relation);
MemoryContextSwitchTo(oldcxt);
}
@@ -508,7 +507,7 @@ get_or_create_unique_check_desc(Relation relation, Snapshot snapshot)
MemoryContext oldcxt;
AOCSUniqueCheckDesc uniqueCheckDesc;
- oldcxt = MemoryContextSwitchTo(aocoLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(aocoDMLStates.stateCxt);
uniqueCheckDesc = palloc0(sizeof(AOCSUniqueCheckDescData));
/* Initialize the block directory */
diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c
index f1b07d2ada..2151ade951 100644
--- a/src/backend/access/appendonly/appendonlyam_handler.c
+++ b/src/backend/access/appendonly/appendonlyam_handler.c
@@ -92,23 +92,16 @@ typedef struct AppendOnlyDMLState
* a memory context that should be long lived enough and is
* responsible for reseting the state via its reset cb
*/
-static struct AppendOnlyLocal
+typedef struct AppendOnlyDMLStates
{
AppendOnlyDMLState *last_used_state;
- HTAB *dmlDescriptorTab;
+ HTAB *state_table;
MemoryContext stateCxt;
MemoryContextCallback cb;
-} appendOnlyLocal = {
- .last_used_state = NULL,
- .dmlDescriptorTab = NULL,
-
- .stateCxt = NULL,
- .cb = {
- .func = reset_state_cb,
- .arg = NULL
- },
-};
+} AppendOnlyDMLStates;
+
+static AppendOnlyDMLStates appendOnlyDMLStates;
/* ------------------------------------------------------------------------
* DML state related functions
@@ -116,60 +109,58 @@ static struct AppendOnlyLocal
*/
/*
+ * Initialize the backend local AppendOnlyDMLStates object for this backend for
+ * the current DML or DML-like command (if not already initialized).
+ *
* This function should be called with a current memory context whose life
* span is enough to last until the end of this command execution.
*/
static void
-init_dml_local_state(void)
+init_appendonly_dml_states()
{
HASHCTL hash_ctl;
- if (!appendOnlyLocal.dmlDescriptorTab)
+ if (!appendOnlyDMLStates.state_table)
{
- Assert(appendOnlyLocal.stateCxt == NULL);
- appendOnlyLocal.stateCxt = AllocSetContextCreate(
+ Assert(appendOnlyDMLStates.stateCxt == NULL);
+ appendOnlyDMLStates.stateCxt = AllocSetContextCreate(
CurrentMemoryContext,
"AppendOnly DML State Context",
ALLOCSET_SMALL_SIZES);
- MemoryContextRegisterResetCallback(
- appendOnlyLocal.stateCxt,
- &appendOnlyLocal.cb);
+
+ appendOnlyDMLStates.cb.func = reset_state_cb;
+ appendOnlyDMLStates.cb.arg = NULL;
+ MemoryContextRegisterResetCallback(appendOnlyDMLStates.stateCxt,
+ &appendOnlyDMLStates.cb);
memset(&hash_ctl, 0, sizeof(hash_ctl));
hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(AppendOnlyDMLState);
- hash_ctl.hcxt = appendOnlyLocal.stateCxt;
- appendOnlyLocal.dmlDescriptorTab =
+ hash_ctl.hcxt = appendOnlyDMLStates.stateCxt;
+ appendOnlyDMLStates.state_table =
hash_create("AppendOnly DML state", 128, &hash_ctl,
HASH_CONTEXT | HASH_ELEM | HASH_BLOBS);
}
}
-
-/*
- * There are disctinct *_dm_state functions in order to document a bit better
- * the intention behind each one of those and keep them as thin as possible.
- */
-
/*
* Create and insert a state entry for a relation. The actual descriptors will
* be created lazily when/if needed.
*
* Should be called exactly once per relation.
*/
-static inline AppendOnlyDMLState *
-enter_dml_state(const Oid relationOid)
+static inline void
+init_dml_state(const Oid relationOid)
{
AppendOnlyDMLState *state;
bool found;
- Assert(appendOnlyLocal.dmlDescriptorTab);
+ Assert(appendOnlyDMLStates.state_table);
- state = (AppendOnlyDMLState *) hash_search(
- appendOnlyLocal.dmlDescriptorTab,
- &relationOid,
- HASH_ENTER,
- &found);
+ state = (AppendOnlyDMLState *) hash_search(appendOnlyDMLStates.state_table,
+ &relationOid,
+ HASH_ENTER,
+ &found);
state->insertDesc = NULL;
state->deleteDesc = NULL;
@@ -180,8 +171,7 @@ enter_dml_state(const Oid relationOid)
Assert(!found);
- appendOnlyLocal.last_used_state = state;
- return state;
+ appendOnlyDMLStates.last_used_state = state;
}
/*
@@ -192,21 +182,20 @@ static inline AppendOnlyDMLState *
find_dml_state(const Oid relationOid)
{
AppendOnlyDMLState *state;
- Assert(appendOnlyLocal.dmlDescriptorTab);
+ Assert(appendOnlyDMLStates.state_table);
- if (appendOnlyLocal.last_used_state &&
- appendOnlyLocal.last_used_state->relationOid == relationOid)
- return appendOnlyLocal.last_used_state;
+ if (appendOnlyDMLStates.last_used_state &&
+ appendOnlyDMLStates.last_used_state->relationOid == relationOid)
+ return appendOnlyDMLStates.last_used_state;
- state = (AppendOnlyDMLState *) hash_search(
- appendOnlyLocal.dmlDescriptorTab,
- &relationOid,
- HASH_FIND,
- NULL);
+ state = (AppendOnlyDMLState *) hash_search(appendOnlyDMLStates.state_table,
+ &relationOid,
+ HASH_FIND,
+ NULL);
Assert(state);
- appendOnlyLocal.last_used_state = state;
+ appendOnlyDMLStates.last_used_state = state;
return state;
}
@@ -220,20 +209,19 @@ static inline AppendOnlyDMLState *
remove_dml_state(const Oid relationOid)
{
AppendOnlyDMLState *state;
- Assert(appendOnlyLocal.dmlDescriptorTab);
+ Assert(appendOnlyDMLStates.state_table);
- state = (AppendOnlyDMLState *) hash_search(
- appendOnlyLocal.dmlDescriptorTab,
- &relationOid,
- HASH_REMOVE,
- NULL);
+ state = (AppendOnlyDMLState *) hash_search(appendOnlyDMLStates.state_table,
+ &relationOid,
+ HASH_REMOVE,
+ NULL);
if (!state)
return NULL;
- if (appendOnlyLocal.last_used_state &&
- appendOnlyLocal.last_used_state->relationOid == relationOid)
- appendOnlyLocal.last_used_state = NULL;
+ if (appendOnlyDMLStates.last_used_state &&
+ appendOnlyDMLStates.last_used_state->relationOid == relationOid)
+ appendOnlyDMLStates.last_used_state = NULL;
return state;
}
@@ -247,8 +235,8 @@ remove_dml_state(const Oid relationOid)
void
appendonly_dml_init(Relation relation, CmdType operation)
{
- init_dml_local_state();
- (void) enter_dml_state(RelationGetRelid(relation));
+ init_appendonly_dml_states();
+ init_dml_state(RelationGetRelid(relation));
}
/*
@@ -340,9 +328,9 @@ appendonly_dml_finish(Relation relation, CmdType operation)
static void
reset_state_cb(void *arg)
{
- appendOnlyLocal.dmlDescriptorTab = NULL;
- appendOnlyLocal.last_used_state = NULL;
- appendOnlyLocal.stateCxt = NULL;
+ appendOnlyDMLStates.state_table = NULL;
+ appendOnlyDMLStates.last_used_state = NULL;
+ appendOnlyDMLStates.stateCxt = NULL;
}
/*
@@ -356,7 +344,7 @@ get_insert_descriptor(const Relation relation)
MemoryContext oldcxt;
state = find_dml_state(RelationGetRelid(relation));
- oldcxt = MemoryContextSwitchTo(appendOnlyLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(appendOnlyDMLStates.stateCxt);
if (state->insertDesc == NULL)
{
@@ -454,7 +442,7 @@ get_delete_descriptor(const Relation relation, bool forUpdate)
errmsg("deletes on append-only tables are not supported in serializable transactions")));
}
- oldcxt = MemoryContextSwitchTo(appendOnlyLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(appendOnlyDMLStates.stateCxt);
state->deleteDesc = appendonly_delete_init(relation);
MemoryContextSwitchTo(oldcxt);
}
@@ -472,7 +460,7 @@ get_or_create_unique_check_desc(Relation relation, Snapshot snapshot)
MemoryContext oldcxt;
AppendOnlyUniqueCheckDesc uniqueCheckDesc;
- oldcxt = MemoryContextSwitchTo(appendOnlyLocal.stateCxt);
+ oldcxt = MemoryContextSwitchTo(appendOnlyDMLStates.stateCxt);
uniqueCheckDesc = palloc0(sizeof(AppendOnlyUniqueCheckDescData));
/* Initialize the block directory */
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 38/41: fix ic-proxy mis-disconnect addrs after reload config file (#14415)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 142596d58433796ec2ae75f726c909919402d42e
Author: Jianghua Yang <yj...@gmail.com>
AuthorDate: Mon Dec 30 18:16:36 2024 +0800
fix ic-proxy mis-disconnect addrs after reload config file (#14415)
After we reload the config using pg_reload_conf, ic-proxy progress will call
ic_proxy_server_on_signal to process, It will compare the new addrs with the
old addrs, both the old and new lists must be sorted by dbid, the caller is responsible
to ensure this. If the addr is removed, it will be disconnected, if some addrs are added,
we will establish the connection, however, old addrs maybe not sorted by dbid in guc
gp_interconnect_proxy_addresses, although it is sorted, the function uv_getaddrinfo
is asynchronous and can not guarantee the addrs parsed from gp_interconnect_proxy_addresses
are added sequentially to ic_proxy_addrs.
So some addr may be mis-disconnected and lead to select gp_segment_id, pg_reload_conf() from gp_dist_random('gp_id') failed, Error interconnect error: connection closed prematurely
Before reloading the config file. we should sort ic_proxy_addrs by dbid to avoid
mis-disconnecting of addrs.
---
contrib/interconnect/proxy/ic_proxy_addr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/contrib/interconnect/proxy/ic_proxy_addr.c b/contrib/interconnect/proxy/ic_proxy_addr.c
index edc5dd4cfa..b47f533936 100644
--- a/contrib/interconnect/proxy/ic_proxy_addr.c
+++ b/contrib/interconnect/proxy/ic_proxy_addr.c
@@ -234,6 +234,11 @@ ic_proxy_reload_addresses(uv_loop_t *loop)
* of the addresses.
*/
ic_proxy_prev_addrs = ic_proxy_list_free_deep(ic_proxy_prev_addrs);
+ /*
+ * before reloading the config file. we should sort ic_proxy_addrs by dbid to
+ * avoid mis-disconnecting of addrs.
+ */
+ list_sort(ic_proxy_addrs, ic_proxy_addr_compare_dbid);
ic_proxy_prev_addrs = ic_proxy_addrs;
ic_proxy_addrs = NULL;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 30/41: Fix makefile to remove tablespace-step target all
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 680a0197b3c61b81aa67f7e785930c4a7cbb44fc
Author: Junwang Zhao <zh...@gmail.com>
AuthorDate: Tue Jul 19 12:47:05 2022 +0800
Fix makefile to remove tablespace-step target all
Fixes https://github.com/greenplum-db/gpdb/issues/13819 and also aligns with upstream
Don't need to setup the tablespace when calling `make` or `make
install`, it should be setup only for the right target like `check` or
`check-tests`.
---
src/test/regress/GNUmakefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index a45ca4f164..43ef46519f 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -134,7 +134,7 @@ installdirs-tests: installdirs
# Get some extra C modules from contrib/spi
-all: refint$(DLSUFFIX) autoinc$(DLSUFFIX) tablespace-setup hooktest query_info_hook_test
+all: refint$(DLSUFFIX) autoinc$(DLSUFFIX) hooktest query_info_hook_test
refint$(DLSUFFIX): $(top_builddir)/contrib/spi/refint$(DLSUFFIX)
cp $< $@
@@ -201,10 +201,10 @@ check-tests: all | temp-install
# $(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/serial_schedule $(EXTRA_TESTS)
installcheck: installcheck-good
-installcheck-small: all
+installcheck-small: all tablespace-setup
$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(EXTRA_TESTS)
-installcheck-good: all twophase_pqexecparams hooktest query_info_hook_test
+installcheck-good: all tablespace-setup twophase_pqexecparams hooktest query_info_hook_test
$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule --schedule=$(srcdir)/greenplum_schedule $(EXTRA_TESTS)
installcheck-parallel: all
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 16/41: Rename UpdateSerializableCommandId() to UpdateCommandIdInSnapshot()
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 495309595a57fb724728cc5a0516d1627afb5c4d
Author: Adam Lee <ad...@vmware.com>
AuthorDate: Wed Oct 19 16:34:25 2022 +0800
Rename UpdateSerializableCommandId() to UpdateCommandIdInSnapshot()
The name of UpdateSerializableCommandId is a bit wrong, now that SERIALIZABLE
and REPEATABLE READ are not the same. From comparison, the if-check above was
changed from checking IsXactIsoLevelSerializable to IsolationUsesXactSnapshot().
This commit renames it and resolves that GPDB_91_MERGE_FIXME.
commit 5eb15c9942a9bd6aaf712f2ab6175005e035168a
Author: Joe Conway <ma...@joeconway.com>
Date: Sat Sep 11 18:38:58 2010 +0000
SERIALIZABLE transactions are actually implemented beneath the covers with
transaction snapshots, i.e. a snapshot registered at the beginning of
a transaction. Change variable naming and comments to reflect this reality
in preparation for a future, truly serializable mode, e.g.
Serializable Snapshot Isolation (SSI).
For the moment transaction snapshots are still used to implement
SERIALIZABLE, but hopefully not for too much longer. Patch by Kevin
Grittner and Dan Ports with review and some minor wording changes by me.
---
src/backend/storage/ipc/procarray.c | 3 +--
src/backend/utils/time/snapmgr.c | 6 +-----
src/include/storage/procarray.h | 2 +-
3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 25a66171a3..c872907a46 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -4019,10 +4019,9 @@ HaveVirtualXIDsDelayingChkptGuts(VirtualTransactionId *vxids, int nvxids,
/*
* MPP: Special code to update the command id in the SharedLocalSnapshot
- * when we are in SERIALIZABLE isolation mode.
*/
void
-UpdateSerializableCommandId(CommandId curcid)
+UpdateCommandIdInSnapshot(CommandId curcid)
{
if ((DistributedTransactionContext == DTX_CONTEXT_QE_TWO_PHASE_EXPLICIT_WRITER ||
DistributedTransactionContext == DTX_CONTEXT_QE_TWO_PHASE_IMPLICIT_WRITER) &&
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index ddf2194eea..c51a60a029 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -335,11 +335,7 @@ GetTransactionSnapshot(void)
getDistributedTransactionId(),
DtxContextToString(DistributedTransactionContext));
- // GPDB_91_MERGE_FIXME: the name of UpdateSerializableCommandId is a bit
- // wrong, now that SERIALIZABLE and REPEATABLE READ are not the same.
- // From comparison, the if-check above was changed from checking
- // IsXactIsoLevelSerializable to IsolationUsesXactSnapshot()
- UpdateSerializableCommandId(CurrentSnapshot->curcid);
+ UpdateCommandIdInSnapshot(CurrentSnapshot->curcid);
return CurrentSnapshot;
}
diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h
index 8f58ea62c8..c3fe54f4d7 100644
--- a/src/include/storage/procarray.h
+++ b/src/include/storage/procarray.h
@@ -101,7 +101,7 @@ extern void XidCacheRemoveRunningXids(TransactionId xid,
TransactionId latestXid);
extern PGPROC *FindProcByGpSessionId(long gp_session_id);
-extern void UpdateSerializableCommandId(CommandId curcid);
+extern void UpdateCommandIdInSnapshot(CommandId curcid);
extern void updateSharedLocalSnapshot(struct DtxContextInfo *dtxContextInfo,
DtxContext distributedTransactionContext,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 10/41: Tests of VACUUM (SKIP_LOCKED) (#14265)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit a2d8a0ec6bd004c9bc1acefbc023e7d241bc8bd9
Author: Yao Wang <wa...@vmware.com>
AuthorDate: Wed Oct 19 10:41:53 2022 +0800
Tests of VACUUM (SKIP_LOCKED) (#14265)
On PG12 an option SKIP_LOCKED was added to VACUUM and ANALYZE to indicate
whether we need to skip tables when a lock cannot be acquired at the time.
However, relevant tests don't cover all the scenarios on GPDB. This PR is
to add more tests to cover the scenarios.
---
src/test/isolation/expected/vacuum-skip-locked.out | 148 +++++++++++++++++++++
src/test/isolation/specs/vacuum-skip-locked.spec | 66 +++++++--
.../expected/vacuum_skip_locked_onseg.out | 53 ++++++++
src/test/isolation2/isolation2_schedule | 1 +
.../isolation2/sql/vacuum_skip_locked_onseg.sql | 41 ++++++
5 files changed, 295 insertions(+), 14 deletions(-)
diff --git a/src/test/isolation/expected/vacuum-skip-locked.out b/src/test/isolation/expected/vacuum-skip-locked.out
index 20f79649dc..f0aab2a86b 100644
--- a/src/test/isolation/expected/vacuum-skip-locked.out
+++ b/src/test/isolation/expected/vacuum-skip-locked.out
@@ -147,3 +147,151 @@ step vac_full_all_parts: VACUUM (SKIP_LOCKED, FULL) parted;
step commit:
COMMIT;
+
+starting permutation: lock_share_ao vac_specified_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_specified_ao: VACUUM (SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao vac_all_parts_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+step vac_all_parts_ao: VACUUM (SKIP_LOCKED) parted_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao analyze_specified_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+s2: WARNING: skipping analyze of "part1_ao" --- lock not available
+step analyze_specified_ao: ANALYZE (SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao analyze_all_parts_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+step analyze_all_parts_ao: ANALYZE (SKIP_LOCKED) parted_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao vac_analyze_specified_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_analyze_specified_ao: VACUUM (ANALYZE, SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao vac_analyze_all_parts_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+step vac_analyze_all_parts_ao: VACUUM (ANALYZE, SKIP_LOCKED) parted_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao vac_full_specified_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_full_specified_ao: VACUUM (SKIP_LOCKED, FULL) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_share_ao vac_full_all_parts_ao commit
+step lock_share_ao:
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+
+step vac_full_all_parts_ao: VACUUM (SKIP_LOCKED, FULL) parted_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao vac_specified_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_specified_ao: VACUUM (SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao vac_all_parts_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+step vac_all_parts_ao: VACUUM (SKIP_LOCKED) parted_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao analyze_specified_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+s2: WARNING: skipping analyze of "part1_ao" --- lock not available
+step analyze_specified_ao: ANALYZE (SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao vac_analyze_specified_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_analyze_specified_ao: VACUUM (ANALYZE, SKIP_LOCKED) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao vac_full_specified_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+s2: WARNING: skipping vacuum of "part1_ao" --- lock not available
+step vac_full_specified_ao: VACUUM (SKIP_LOCKED, FULL) part1_ao, part2_ao;
+step commit:
+ COMMIT;
+
+
+starting permutation: lock_access_exclusive_ao vac_full_all_parts_ao commit
+step lock_access_exclusive_ao:
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+
+step vac_full_all_parts_ao: VACUUM (SKIP_LOCKED, FULL) parted_ao;
+step commit:
+ COMMIT;
+
diff --git a/src/test/isolation/specs/vacuum-skip-locked.spec b/src/test/isolation/specs/vacuum-skip-locked.spec
index ce49dd44de..9b3ea7bfae 100644
--- a/src/test/isolation/specs/vacuum-skip-locked.spec
+++ b/src/test/isolation/specs/vacuum-skip-locked.spec
@@ -10,11 +10,17 @@ setup
ALTER TABLE part1 SET (autovacuum_enabled = false);
CREATE TABLE part2 PARTITION OF parted FOR VALUES IN (2);
ALTER TABLE part2 SET (autovacuum_enabled = false);
+
+ CREATE TABLE parted_ao (a INT) using ao_column
+ distributed by (a) PARTITION BY LIST (a);
+ CREATE TABLE part1_ao PARTITION OF parted_ao FOR VALUES IN (1);
+ CREATE TABLE part2_ao PARTITION OF parted_ao FOR VALUES IN (2);
}
teardown
{
DROP TABLE IF EXISTS parted;
+ DROP TABLE IF EXISTS parted_ao;
}
session s1
@@ -32,16 +38,34 @@ step commit
{
COMMIT;
}
+step "lock_share_ao"
+{
+ BEGIN;
+ LOCK part1_ao IN SHARE MODE;
+}
+step "lock_access_exclusive_ao"
+{
+ BEGIN;
+ LOCK part1_ao IN ACCESS EXCLUSIVE MODE;
+}
-session s2
-step vac_specified { VACUUM (SKIP_LOCKED) part1, part2; }
-step vac_all_parts { VACUUM (SKIP_LOCKED) parted; }
-step analyze_specified { ANALYZE (SKIP_LOCKED) part1, part2; }
-step analyze_all_parts { ANALYZE (SKIP_LOCKED) parted; }
-step vac_analyze_specified { VACUUM (ANALYZE, SKIP_LOCKED) part1, part2; }
-step vac_analyze_all_parts { VACUUM (ANALYZE, SKIP_LOCKED) parted; }
-step vac_full_specified { VACUUM (SKIP_LOCKED, FULL) part1, part2; }
-step vac_full_all_parts { VACUUM (SKIP_LOCKED, FULL) parted; }
+session "s2"
+step "vac_specified" { VACUUM (SKIP_LOCKED) part1, part2; }
+step "vac_all_parts" { VACUUM (SKIP_LOCKED) parted; }
+step "analyze_specified" { ANALYZE (SKIP_LOCKED) part1, part2; }
+step "analyze_all_parts" { ANALYZE (SKIP_LOCKED) parted; }
+step "vac_analyze_specified" { VACUUM (ANALYZE, SKIP_LOCKED) part1, part2; }
+step "vac_analyze_all_parts" { VACUUM (ANALYZE, SKIP_LOCKED) parted; }
+step "vac_full_specified" { VACUUM (SKIP_LOCKED, FULL) part1, part2; }
+step "vac_full_all_parts" { VACUUM (SKIP_LOCKED, FULL) parted; }
+step "vac_specified_ao" { VACUUM (SKIP_LOCKED) part1_ao, part2_ao; }
+step "vac_all_parts_ao" { VACUUM (SKIP_LOCKED) parted_ao; }
+step "analyze_specified_ao" { ANALYZE (SKIP_LOCKED) part1_ao, part2_ao; }
+step "analyze_all_parts_ao" { ANALYZE (SKIP_LOCKED) parted_ao; }
+step "vac_analyze_specified_ao" { VACUUM (ANALYZE, SKIP_LOCKED) part1_ao, part2_ao; }
+step "vac_analyze_all_parts_ao" { VACUUM (ANALYZE, SKIP_LOCKED) parted_ao; }
+step "vac_full_specified_ao" { VACUUM (SKIP_LOCKED, FULL) part1_ao, part2_ao; }
+step "vac_full_all_parts_ao" { VACUUM (SKIP_LOCKED, FULL) parted_ao; }
permutation lock_share vac_specified commit
permutation lock_share vac_all_parts commit
@@ -59,9 +83,23 @@ permutation lock_access_exclusive analyze_specified commit
# different from upstream. Even in PostgreSQL, the documentation for
# SKIP_LOCKED says that it may still block if it needs to acquire sample
# rows from the partitions.
-#permutation lock_access_exclusive analyze_all_parts commit
-permutation lock_access_exclusive vac_analyze_specified commit
-#permutation lock_access_exclusive vac_analyze_all_parts commit
-permutation lock_access_exclusive vac_full_specified commit
-permutation lock_access_exclusive vac_full_all_parts commit
+#permutation "lock_access_exclusive" "analyze_all_parts" "commit"
+permutation "lock_access_exclusive" "vac_analyze_specified" "commit"
+#permutation "lock_access_exclusive" "vac_analyze_all_parts" "commit"
+permutation "lock_access_exclusive" "vac_full_specified" "commit"
+permutation "lock_access_exclusive" "vac_full_all_parts" "commit"
+permutation "lock_share_ao" "vac_specified_ao" "commit"
+permutation "lock_share_ao" "vac_all_parts_ao" "commit"
+permutation "lock_share_ao" "analyze_specified_ao" "commit"
+permutation "lock_share_ao" "analyze_all_parts_ao" "commit"
+permutation "lock_share_ao" "vac_analyze_specified_ao" "commit"
+permutation "lock_share_ao" "vac_analyze_all_parts_ao" "commit"
+permutation "lock_share_ao" "vac_full_specified_ao" "commit"
+permutation "lock_share_ao" "vac_full_all_parts_ao" "commit"
+permutation "lock_access_exclusive_ao" "vac_specified_ao" "commit"
+permutation "lock_access_exclusive_ao" "vac_all_parts_ao" "commit"
+permutation "lock_access_exclusive_ao" "analyze_specified_ao" "commit"
+permutation "lock_access_exclusive_ao" "vac_analyze_specified_ao" "commit"
+permutation "lock_access_exclusive_ao" "vac_full_specified_ao" "commit"
+permutation "lock_access_exclusive_ao" "vac_full_all_parts_ao" "commit"
diff --git a/src/test/isolation2/expected/vacuum_skip_locked_onseg.out b/src/test/isolation2/expected/vacuum_skip_locked_onseg.out
new file mode 100644
index 0000000000..243f663a27
--- /dev/null
+++ b/src/test/isolation2/expected/vacuum_skip_locked_onseg.out
@@ -0,0 +1,53 @@
+-- Test VACUUM with SKIP_LOCKED
+-- The test focuses on the vacuum behavior when the table is locked
+-- on segments. There is another test vacuum-skip-locked in
+-- isolation dir which focuses on regular test cases (table is locked
+-- on master).
+
+1: CREATE TABLE vacuum_tbl (c1 int) DISTRIBUTED BY (c1);
+CREATE
+
+-- Connect to seg #0 in utility mode, lock the table in share mode
+0U: BEGIN;
+BEGIN
+0U: LOCK vacuum_tbl IN SHARE MODE;
+LOCK
+
+-- Issue vacuum with SKIP_LOCKED option
+-- Note that some ANALYZE options are disabled here because the ANALYZE
+-- try to acquire sample on segments and block. It is acceptable on
+-- GPDB. See the comments in isolation/specs/vacuum-skip-locked.spec.
+
+2: VACUUM (SKIP_LOCKED) vacuum_tbl;
+VACUUM
+--2: ANALYZE (SKIP_LOCKED) vacuum_tbl;
+--2: VACUUM (ANALYZE, SKIP_LOCKED) vacuum_tbl;
+2: VACUUM (SKIP_LOCKED, FULL) vacuum_tbl;
+VACUUM
+
+0U: COMMIT;
+COMMIT
+
+-- Connect to seg #0 in utility mode, lock the table in exclusive mode
+0U: BEGIN;
+BEGIN
+0U: LOCK vacuum_tbl IN ACCESS EXCLUSIVE MODE;
+LOCK
+
+-- Issue vacuum with SKIP_LOCKED option
+-- Note that some ANALYZE options are disabled here because the ANALYZE
+-- try to acquire sample on segments and block. It is acceptable on
+-- GPDB. See the comments in isolation/specs/vacuum-skip-locked.spec.
+
+2: VACUUM (SKIP_LOCKED) vacuum_tbl;
+VACUUM
+--2: ANALYZE (SKIP_LOCKED) vacuum_tbl;
+--2: VACUUM (ANALYZE, SKIP_LOCKED) vacuum_tbl;
+2: VACUUM (SKIP_LOCKED, FULL) vacuum_tbl;
+VACUUM
+
+0U: COMMIT;
+COMMIT
+
+1: DROP TABLE IF EXISTS vacuum_tbl;
+DROP
diff --git a/src/test/isolation2/isolation2_schedule b/src/test/isolation2/isolation2_schedule
index 57e3b76252..594c413835 100644
--- a/src/test/isolation2/isolation2_schedule
+++ b/src/test/isolation2/isolation2_schedule
@@ -6,6 +6,7 @@ test: check_gxid
test: checkpoint_dtx_info
test: autovacuum-analyze
+test: vacuum_skip_locked_onseg
test: lockmodes
# test: pg_rewind_fail_missing_xlog
test: prepared_xact_deadlock_pg_rewind
diff --git a/src/test/isolation2/sql/vacuum_skip_locked_onseg.sql b/src/test/isolation2/sql/vacuum_skip_locked_onseg.sql
new file mode 100644
index 0000000000..3de48f116a
--- /dev/null
+++ b/src/test/isolation2/sql/vacuum_skip_locked_onseg.sql
@@ -0,0 +1,41 @@
+-- Test VACUUM with SKIP_LOCKED
+-- The test focuses on the vacuum behavior when the table is locked
+-- on segments. There is another test vacuum-skip-locked in
+-- isolation dir which focuses on regular test cases (table is locked
+-- on master).
+
+1: CREATE TABLE vacuum_tbl (c1 int) DISTRIBUTED BY (c1);
+
+-- Connect to seg #0 in utility mode, lock the table in share mode
+0U: BEGIN;
+0U: LOCK vacuum_tbl IN SHARE MODE;
+
+-- Issue vacuum with SKIP_LOCKED option
+-- Note that some ANALYZE options are disabled here because the ANALYZE
+-- try to acquire sample on segments and block. It is acceptable on
+-- GPDB. See the comments in isolation/specs/vacuum-skip-locked.spec.
+
+2: VACUUM (SKIP_LOCKED) vacuum_tbl;
+--2: ANALYZE (SKIP_LOCKED) vacuum_tbl;
+--2: VACUUM (ANALYZE, SKIP_LOCKED) vacuum_tbl;
+2: VACUUM (SKIP_LOCKED, FULL) vacuum_tbl;
+
+0U: COMMIT;
+
+-- Connect to seg #0 in utility mode, lock the table in exclusive mode
+0U: BEGIN;
+0U: LOCK vacuum_tbl IN ACCESS EXCLUSIVE MODE;
+
+-- Issue vacuum with SKIP_LOCKED option
+-- Note that some ANALYZE options are disabled here because the ANALYZE
+-- try to acquire sample on segments and block. It is acceptable on
+-- GPDB. See the comments in isolation/specs/vacuum-skip-locked.spec.
+
+2: VACUUM (SKIP_LOCKED) vacuum_tbl;
+--2: ANALYZE (SKIP_LOCKED) vacuum_tbl;
+--2: VACUUM (ANALYZE, SKIP_LOCKED) vacuum_tbl;
+2: VACUUM (SKIP_LOCKED, FULL) vacuum_tbl;
+
+0U: COMMIT;
+
+1: DROP TABLE IF EXISTS vacuum_tbl;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 26/41: fix upgrading external tables with dropped cols
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 2f4bafda0ddccf2c8de2ec3777c0575a3110c209
Author: Kalen Krempely <ka...@gmail.com>
AuthorDate: Mon Oct 24 19:05:23 2022 -0700
fix upgrading external tables with dropped cols
External tables with dropped columns failed to upgrade with:
```
pg_restore: creating EXTERNAL TABLE ext_upgrade_failure_test
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 237; 1259 18142 EXTERNAL TABLE ext_upgrade_failure_test gpadmin
pg_restore: [archiver (db)] could not execute query: ERROR: syntax error at or near ","
LINE 14: "........pg.dropped.1........" ,
^
```
Fix pg_dump to output the ALTER TABLE DROP COLUMN DDL for external
tables with dropped columns.
---
src/bin/pg_dump/pg_dump.c | 15 ++++++++++++++-
src/test/regress/expected/pg_dump_binary_upgrade.out | 18 ++++++++++++++++++
src/test/regress/greenplum_schedule | 2 ++
src/test/regress/sql/pg_dump_binary_upgrade.sql | 20 ++++++++++++++++++++
4 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index bfdf20beab..1b5d41796a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -17720,7 +17720,20 @@ dumpExternal(Archive *fout, const TableInfo *tbinfo, PQExpBuffer q, PQExpBuffer
appendPQExpBuffer(q, "%s ", fmtId(tbinfo->attnames[j]));
/* Attribute type */
- appendPQExpBufferStr(q, tbinfo->atttypnames[j]);
+ if (tbinfo->attisdropped[j])
+ {
+ /*
+ * ALTER TABLE DROP COLUMN clears
+ * pg_attribute.atttypid, so we will not have gotten a
+ * valid type name; insert INTEGER as a stopgap. We'll
+ * clean things up later.
+ */
+ appendPQExpBufferStr(q, " INTEGER /* dummy */");
+ }
+ else
+ {
+ appendPQExpBufferStr(q, tbinfo->atttypnames[j]);
+ }
actual_atts++;
}
diff --git a/src/test/regress/expected/pg_dump_binary_upgrade.out b/src/test/regress/expected/pg_dump_binary_upgrade.out
new file mode 100644
index 0000000000..992a9784ea
--- /dev/null
+++ b/src/test/regress/expected/pg_dump_binary_upgrade.out
@@ -0,0 +1,18 @@
+-- Ensure that pg_dump --binary-upgrade correctly outputs
+-- ALTER TABLE DROP COLUMN DDL for external tables.
+CREATE SCHEMA dump_this_schema;
+-- External tables with dropped columns is dumped correctly.
+CREATE EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns (
+ a int,
+ b int,
+ c int
+) LOCATION ('gpfdist://1.1.1.1:8082/xxxx.csv') FORMAT 'csv';
+ALTER EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns DROP COLUMN a;
+ALTER EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns DROP COLUMN b;
+-- Run pg_dump and expect to see an ALTER TABLE DROP COLUMN output
+-- for the tables with dropped column references.
+\! pg_dump --binary-upgrade --schema dump_this_schema regression | grep " DROP COLUMN "
+ALTER FOREIGN TABLE ONLY dump_this_schema.external_table_with_dropped_columns DROP COLUMN "........pg.dropped.1........";
+ALTER FOREIGN TABLE ONLY dump_this_schema.external_table_with_dropped_columns DROP COLUMN "........pg.dropped.2........";
+DROP SCHEMA dump_this_schema CASCADE;
+NOTICE: drop cascades to foreign table dump_this_schema.external_table_with_dropped_columns
diff --git a/src/test/regress/greenplum_schedule b/src/test/regress/greenplum_schedule
index 8f83c38787..58d65b4cb1 100755
--- a/src/test/regress/greenplum_schedule
+++ b/src/test/regress/greenplum_schedule
@@ -18,6 +18,8 @@
# test for builtin namespace pg_ext_aux
test: pg_ext_aux
+test: pg_dump_binary_upgrade
+
test: gp_dispatch_keepalives
# copy command
diff --git a/src/test/regress/sql/pg_dump_binary_upgrade.sql b/src/test/regress/sql/pg_dump_binary_upgrade.sql
new file mode 100644
index 0000000000..70291e049c
--- /dev/null
+++ b/src/test/regress/sql/pg_dump_binary_upgrade.sql
@@ -0,0 +1,20 @@
+-- Ensure that pg_dump --binary-upgrade correctly outputs
+-- ALTER TABLE DROP COLUMN DDL for external tables.
+
+CREATE SCHEMA dump_this_schema;
+
+-- External tables with dropped columns is dumped correctly.
+CREATE EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns (
+ a int,
+ b int,
+ c int
+) LOCATION ('gpfdist://1.1.1.1:8082/xxxx.csv') FORMAT 'csv';
+
+ALTER EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns DROP COLUMN a;
+ALTER EXTERNAL TABLE dump_this_schema.external_table_with_dropped_columns DROP COLUMN b;
+
+-- Run pg_dump and expect to see an ALTER TABLE DROP COLUMN output
+-- for the tables with dropped column references.
+\! pg_dump --binary-upgrade --schema dump_this_schema regression | grep " DROP COLUMN "
+
+DROP SCHEMA dump_this_schema CASCADE;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 24/41: fix gp_gettmid to return correct startup timestamp. (#14204)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 33e08725fb447dae7309af5d1b34e0a75c6badc0
Author: Violet Cheng <vc...@pivotal.io>
AuthorDate: Mon Oct 31 07:04:54 2022 +0800
fix gp_gettmid to return correct startup timestamp. (#14204)
Previously, gp_gettmid() returns PgStartTime as the start time of gpdb ("tmid") and saves it into instrument shared memory, but the value is wrong after converting to `TimestampTz` (which is int64). Since the value is saved in the shared memory, plus GPCC has been using 32-bit integer for tmid, adapting to int64 will require a lot of change in both GPDB's and GPCC's coed. Therefore, in this commit, gp_gettmid() converts PgStartTime to a correct int32 value instead.
Co-authored-by: Violet Cheng <vc...@vmware.com>
---
src/backend/executor/instrument.c | 24 ++++++++++-
src/backend/executor/test/Makefile | 12 ++++++
src/backend/executor/test/instrument_test.c | 64 +++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 1 deletion(-)
diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c
index efac4315eb..ea879180e6 100644
--- a/src/backend/executor/instrument.c
+++ b/src/backend/executor/instrument.c
@@ -536,9 +536,31 @@ instrShmemRecycleCallback(ResourceReleasePhase phase, bool isCommit, bool isTopL
SpinLockRelease(&InstrumentGlobal->lock);
}
+/*
+ * Cast PgStartTime from TimestampTz to int32. Separated from gp_gettmid() to avoid elog() in
+ * gp_gettmid() to cause panic when running unit tests.
+ * Return -1 for invalid PgStartTime or overflow values.
+ */
+static int32 gp_gettmid_helper()
+{
+ pg_time_t time;
+ if (PgStartTime < 0)
+ return -1;
+ time = timestamptz_to_time_t(PgStartTime);
+ if (time > INT32_MAX)
+ return -1;
+ return (int32)time;
+}
+
+/*
+ * Wrapper for gp_gettmid_helper()
+ */
static void gp_gettmid(int32* tmid)
{
- *tmid = (int32) PgStartTime;
+ int32 time = gp_gettmid_helper();
+ if (time == -1)
+ elog(PANIC, "time_t converted from PgStartTime is too large");
+ *tmid = time;
}
/* helper functions for WAL usage accumulation */
diff --git a/src/backend/executor/test/Makefile b/src/backend/executor/test/Makefile
new file mode 100644
index 0000000000..b8480f4c17
--- /dev/null
+++ b/src/backend/executor/test/Makefile
@@ -0,0 +1,12 @@
+subdir=src/backend/executor
+top_builddir=../../../..
+include $(top_builddir)/src/Makefile.global
+
+TARGETS= instrument
+
+include $(top_srcdir)/src/backend/mock.mk
+
+instrument.t: $(MOCK_DIR)/backend/access/transam/distributedlog_mock.o \
+ $(MOCK_DIR)/backend/access/hash/hash_mock.o \
+ $(MOCK_DIR)/backend/utils/fmgr/fmgr_mock.o
+
diff --git a/src/backend/executor/test/instrument_test.c b/src/backend/executor/test/instrument_test.c
new file mode 100644
index 0000000000..282824b8dd
--- /dev/null
+++ b/src/backend/executor/test/instrument_test.c
@@ -0,0 +1,64 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include "cmockery.h"
+
+#include "postgres.h"
+#include "utils/memutils.h"
+
+#include "../instrument.c"
+
+#define SIZE_OF_IN_PROGRESS_ARRAY (10 * sizeof(DistributedTransactionId))
+
+static void
+test__GetTmid_Test(void **state)
+{
+ assert_true(sizeof(pg_time_t) > sizeof(int32));
+ /*
+ * For very large PgStartTime values, result from timestamptz_to_time_t either overflows or equals to -1,
+ * and should not match the value casted to int32 from gp_gettmid_helper()
+ */
+ TimestampTz delta = 0x4000000000000000 >> 14;
+ for (TimestampTz time = 0x7FFFFFFFFFFFFFFF - delta; time > 0x3fffffffffffffff; time -= delta) {
+ PgStartTime = time;
+ int32 tmid = gp_gettmid_helper();
+ pg_time_t res = timestamptz_to_time_t(PgStartTime);
+ assert_false((int64)tmid - res == 0);
+ }
+ /*
+ * For smaller PgStartTime values, the result from timestamptz_to_time_t casted to int32
+ * should match the result from gp_gettmid_helper()
+ */
+ delta /= 4;
+ for (TimestampTz time = 0x3ffffffffffff - delta; time >= 0; time -= delta) {
+ PgStartTime = time;
+ int32 tmid = gp_gettmid_helper();
+ pg_time_t res = timestamptz_to_time_t(PgStartTime);
+ assert_true((int64)tmid - res == 0);
+ }
+
+ /* gp_gettmid_helper should return -1 for negative PgStartTime */
+ PgStartTime = -100;
+ int32 tmid = gp_gettmid_helper();
+ assert_true(tmid == -1);
+
+ /* gp_gettmid_helper should return -1 for very large PgStartTime value */
+ PgStartTime = 0x7FFFFFFFFFFFFFFF - delta;
+ tmid = gp_gettmid_helper();
+ assert_true(tmid == -1);
+}
+
+int
+main(int argc, char* argv[])
+{
+ cmockery_parse_arguments(argc, argv);
+
+ const UnitTest tests[] =
+ {
+ unit_test(test__GetTmid_Test)
+ };
+
+ MemoryContextInit();
+
+ return run_tests(tests);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 05/41: Fix: Ensure Smgr Relation is Opened Before Accessing AO Segment Files
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 765c9ed7ebac77d8949be78f106570c4bf76e85b
Author: yjhjstz <yj...@gmail.com>
AuthorDate: Thu Dec 26 09:18:12 2024 +0800
Fix: Ensure Smgr Relation is Opened Before Accessing AO Segment Files
This commit adds calls to `RelationOpenSmgr()` in `open_all_datumstreamread_segfiles()` and `openFetchSegmentFile()` to ensure that the storage manager (Smgr) relation is opened before accessing Append-Optimized (AO) segment files.
Without explicitly opening the Smgr relation, accessing `rel->rd_smgr->smgr_ao` could lead to undefined behavior or errors when the Smgr is not initialized. This change ensures stability and correctness when working with AO segment files.
---
src/backend/access/aocs/aocsam.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/backend/access/aocs/aocsam.c b/src/backend/access/aocs/aocsam.c
index 1f115295fb..4b9741bf51 100644
--- a/src/backend/access/aocs/aocsam.c
+++ b/src/backend/access/aocs/aocsam.c
@@ -120,6 +120,7 @@ open_all_datumstreamread_segfiles(AOCSScanDesc scan, AOCSFileSegInfo *segInfo)
{
AttrNumber attno = proj_atts[i];
+ RelationOpenSmgr(rel);
open_datumstreamread_segfile(basepath, rel->rd_smgr->smgr_ao, rel->rd_node, segInfo, ds[attno], attno);
datumstreamread_block(ds[attno], blockDirectory, attno);
@@ -1419,6 +1420,7 @@ openFetchSegmentFile(AOCSFetchDesc aocsFetchDesc,
if (logicalEof == 0)
return false;
+ RelationOpenSmgr(aocsFetchDesc->relation);
open_datumstreamread_segfile(aocsFetchDesc->basepath, aocsFetchDesc->relation->rd_smgr->smgr_ao, aocsFetchDesc->relation->rd_node,
fsInfo,
datumStreamFetchDesc->datumStream,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 41/41: Fix test cases of cherry-pick.
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 4bd2d57baa90aec88c1da062b912e7c760271d2c
Author: Jianghua Yang <yj...@gmail.com>
AuthorDate: Tue Dec 31 15:30:37 2024 +0800
Fix test cases of cherry-pick.
---
src/test/regress/GNUmakefile | 2 +-
src/test/regress/expected/rpt_optimizer.out | 21 ++++----
.../regress/expected/subselect_gp_optimizer.out | 57 ++++++++++++----------
3 files changed, 44 insertions(+), 36 deletions(-)
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index 43ef46519f..83d1dc76aa 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -211,7 +211,7 @@ installcheck-parallel: all
$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(MAXCONNOPT) $(EXTRA_TESTS)
# cbdb parallel plan tests, ignore the incompatible cases, should run with 5 GUCs like below:
-installcheck-cbdb-parallel: all twophase_pqexecparams
+installcheck-cbdb-parallel: all tablespace-setup twophase_pqexecparams
( \
export PGOPTIONS='-c optimizer=off -c enable_parallel=true -c min_parallel_table_scan_size=0 -c min_parallel_index_scan_size=0 -c force_parallel_mode=1'; \
$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule --schedule=$(srcdir)/greenplum_schedule $(MAXCONNOPT) $(EXTRA_TESTS) --exclude-tests explain \
diff --git a/src/test/regress/expected/rpt_optimizer.out b/src/test/regress/expected/rpt_optimizer.out
index 5585b29b56..62a9fe489a 100644
--- a/src/test/regress/expected/rpt_optimizer.out
+++ b/src/test/regress/expected/rpt_optimizer.out
@@ -1092,17 +1092,20 @@ set optimizer_enable_hashjoin=off;
set enable_hashjoin=off;
set enable_nestloop=on;
explain select b from dist_tab where b in (select distinct c from rep_tab);
- QUERY PLAN
-------------------------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.15..10000000021.42 rows=4 width=4)
- -> Nested Loop (cost=10000000001.15..10000000021.36 rows=1 width=4)
- -> HashAggregate (cost=10000000001.02..10000000001.03 rows=2 width=4)
+ QUERY PLAN
+---------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..443.00 rows=4 width=4)
+ -> Nested Loop (cost=0.00..443.00 rows=2 width=4)
+ Join Filter: true
+ -> GroupAggregate (cost=0.00..431.00 rows=2 width=4)
Group Key: rep_tab.c
- -> Seq Scan on rep_tab (cost=10000000000.00..10000000001.02 rows=2 width=4)
- -> Index Only Scan using idx on dist_tab (cost=0.13..10.16 rows=1 width=4)
+ -> Sort (cost=0.00..431.00 rows=2 width=4)
+ Sort Key: rep_tab.c
+ -> Seq Scan on rep_tab (cost=0.00..431.00 rows=2 width=4)
+ -> Index Scan using idx on dist_tab (cost=0.00..12.00 rows=1 width=4)
Index Cond: (b = rep_tab.c)
- Optimizer: Postgres query optimizer
-(8 rows)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(11 rows)
select b from dist_tab where b in (select distinct c from rep_tab);
b
diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out
index a8bca6365f..4c1a9bae45 100644
--- a/src/test/regress/expected/subselect_gp_optimizer.out
+++ b/src/test/regress/expected/subselect_gp_optimizer.out
@@ -1775,22 +1775,27 @@ EXPLAIN select count(distinct ss.ten) from
EXPLAIN select count(*) from
(select 1 from tenk1 a
where unique1 IN (select distinct hundred from tenk1 b)) ss;
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
- Finalize Aggregate (cost=210.51..210.52 rows=1 width=8)
- -> Gather Motion 3:1 (slice1; segments: 3) (cost=210.45..210.50 rows=3 width=8)
- -> Partial Aggregate (cost=210.45..210.46 rows=1 width=8)
- -> Hash Join (cost=138.92..210.37 rows=33 width=0)
- Hash Cond: (a.unique1 = b.hundred)
- -> Seq Scan on tenk1 a (cost=0.00..62.33 rows=3333 width=4)
- -> Hash (cost=137.67..137.67 rows=100 width=4)
- -> HashAggregate (cost=137.33..137.67 rows=100 width=4)
- Group Key: b.hundred
- -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..129.00 rows=3333 width=4)
- Hash Key: b.hundred
- -> Seq Scan on tenk1 b (cost=0.00..62.33 rows=3333 width=4)
- Optimizer: Postgres query optimizer
-(13 rows)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------
+ Finalize Aggregate (cost=0.00..431.99 rows=1 width=8)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.99 rows=1 width=8)
+ -> Partial Aggregate (cost=0.00..431.99 rows=1 width=8)
+ -> Nested Loop (cost=0.00..431.99 rows=34 width=1)
+ Join Filter: true
+ -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.95 rows=100 width=4)
+ -> GroupAggregate (cost=0.00..431.94 rows=34 width=4)
+ Group Key: tenk1.hundred
+ -> Sort (cost=0.00..431.94 rows=34 width=4)
+ Sort Key: tenk1.hundred
+ -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..431.94 rows=34 width=4)
+ Hash Key: tenk1.hundred
+ -> Streaming HashAggregate (cost=0.00..431.94 rows=34 width=4)
+ Group Key: tenk1.hundred
+ -> Seq Scan on tenk1 (cost=0.00..431.51 rows=3334 width=4)
+ -> Index Only Scan using tenk1_unique1 on tenk1 tenk1_1 (cost=0.00..0.04 rows=1 width=1)
+ Index Cond: (unique1 = tenk1.hundred)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(18 rows)
EXPLAIN select count(distinct ss.ten) from
(select ten from tenk1 a
@@ -1815,7 +1820,7 @@ EXPLAIN select count(distinct ss.ten) from
-> Streaming HashAggregate (cost=0.00..431.94 rows=34 width=4)
Group Key: tenk1_1.hundred
-> Seq Scan on tenk1 tenk1_1 (cost=0.00..431.51 rows=3334 width=4)
- Optimizer: Pivotal Optimizer (GPORCA) version 3.64.0
+ Optimizer: Pivotal Optimizer (GPORCA)
(19 rows)
--
@@ -1827,18 +1832,18 @@ EXPLAIN select count(distinct ss.ten) from
EXPLAIN SELECT EXISTS(SELECT * FROM tenk1 WHERE tenk1.unique1 = tenk2.unique1) FROM tenk2 LIMIT 1;
QUERY PLAN
----------------------------------------------------------------------------------------------
- Limit (cost=0.00..865.43 rows=1 width=1)
- -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..865.43 rows=1 width=1)
- -> Limit (cost=0.00..865.43 rows=1 width=1)
- -> Hash Left Join (cost=0.00..865.40 rows=3334 width=8)
+ Limit (cost=0.00..865.45 rows=1 width=1)
+ -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..865.45 rows=1 width=1)
+ -> Limit (cost=0.00..865.45 rows=1 width=1)
+ -> Hash Left Join (cost=0.00..865.42 rows=3334 width=8)
Hash Cond: (tenk2.unique1 = tenk1.unique1)
- -> Seq Scan on tenk2 (cost=0.00..431.50 rows=3334 width=4)
- -> Hash (cost=431.95..431.95 rows=3334 width=12)
- -> HashAggregate (cost=0.00..431.95 rows=3334 width=12)
+ -> Seq Scan on tenk2 (cost=0.00..431.51 rows=3334 width=4)
+ -> Hash (cost=431.96..431.96 rows=3334 width=12)
+ -> HashAggregate (cost=0.00..431.96 rows=3334 width=12)
Group Key: tenk1.unique1
- -> Seq Scan on tenk1 (cost=0.00..431.50 rows=3334 width=4)
+ -> Seq Scan on tenk1 (cost=0.00..431.51 rows=3334 width=4)
Optimizer: Pivotal Optimizer (GPORCA)
-(19 rows)
+(11 rows)
SELECT EXISTS(SELECT * FROM tenk1 WHERE tenk1.unique1 = tenk2.unique1) FROM tenk2 LIMIT 1;
exists
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 28/41: ao/co: Remove FIXME for DML state mechanism
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 74c48c597d9c5061726707dd444b813f9c97ae4d
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Sun Oct 30 15:00:33 2022 -0700
ao/co: Remove FIXME for DML state mechanism
The backend local hash table mechanism works well enough for storing
DML/DML-like command-bound state. Lift the FIXME that questions its
applicability.
Discussion: https://groups.google.com/a/greenplum.org/g/gpdb-dev/c/g_RG4r_9W3s/m/VJNafJibEQAJ
---
src/backend/access/aocs/aocsam_handler.c | 16 ++++++----------
src/backend/access/appendonly/appendonlyam_handler.c | 15 +++++----------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c
index 0fc06c4ad9..7dbdb37756 100644
--- a/src/backend/access/aocs/aocsam_handler.c
+++ b/src/backend/access/aocs/aocsam_handler.c
@@ -88,6 +88,9 @@ typedef struct AOCSBitmapScanData
int rs_cindex; /* current tuple's index tbmres->offset or -1 */
} *AOCSBitmapScan;
+/*
+ * Per-relation backend-local DML state for DML or DML-like operations.
+ */
typedef struct AOCODMLState
{
Oid relationOid;
@@ -107,17 +110,10 @@ typedef struct AOCODMLState
} AOCODMLState;
static void reset_state_cb(void *arg);
+
/*
- * GPDB_12_MERGE_FIXME: This is a temporary state of things. A locally stored
- * state is needed currently because there is no viable place to store this
- * information outside of the table access method. Ideally the caller should be
- * responsible for initializing a state and passing it over using the table
- * access method api.
- *
- * Until this is in place, the local state is not to be accessed directly but
- * only via the *_dml_state functions.
- * It contains:
- * a quick look up member for the common case
+ * A repository for per-relation backend-local DML states. Contains:
+ * a quick look up member for the common case (only 1 relation)
* a hash table which keeps per relation information
* a memory context that should be long lived enough and is
* responsible for reseting the state via its reset cb
diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c
index 2151ade951..6f4941447c 100644
--- a/src/backend/access/appendonly/appendonlyam_handler.c
+++ b/src/backend/access/appendonly/appendonlyam_handler.c
@@ -57,6 +57,9 @@ static void reset_state_cb(void *arg);
static const TableAmRoutine ao_row_methods;
+/*
+ * Per-relation backend-local DML state for DML or DML-like operations.
+ */
typedef struct AppendOnlyDMLState
{
Oid relationOid;
@@ -78,16 +81,8 @@ typedef struct AppendOnlyDMLState
/*
- * GPDB_12_MERGE_FIXME: This is a temporary state of things. A locally stored
- * state is needed currently because there is no viable place to store this
- * information outside of the table access method. Ideally the caller should be
- * responsible for initializing a state and passing it over using the table
- * access method api.
- *
- * Until this is in place, the local state is not to be accessed directly but
- * only via the *_dml_state functions.
- * It contains:
- * a quick look up member for the common case
+ * A repository for per-relation backend-local DML states. Contains:
+ * a quick look up member for the common case (only 1 relation)
* a hash table which keeps per relation information
* a memory context that should be long lived enough and is
* responsible for reseting the state via its reset cb
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 06/41: pg_upgrade: Resolve FIXME for spclocation column
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit f819916fea1f5fbeafaed51e3c688039d0dcb438
Author: Brent Doil <bd...@vmware.com>
AuthorDate: Thu Sep 8 15:57:07 2022 -0400
pg_upgrade: Resolve FIXME for spclocation column
For GPDB5 pg_tablespace.spclocation is used
For GPDB6+ pg_catalog.pg_tablespace_location(oid) is used
Authored-by: Brent Doil <bd...@vmware.com>
---
src/bin/pg_upgrade/info.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c
index e1c1a778f4..fe04b4d354 100644
--- a/src/bin/pg_upgrade/info.c
+++ b/src/bin/pg_upgrade/info.c
@@ -396,7 +396,6 @@ get_db_infos(ClusterInfo *cluster)
/* we don't preserve pg_database.oid so we sort by name */
"ORDER BY 2",
/* 9.2 removed the spclocation column */
- /* GPDB_XX_MERGE_FIXME: spclocation was removed in 6.0 cycle */
(GET_MAJOR_VERSION(cluster->major_version) <= 803) ?
"t.spclocation" : "pg_catalog.pg_tablespace_location(t.oid)");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 09/41: fix crash on get_ao_compression_ratio of heap table (#14205)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit bb5d05287fa82f5b9e7a90e27ccaf634eea202ab
Author: Haotian Chen <10...@users.noreply.github.com>
AuthorDate: Wed Oct 12 17:49:11 2022 +0800
fix crash on get_ao_compression_ratio of heap table (#14205)
Co-authored-by: CharlieTT <ch...@vmware.com>
Fix crash of PG_TRY which caused by return branch in PG_TRY block. When we return value in PG_TRY, some
setjump/longjump context has been messed up so that we cannot longjump to right address once ereport(ERROR)
exists later, so crash will happen.
---
src/backend/access/appendonly/aosegfiles.c | 14 +++++++++-----
src/test/regress/expected/AORO_Compression.out | 12 ++++++++++++
src/test/regress/sql/AORO_Compression.sql | 11 +++++++++++
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/backend/access/appendonly/aosegfiles.c b/src/backend/access/appendonly/aosegfiles.c
index 1eb78db3f2..4c21354b36 100644
--- a/src/backend/access/appendonly/aosegfiles.c
+++ b/src/backend/access/appendonly/aosegfiles.c
@@ -1624,12 +1624,10 @@ aorow_compression_ratio_internal(Relation parentrel)
if (NULL == attr1 || NULL == attr2)
{
- SPI_finish();
- return 1;
+ compress_ratio = 1;
}
-
- if (scanint8(attr1, true, &eof) &&
- scanint8(attr2, true, &eof_uncomp))
+ else if (scanint8(attr1, true, &eof) &&
+ scanint8(attr2, true, &eof_uncomp))
{
/* guard against division by zero */
if (eof > 0)
@@ -1641,6 +1639,12 @@ aorow_compression_ratio_internal(Relation parentrel)
compress_ratio = round(compress_ratio * 100.0) / 100.0;
}
}
+ else
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_INTERNAL_ERROR),
+ errmsg("unable to parse aorow compress_ratio string to int8.")));
+ }
}
connected = false;
diff --git a/src/test/regress/expected/AORO_Compression.out b/src/test/regress/expected/AORO_Compression.out
index 3ed0de2e84..25e4861d60 100644
--- a/src/test/regress/expected/AORO_Compression.out
+++ b/src/test/regress/expected/AORO_Compression.out
@@ -25,3 +25,15 @@ CREATE TABLE a_aoro_table_with_rle_type_compression(col int) WITH (APPENDONLY=tr
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'col' as the Cloudberry 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.
ERROR: rle_type cannot be used with Append Only relations row orientation
+-- Test get_ao_compression_ratio
+CREATE TABLE test_table (date date)
+PARTITION BY RANGE(date)
+(
+PARTITION test_cmp_02 START ('2022-02-01'::date) END ('2022-03-01'::date) EVERY ('1 mon'::interval) WITH (tablename='test_table_1_prt_cmp_202202', appendonly='true', orientation='row', compresstype=zlib),
+START ('2022-03-01'::date) END ('2022-04-01'::date) EVERY ('1 mon'::interval) WITH (tablename='test_table_1_prt_123', appendonly='false')
+);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'date' 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.
+select get_ao_compression_ratio('test_table_1_prt_123');
+ERROR: 'test_table_1_prt_123' is not an append-only relation
+drop table test_table;
diff --git a/src/test/regress/sql/AORO_Compression.sql b/src/test/regress/sql/AORO_Compression.sql
index 06d350c6cd..d0ac30d748 100644
--- a/src/test/regress/sql/AORO_Compression.sql
+++ b/src/test/regress/sql/AORO_Compression.sql
@@ -11,3 +11,14 @@ SELECT pg_size_pretty(pg_relation_size('a_aoro_table_with_zlib_compression')),
-- Test basic create table for AO/RO table fails for rle compression. rle is only supported for columnar tables.
CREATE TABLE a_aoro_table_with_rle_type_compression(col int) WITH (APPENDONLY=true, COMPRESSTYPE=rle_type, COMPRESSLEVEL=1, ORIENTATION=row);
+
+-- Test get_ao_compression_ratio
+CREATE TABLE test_table (date date)
+PARTITION BY RANGE(date)
+(
+PARTITION test_cmp_02 START ('2022-02-01'::date) END ('2022-03-01'::date) EVERY ('1 mon'::interval) WITH (tablename='test_table_1_prt_cmp_202202', appendonly='true', orientation='row', compresstype=zlib),
+START ('2022-03-01'::date) END ('2022-04-01'::date) EVERY ('1 mon'::interval) WITH (tablename='test_table_1_prt_123', appendonly='false')
+);
+
+select get_ao_compression_ratio('test_table_1_prt_123');
+drop table test_table;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 34/41: Check with assert if AO table's toast table kept existing relfrozenxid unchanged. (#13499)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit f770fbb757c0714333812e975f88e51158d2ea35
Author: Aegeaner <gj...@vmware.com>
AuthorDate: Tue Nov 15 10:25:00 2022 +0800
Check with assert if AO table's toast table kept existing relfrozenxid unchanged. (#13499)
CLUSTER operation on append-optimized tables does not compute freeze limit
(frozenXid) because AO tables do not have relfrozenxid. The toast tables
need to keep existing relfrozenxid value unchanged in this case.
---
src/backend/commands/cluster.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 0517912ffd..bdb03c7691 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -1393,20 +1393,6 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
if (relform1->reltoastrelid && relform2->reltoastrelid)
{
/* Recursively swap the contents of the toast tables */
-#ifdef USE_ASSERT_CHECKING
- /*
- * CLUSTER operation on append-optimized tables does not
- * compute freeze limit (frozenXid) because AO tables do not
- * have relfrozenxid. The toast tables need to keep existing
- * relfrozenxid value unchanged in this case.
- *
- * assert, if the frozenXid is invalid, it must be AO table.
- */
- bool isAO1 = (relform1->relam == AO_ROW_TABLE_AM_OID);
- bool isAO2 = (relform2->relam == AO_ROW_TABLE_AM_OID);
- if (!TransactionIdIsNormal(frozenXid))
- Assert(isAO1 && isAO2);
-#endif
swap_relation_files(relform1->reltoastrelid,
relform2->reltoastrelid,
target_is_pg_class,
@@ -1453,6 +1439,24 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
}
}
+#ifdef USE_ASSERT_CHECKING
+ /*
+ * Check with assert if AO table's toast table kept existing relfrozenxid unchanged.
+ *
+ * CLUSTER operation on append-optimized tables does not
+ * compute freeze limit (frozenXid) because AO tables do not
+ * have relfrozenxid. The toast tables need to keep existing
+ * relfrozenxid value unchanged in this case.
+ */
+ if (swap_toast_by_content
+ && frozenXid == InvalidTransactionId
+ && relform1->relkind == RELKIND_TOASTVALUE
+ && relform2->relkind == RELKIND_TOASTVALUE)
+ {
+ Assert(relform1->relfrozenxid == relform2->relfrozenxid);
+ }
+#endif
+
/*
* If we're swapping two toast tables by content, do the same for their
* valid index. The swap can actually be safely done only if the relations
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 36/41: Add numsegments check for gpcheckcat
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 276d6a855ad8c6aa05522491e98a5fdba3187507
Author: Nihal Jain <jn...@jnihal-a01.vmware.com>
AuthorDate: Wed Nov 2 13:44:42 2022 +0530
Add numsegments check for gpcheckcat
For a partitioned table to have a correct distribution policy, the numsegments value for all root, middle and leaf level partitions must be equal. This commit adds this check for gpcheckcat. Readable external partitions are excluded from this check.
Sample log output for numsegments check failure:
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[INFO]:-[FAIL] partition numsegments check
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-partition numsegments check found 1 issue(s)
[ERROR]: child partition(s) have different numsegments value from the root partition. Check the gpcheckcat log for details.
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-The following tables have different numsegments value:
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:---------
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:- table | affected child | parent numsegments value | child numsegments value
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:- ------+----------------+--------------------------+------------------------
20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:- public.sales_1_prt_10 | public.sales_1_prt_10_2_prt_asia | 3 | 1
---
gpMgmt/bin/gpcheckcat | 63 ++++++++++++++++++++++++
gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature | 17 +++++++
2 files changed, 80 insertions(+)
diff --git a/gpMgmt/bin/gpcheckcat b/gpMgmt/bin/gpcheckcat
index da0d56479b..8da2a0298a 100755
--- a/gpMgmt/bin/gpcheckcat
+++ b/gpMgmt/bin/gpcheckcat
@@ -563,6 +563,69 @@ def checkPartitionIntegrity():
err = []
db = connect()
+ # Check for the numsegments value of parent and child partition from the gp_distribution_policy table
+ qry = '''
+ select inhparent::regclass, inhrelid::regclass, parent.numsegments as numsegments_parent, child.numsegments as numsegments_child
+ from pg_inherits inner join pg_partitioned_table on (pg_inherits.inhparent = pg_partitioned_table.partrelid)
+ inner join gp_distribution_policy parent on (parent.localoid = inhparent)
+ inner join gp_distribution_policy child on (child.localoid = inhrelid)
+ where parent.numsegments is distinct from child.numsegments
+ and not (inhrelid in (select ftrelid from pg_catalog.pg_foreign_table) and child.numsegments = NULL);
+ '''
+ try:
+ curs = db.query(qry)
+ cols = ('inhparent', 'inhrelid', 'numsegments_parent', 'numsegments_child')
+ col_names = {
+ 'inhparent': 'table',
+ 'inhrelid': 'affected child',
+ 'numsegments_parent': 'parent numsegments value',
+ 'numsegments_child': 'child numsegments value',
+ }
+
+ err = []
+ for row in curs.dictresult():
+ err.append([GV.cfg[GV.coordinator_dbid], cols, row])
+
+ if not err:
+ logger.info('[OK] partition numsegments check')
+ else:
+ err_count = len(err)
+ GV.checkStatus = False
+ setError(ERROR_REMOVE)
+ logger.info('[FAIL] partition numsegments check')
+ logger.error('partition numsegments check found %d issue(s)' % err_count)
+ if err_count > 100:
+ logger.error(qry)
+
+ myprint(
+ '[ERROR]: child partition(s) have different numsegments value '
+ 'from the root partition. Check the gpcheckcat log for details.'
+ )
+ logger.error('The following tables have different numsegments value (showing at most 100 rows):')
+
+ # report at most 100 rows, for brevity
+ err = err[:100]
+
+ for index, e in enumerate(err):
+ cfg = e[0]
+ col = e[1]
+ row = e[2]
+
+ if index == 0:
+ logger.error("--------")
+ logger.error(" " + " | ".join(map(col_names.get, col)))
+ logger.error(" " + "-+-".join(['-' * len(col_names[x]) for x in col]))
+
+ logger.error(" " + " | ".join([str(row[x]) for x in col]))
+
+ if err_count > 100:
+ logger.error(" ...")
+
+ except Exception as e:
+ setError(ERROR_NOREPAIR)
+ myprint('[ERROR] executing test: checkPartitionIntegrity')
+ myprint(' Execution error: ' + str(e))
+
# Check for the distribution policy of parent and child partitions based on the following conditions:
# 1. If a root is randomly distributed, then all middle, leaf level partitions must also be randomly distributed
# 2. If a root is hash distributed, then middle level should be same as root and
diff --git a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
index 8645f720db..0baa0278c7 100644
--- a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
+++ b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
@@ -232,6 +232,23 @@ Feature: gpcheckcat tests
And gpcheckcat should not print "Failed test\(s\) that are not reported here: part_integrity" to stdout
And the user runs "dropdb policy_db"
+ Scenario: gpcheckcat should report when parent and child partitions have different numsegments value
+ Given database "policy_db" is dropped and recreated
+ And the user runs "psql policy_db -f test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql"
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 0
+ And gpcheckcat should not print "child partition\(s\) have different numsegments value from the root partition" to stdout
+ And gpcheckcat should not print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+
+ And the user runs sql "set allow_system_table_mods=true; update gp_distribution_policy set numsegments = '1' where localoid='sales_1_prt_2'::regclass::oid;" in "policy_db" on all the segments
+ Then psql should return a return code of 0
+ When the user runs "gpcheckcat -R part_integrity policy_db"
+ Then gpcheckcat should return a return code of 1
+ And gpcheckcat should print "child partition\(s\) have different numsegments value from the root partition" to stdout
+ And gpcheckcat should print "Failed test\(s\) that are not reported here: part_integrity" to stdout
+ And the user runs "dropdb policy_db"
+
Scenario: gpcheckcat foreign key check should report missing catalog entries. Also test missing_extraneous for the same case.
Given database "fkey_db" is dropped and recreated
And the path "gpcheckcat.repair.*" is removed from current working directory
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 17/41: Add tests for ALTER TABLE ONLY ... SET TABLESPACE
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 5330213a81f4da148d03d007fa2f6b23d70793e6
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Wed Oct 19 13:39:48 2022 -0700
Add tests for ALTER TABLE ONLY ... SET TABLESPACE
Historically in GPDB6, when executing ALTER TABLE SET TABLESPACE
on a partition root, we will recurse into its child tables. This
behavior differs from the upstream where it is not recursed. We
have decided to keep this behavior for 7X, but to also support
the ONLY keyword so that users can choose to alter just the
partition root. Similar to other ALTER TABLE ONLY statements,
the syntax is e.g.:
ALTER TABLE ONLY foopart SET TABLESPACE myts
Discussion: https://groups.google.com/a/greenplum.org/g/gpdb-dev/c/ImJrvQEECwA
---
src/test/regress/input/tablespace.source | 19 +++++++++++++++++++
src/test/regress/output/tablespace.source | 25 +++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source
index ed7c56d65f..18f1736399 100644
--- a/src/test/regress/input/tablespace.source
+++ b/src/test/regress/input/tablespace.source
@@ -446,3 +446,22 @@ DROP SCHEMA testschema CASCADE;
DROP ROLE regress_tablespace_user1;
DROP ROLE regress_tablespace_user2;
+
+-- Test that altering tablespace of a partition table should recurse into its child tables unless ONLY is specified.
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 START (1) END (100));
+CREATE TABLESPACE myts LOCATION '@testtablespace@';
+ALTER TABLE tablespace_part SET TABLESPACE myts;
+
+-- Both parent and child tables use the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+
+DROP TABLE tablespace_part;
+
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 START (1) END (100));
+ALTER TABLE ONLY tablespace_part SET TABLESPACE myts;
+
+-- Only the parent table uses the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+
+DROP TABLE tablespace_part;
+DROP TABLESPACE myts;
diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/output/tablespace.source
index 7f8a955420..071a880620 100644
--- a/src/test/regress/output/tablespace.source
+++ b/src/test/regress/output/tablespace.source
@@ -984,3 +984,28 @@ drop cascades to table testschema.atable
drop cascades to table testschema.tablespace_acl
DROP ROLE regress_tablespace_user1;
DROP ROLE regress_tablespace_user2;
+-- Test that altering tablespace of a partition table should recurse into its child tables unless ONLY is specified.
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 START (1) END (100));
+CREATE TABLESPACE myts LOCATION '@testtablespace@';
+ALTER TABLE tablespace_part SET TABLESPACE myts;
+-- Both parent and child tables use the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+ relname | spcname
+--------------------------+---------
+ tablespace_part | myts
+ tablespace_part_1_prt_t1 | myts
+(2 rows)
+
+DROP TABLE tablespace_part;
+CREATE TABLE tablespace_part(a int, b int) PARTITION BY RANGE(a) (partition t1 START (1) END (100));
+ALTER TABLE ONLY tablespace_part SET TABLESPACE myts;
+-- Only the parent table uses the new tablespace
+SELECT c.relname, t.spcname FROM pg_class c LEFT JOIN pg_tablespace t ON c.reltablespace = t.oid WHERE relname LIKE 'tablespace_part%';
+ relname | spcname
+--------------------------+---------
+ tablespace_part | myts
+ tablespace_part_1_prt_t1 |
+(2 rows)
+
+DROP TABLE tablespace_part;
+DROP TABLESPACE myts;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 23/41: Fix typo. (#14290)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ca2123f6b9d74258bb181aacbfd8b76fac8e7f6e
Author: fiograf <50...@users.noreply.github.com>
AuthorDate: Sun Oct 30 03:13:32 2022 +0300
Fix typo. (#14290)
Fix typo.
---
gpMgmt/bin/gppylib/operations/startSegments.py | 2 +-
gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py | 2 +-
gpMgmt/bin/gppylib/system/configurationImplGpdb.py | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/gpMgmt/bin/gppylib/operations/startSegments.py b/gpMgmt/bin/gppylib/operations/startSegments.py
index 76db47c453..3c1246dbfe 100644
--- a/gpMgmt/bin/gppylib/operations/startSegments.py
+++ b/gpMgmt/bin/gppylib/operations/startSegments.py
@@ -136,7 +136,7 @@ class StartSegmentsOperation:
def __runStartCommand(self, segments, startMethod, numContentsInCluster, resultOut, gpArray, era):
"""
- Putt results into the resultOut object
+ Put results into the resultOut object
"""
if len(segments) == 0:
diff --git a/gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py b/gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py
index 74d080a1a2..b4d7df2c54 100755
--- a/gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py
+++ b/gpMgmt/bin/gppylib/system/ComputeCatalogUpdate.py
@@ -42,7 +42,7 @@ class ComputeCatalogUpdate:
@param gpArray the array containing the goal and db segment states.
@param forceMap a map of dbid->True for mirrors for which we should force updating via remove/add
- @param useUtilityMode True if the operations we're doing are expected to run via utility moed
+ @param useUtilityMode True if the operations we're doing are expected to run via utility mode
@param allowPrimary True if caller authorizes add/remove primary operations (e.g. gpexpand)
"""
diff --git a/gpMgmt/bin/gppylib/system/configurationImplGpdb.py b/gpMgmt/bin/gppylib/system/configurationImplGpdb.py
index 5ea4ae79a6..5e20a70225 100644
--- a/gpMgmt/bin/gppylib/system/configurationImplGpdb.py
+++ b/gpMgmt/bin/gppylib/system/configurationImplGpdb.py
@@ -84,7 +84,7 @@ class GpConfigurationProviderUsingGpdbCatalog(GpConfigurationProvider) :
@param textForConfigTable label to be used when adding to segment configuration history
@param dbIdToForceMirrorRemoveAdd a map of dbid -> True for mirrors for which we should force updating the mirror
- @param useUtilityMode True if the operations we're doing are expected to run via utility moed
+ @param useUtilityMode True if the operations we're doing are expected to run via utility mode
@param allowPrimary True if caller authorizes add/remove primary operations (e.g. gpexpand)
"""
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 15/41: Remove FIXME in bfv_olap_optimizer.out. (#14319)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit ff57b4890e03a1c65e908539bbe0aa420354f2bf
Author: Zhenghua Lyu <ka...@gmail.com>
AuthorDate: Mon Oct 24 09:00:44 2022 +0800
Remove FIXME in bfv_olap_optimizer.out. (#14319)
Now the SQL does not fallback to planner.
---
src/test/regress/expected/bfv_olap_optimizer.out | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/test/regress/expected/bfv_olap_optimizer.out b/src/test/regress/expected/bfv_olap_optimizer.out
index 84e7fd25ee..ae41f93494 100644
--- a/src/test/regress/expected/bfv_olap_optimizer.out
+++ b/src/test/regress/expected/bfv_olap_optimizer.out
@@ -673,9 +673,6 @@ DETAIL: Query-to-DXL Translation: No variable entry found due to incorrect norm
| 2100
(2 rows)
--- start_ignore
--- GPDB_12_MERGE_FIXME: unsupported exec location fallback
--- end_ignore
with cte as (select row_number() over (order by code) as rn1, code
from t2_github_issue_10143
group by code)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 29/41: ao/co: Move unique index DML tests to new group
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 2c3ad98952fae9d650c1efdc48b4595ae37d9b8a
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Fri Nov 4 20:55:21 2022 -0700
ao/co: Move unique index DML tests to new group
Grouping them with the other uao_dml tests led to flakes. Move them to a
new group.
Heed the words of wisdom:
"These tests use gp_select_invisible and VACUUM, and will get confused
if there are concurrent transactions holding back the global xmin."
---
src/test/regress/greenplum_schedule | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/test/regress/greenplum_schedule b/src/test/regress/greenplum_schedule
index 58d65b4cb1..d1861f680b 100755
--- a/src/test/regress/greenplum_schedule
+++ b/src/test/regress/greenplum_schedule
@@ -236,7 +236,7 @@ test: uao_ddl/gp_partition_tables_column uao_ddl/gp_partition_tables_row
# These tests use gp_select_invisible and VACUUM, and will get confused if there are
# concurrent transactions holding back the global xmin.
-test: uao_dml/uao_dml_cursor_row uao_dml/uao_dml_select_row uao_dml/uao_dml_cursor_column uao_dml/uao_dml_select_column uao_dml/uao_dml_unique_index_delete_row uao_dml/uao_dml_unique_index_delete_column uao_dml/uao_dml_unique_index_update_row uao_dml/uao_dml_unique_index_update_column
+test: uao_dml/uao_dml_cursor_row uao_dml/uao_dml_select_row uao_dml/uao_dml_cursor_column uao_dml/uao_dml_select_column
# test ao partition unique index update
test: ao_unique_index_partition
@@ -348,4 +348,7 @@ test: dynamic_table
# different CI env with GPDB
# test: gp_check_files
+# DML tests for AO/CO unique indexes.
+test: uao_dml/uao_dml_unique_index_delete_row uao_dml/uao_dml_unique_index_delete_column uao_dml/uao_dml_unique_index_update_row uao_dml/uao_dml_unique_index_update_column
+
# end of tests
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 40/41: Resolve a FIXME in merge_leaf_stats()
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 96d06cafad8f6ef573a705d21941370618685fba
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Thu Sep 8 15:01:36 2022 -0700
Resolve a FIXME in merge_leaf_stats()
A FIXME was left noting whether to use AccessShareLock or NoLock
when opening child tables to merge their stats. Since we have
acquired ShareUpdateExclusiveLock on the parent table when we
are at merge_leaf_stats(), we don't need extra lock to guard
against concurrent DROP of either the parent or the child (which
requries AccessExclusiveLock on the parent).
Concurrent UPDATE is possible but because we are not updating the table
ourselves, NoLock is sufficient here.
---
src/backend/commands/analyze.c | 14 +++--
src/test/isolation2/expected/lockmodes.out | 61 ++++++++++++++++++++++
.../isolation2/expected/lockmodes_optimizer.out | 61 ++++++++++++++++++++++
src/test/isolation2/sql/lockmodes.sql | 28 ++++++++++
4 files changed, 160 insertions(+), 4 deletions(-)
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index bdf8740c28..a8ac8c75b3 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -4414,11 +4414,17 @@ merge_leaf_stats(VacAttrStatsP stats,
(errmsg("Merging leaf partition stats to calculate root partition stats : column %s",
get_attname(stats->attr->attrelid, stats->attr->attnum, false))));
- /* GPDB_12_MERGE_FIXME: what's the appropriate lock level? AccessShareLock
- * is enough to scan the table, but are we updating them, too? If not,
- * NoLock might be enough?
+ /*
+ * Since we have acquired ShareUpdateExclusiveLock on the parent table when
+ * ANALYZE'ing it, we don't need extra lock to guard against concurrent DROP
+ * of either the parent or the child (which requries AccessExclusiveLock on
+ * the parent).
+ * Concurrent UPDATE is possible but because we are not updating the table
+ * ourselves, NoLock is sufficient here.
*/
- all_children_list = find_all_inheritors(stats->attr->attrelid, AccessShareLock, NULL);
+ all_children_list = find_all_inheritors(stats->attr->attrelid, NoLock, NULL);
+ SIMPLE_FAULT_INJECTOR("merge_leaf_stats_after_find_children");
+
oid_list = NIL;
foreach (lc, all_children_list)
{
diff --git a/src/test/isolation2/expected/lockmodes.out b/src/test/isolation2/expected/lockmodes.out
index 5318955776..df566ff9cd 100644
--- a/src/test/isolation2/expected/lockmodes.out
+++ b/src/test/isolation2/expected/lockmodes.out
@@ -2200,3 +2200,64 @@ ALTER
1: drop table lockmodes_datadir;
DROP
1q: ... <quitting>
+2q: ... <quitting>
+
+-- Check that concurrent DROP on leaf partition won't impact analyze on the
+-- parent since analyze will hold a ShareUpdateExclusiveLock and DROP will
+-- require an AccessExclusiveLock.
+-- Case 1. The analyze result is expected when there's concurrent drop on child.
+1:create table analyzedrop(a int) partition by range(a);
+CREATE
+1:create table analyzedrop_1 partition of analyzedrop for values from (0) to (10);
+CREATE
+1:create table analyzedrop_2 partition of analyzedrop for values from (10) to (20);
+CREATE
+1:insert into analyzedrop select * from generate_series(0,19);
+INSERT 20
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1&: analyze analyzedrop; <waiting ...>
+2&: drop table analyzedrop_1; <waiting ...>
+3:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1<: <... completed>
+ANALYZE
+2<: <... completed>
+DROP
+3:select * from pg_stats where tablename like 'analyzedrop%';
+ schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram
+------------+---------------+---------+-----------+-----------+-----------+------------+------------------+-------------------+--------------------------------------------------+-------------+-------------------+------------------------+----------------------
+ public | analyzedrop | a | t | 0 | 4 | -1 | | | {0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19} | | | |
+ public | analyzedrop_2 | a | f | 0 | 4 | -1 | | | {10,11,12,13,14,15,16,17,18,19} | 1 | | |
+(2 rows)
+-- Case 2. No failure should happen when there's concurrent drop on parent as well.
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1&: analyze analyzedrop; <waiting ...>
+2&: drop table analyzedrop_2; <waiting ...>
+3&: drop table analyzedrop; <waiting ...>
+4:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1<: <... completed>
+ANALYZE
+2<: <... completed>
+DROP
+3<: <... completed>
+DROP
+--empty as table is dropped
+4:select * from pg_stats where tablename like 'analyzedrop%';
+ schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram
+------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------
+(0 rows)
diff --git a/src/test/isolation2/expected/lockmodes_optimizer.out b/src/test/isolation2/expected/lockmodes_optimizer.out
index f98192946d..ed247a8a1b 100644
--- a/src/test/isolation2/expected/lockmodes_optimizer.out
+++ b/src/test/isolation2/expected/lockmodes_optimizer.out
@@ -2207,3 +2207,64 @@ ALTER
1: drop table lockmodes_datadir;
DROP
1q: ... <quitting>
+2q: ... <quitting>
+
+-- Check that concurrent DROP on leaf partition won't impact analyze on the
+-- parent since analyze will hold a ShareUpdateExclusiveLock and DROP will
+-- require an AccessExclusiveLock.
+-- Case 1. The analyze result is expected when there's concurrent drop on child.
+1:create table analyzedrop(a int) partition by range(a);
+CREATE
+1:create table analyzedrop_1 partition of analyzedrop for values from (0) to (10);
+CREATE
+1:create table analyzedrop_2 partition of analyzedrop for values from (10) to (20);
+CREATE
+1:insert into analyzedrop select * from generate_series(0,19);
+INSERT 20
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1&: analyze analyzedrop; <waiting ...>
+2&: drop table analyzedrop_1; <waiting ...>
+3:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1<: <... completed>
+ANALYZE
+2<: <... completed>
+DROP
+3:select * from pg_stats where tablename like 'analyzedrop%';
+ schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram
+------------+---------------+---------+-----------+-----------+-----------+------------+------------------+-------------------+--------------------------------------------------+-------------+-------------------+------------------------+----------------------
+ public | analyzedrop | a | t | 0 | 4 | -1 | | | {0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19} | | | |
+ public | analyzedrop_2 | a | f | 0 | 4 | -1 | | | {10,11,12,13,14,15,16,17,18,19} | 1 | | |
+(2 rows)
+-- Case 2. No failure should happen when there's concurrent drop on parent as well.
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1&: analyze analyzedrop; <waiting ...>
+2&: drop table analyzedrop_2; <waiting ...>
+3&: drop table analyzedrop; <waiting ...>
+4:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+ gp_inject_fault_infinite
+--------------------------
+ Success:
+(1 row)
+1<: <... completed>
+ANALYZE
+2<: <... completed>
+DROP
+3<: <... completed>
+DROP
+--empty as table is dropped
+4:select * from pg_stats where tablename like 'analyzedrop%';
+ schemaname | tablename | attname | inherited | null_frac | avg_width | n_distinct | most_common_vals | most_common_freqs | histogram_bounds | correlation | most_common_elems | most_common_elem_freqs | elem_count_histogram
+------------+-----------+---------+-----------+-----------+-----------+------------+------------------+-------------------+------------------+-------------+-------------------+------------------------+----------------------
+(0 rows)
diff --git a/src/test/isolation2/sql/lockmodes.sql b/src/test/isolation2/sql/lockmodes.sql
index 28541f8ba8..a42f9c1171 100644
--- a/src/test/isolation2/sql/lockmodes.sql
+++ b/src/test/isolation2/sql/lockmodes.sql
@@ -712,3 +712,31 @@ ALTER SYSTEM SET gp_enable_global_deadlock_detector TO on;
1: drop table lockmodes_datadir;
1q:
+2q:
+
+-- Check that concurrent DROP on leaf partition won't impact analyze on the
+-- parent since analyze will hold a ShareUpdateExclusiveLock and DROP will
+-- require an AccessExclusiveLock.
+-- Case 1. The analyze result is expected when there's concurrent drop on child.
+1:create table analyzedrop(a int) partition by range(a);
+1:create table analyzedrop_1 partition of analyzedrop for values from (0) to (10);
+1:create table analyzedrop_2 partition of analyzedrop for values from (10) to (20);
+1:insert into analyzedrop select * from generate_series(0,19);
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+1&: analyze analyzedrop;
+2&: drop table analyzedrop_1;
+3:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+1<:
+2<:
+3:select * from pg_stats where tablename like 'analyzedrop%';
+-- Case 2. No failure should happen when there's concurrent drop on parent as well.
+1:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'suspend', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+1&: analyze analyzedrop;
+2&: drop table analyzedrop_2;
+3&: drop table analyzedrop;
+4:select gp_inject_fault_infinite('merge_leaf_stats_after_find_children', 'reset', dbid) from gp_segment_configuration where content = -1 and role = 'p';
+1<:
+2<:
+3<:
+--empty as table is dropped
+4:select * from pg_stats where tablename like 'analyzedrop%';
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 04/41: Fix dependency bug with minirepro and materialized views (#14223)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit f2245856fdcbba5a637b76b59470642615f05566
Author: Chris Hajas <ch...@vmware.com>
AuthorDate: Mon Oct 10 15:40:47 2022 -0700
Fix dependency bug with minirepro and materialized views (#14223)
Previously, when using minirepro on a query that accessed materialized
views, the object that the materialized view used/accessed were not
dumped with the minirepro. This is because queries themselves treat
materialized views as tables, not views. However, when enumerating the
dependent objects for dumping the relevant DDL, we need to treat
materialized views as regular views.
This commit sets a flag when dumping from gp_dump_query_oids so that
materialized views are treated as regular views when parsing the query.
---
src/backend/rewrite/rewriteHandler.c | 6 +++++-
src/backend/utils/adt/gp_dump_oids.c | 11 ++++++-----
src/include/nodes/parsenodes.h | 2 ++
src/include/utils/rel.h | 3 +--
src/test/regress/expected/gp_dump_query_oids.out | 17 +++++++++++++++++
src/test/regress/sql/gp_dump_query_oids.sql | 9 +++++++++
6 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 7ba5f9a56b..27e65a0b1d 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -2092,8 +2092,12 @@ fireRIRrules(Query *parsetree, List *activeRIRs)
* expanded as if they were regular views, if they are not scannable.
* In that case this test would need to be postponed till after we've
* opened the rel, so that we could check its state.
+ *
+ * In the minirepro utility in GPDB, we use the expandMatViews flag
+ * to treat materialized views as regular views when dumping the
+ * DDL in order to dump dependent objects
*/
- if (rte->relkind == RELKIND_MATVIEW)
+ if (rte->relkind == RELKIND_MATVIEW && !parsetree->expandMatViews)
continue;
/*
diff --git a/src/backend/utils/adt/gp_dump_oids.c b/src/backend/utils/adt/gp_dump_oids.c
index 806c88e464..36fe718c28 100644
--- a/src/backend/utils/adt/gp_dump_oids.c
+++ b/src/backend/utils/adt/gp_dump_oids.c
@@ -18,6 +18,7 @@
#include "tcop/tcopprot.h"
#include "optimizer/optimizer.h"
#include "optimizer/planmain.h"
+#include "parser/analyze.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/hsearch.h"
@@ -120,11 +121,11 @@ gp_dump_query_oids(PG_FUNCTION_ARGS)
RawStmt *parsetree = lfirst_node(RawStmt, lc);
List *queryTree_sublist;
- queryTree_sublist = pg_analyze_and_rewrite(parsetree,
- sqlText,
- NULL,
- 0,
- NULL);
+
+ Query *query = parse_analyze(parsetree, sqlText, NULL, 0, NULL);
+ query->expandMatViews = true;
+ queryTree_sublist = pg_rewrite_query(query);
+
flat_query_list = list_concat(flat_query_list,
list_copy(queryTree_sublist));
}
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 2a3b3316c2..7a2118bad6 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -239,6 +239,8 @@ typedef struct Query
*/
int stmt_location; /* start location, or -1 if unknown */
int stmt_len; /* length in bytes; 0 means "rest of string" */
+
+ bool expandMatViews; /* force expansion of materialized views during rewrite to treat as views */
} Query;
/****************************************************************************
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index da05f580f8..08dc4a86fb 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -429,8 +429,7 @@ typedef struct ViewOptions
* eval of argument!
*/
#define RelationIsSecurityView(relation) \
- (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
- (relation)->rd_options ? \
+ ((relation)->rd_options ? \
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
/*
diff --git a/src/test/regress/expected/gp_dump_query_oids.out b/src/test/regress/expected/gp_dump_query_oids.out
index 0a58a93133..e5e98006b1 100644
--- a/src/test/regress/expected/gp_dump_query_oids.out
+++ b/src/test/regress/expected/gp_dump_query_oids.out
@@ -1,17 +1,28 @@
-- gp_dump_query_oids() doesn't list built-in functions, so we need a UDF to test with.
CREATE FUNCTION dumptestfunc(t text) RETURNS integer AS $$ SELECT 123 $$ LANGUAGE SQL;
CREATE FUNCTION dumptestfunc2(t text) RETURNS integer AS $$ SELECT 123 $$ LANGUAGE SQL;
+create table base(a int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' 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 materialized view base_mv as select a from base;
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
-- The function returns OIDs. We need to replace them with something reproducable.
CREATE FUNCTION sanitize_output(t text) RETURNS text AS $$
declare
dumptestfunc_oid oid;
dumptestfunc2_oid oid;
+ base_oid oid;
+ base_mv_oid oid;
begin
dumptestfunc_oid = 'dumptestfunc'::regproc::oid;
dumptestfunc2_oid = 'dumptestfunc2'::regproc::oid;
+ base_oid = 'base'::regclass::oid;
+ base_mv_oid = 'base_mv'::regclass::oid;
t := replace(t, dumptestfunc_oid::text, '<dumptestfunc>');
t := replace(t, dumptestfunc2_oid::text, '<dumptestfunc2>');
+ t := replace(t, base_oid::text, '<base_table>');
+ t := replace(t, base_mv_oid::text, '<base_mv>');
RETURN t;
end;
@@ -127,6 +138,12 @@ SELECT array['pg_class'::regclass::oid::text] <@ (string_to_array((SELECT info-
t
(1 row)
+SELECT sanitize_output(gp_dump_query_oids('SELECT * FROM base_mv'));
+ sanitize_output
+-----------------------------------------------------
+ {"relids": "<base_mv>,<base_table>", "funcids": ""}
+(1 row)
+
DROP TABLE foo;
DROP TABLE cctable;
DROP TABLE ctable;
diff --git a/src/test/regress/sql/gp_dump_query_oids.sql b/src/test/regress/sql/gp_dump_query_oids.sql
index dfd78ba55c..5a0152e21c 100644
--- a/src/test/regress/sql/gp_dump_query_oids.sql
+++ b/src/test/regress/sql/gp_dump_query_oids.sql
@@ -1,18 +1,26 @@
-- gp_dump_query_oids() doesn't list built-in functions, so we need a UDF to test with.
CREATE FUNCTION dumptestfunc(t text) RETURNS integer AS $$ SELECT 123 $$ LANGUAGE SQL;
CREATE FUNCTION dumptestfunc2(t text) RETURNS integer AS $$ SELECT 123 $$ LANGUAGE SQL;
+create table base(a int);
+create materialized view base_mv as select a from base;
-- The function returns OIDs. We need to replace them with something reproducable.
CREATE FUNCTION sanitize_output(t text) RETURNS text AS $$
declare
dumptestfunc_oid oid;
dumptestfunc2_oid oid;
+ base_oid oid;
+ base_mv_oid oid;
begin
dumptestfunc_oid = 'dumptestfunc'::regproc::oid;
dumptestfunc2_oid = 'dumptestfunc2'::regproc::oid;
+ base_oid = 'base'::regclass::oid;
+ base_mv_oid = 'base_mv'::regclass::oid;
t := replace(t, dumptestfunc_oid::text, '<dumptestfunc>');
t := replace(t, dumptestfunc2_oid::text, '<dumptestfunc2>');
+ t := replace(t, base_oid::text, '<base_table>');
+ t := replace(t, base_mv_oid::text, '<base_mv>');
RETURN t;
end;
@@ -74,6 +82,7 @@ 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),','));
+SELECT sanitize_output(gp_dump_query_oids('SELECT * FROM base_mv'));
DROP TABLE foo;
DROP TABLE cctable;
DROP TABLE ctable;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 39/41: ao/co: don't dereference dangling pointers (#14468)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit f2764ef4c662ccbd7527f86a4b435fe41dcb25b1
Author: Adam Lee <ad...@vmware.com>
AuthorDate: Thu Nov 17 11:43:53 2022 +0800
ao/co: don't dereference dangling pointers (#14468)
hash_search(,,HASH_REMOVE,) returns a dangling pointer that shouldn't be
dereferenced.
---
src/backend/access/aocs/aocsam_handler.c | 16 ++++++++++++----
src/backend/access/appendonly/appendonlyam_handler.c | 17 +++++++++++++----
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c
index 7dbdb37756..78d0248a48 100644
--- a/src/backend/access/aocs/aocsam_handler.c
+++ b/src/backend/access/aocs/aocsam_handler.c
@@ -242,7 +242,7 @@ find_dml_state(const Oid relationOid)
*
* Should be called exactly once per relation.
*/
-static inline AOCODMLState *
+static inline void
remove_dml_state(const Oid relationOid)
{
AOCODMLState *state;
@@ -254,13 +254,13 @@ remove_dml_state(const Oid relationOid)
NULL);
if (!state)
- return NULL;
+ return;
if (aocoDMLStates.last_used_state &&
aocoDMLStates.last_used_state->relationOid == relationOid)
aocoDMLStates.last_used_state = NULL;
- return state;
+ return;
}
/*
@@ -285,7 +285,14 @@ aoco_dml_finish(Relation relation, CmdType operation)
AOCODMLState *state;
bool had_delete_desc = false;
- state = remove_dml_state(RelationGetRelid(relation));
+ Oid relationOid = RelationGetRelid(relation);
+
+ Assert(aocoDMLStates.state_table);
+
+ state = (AOCODMLState *) hash_search(aocoDMLStates.state_table,
+ &relationOid,
+ HASH_FIND,
+ NULL);
if (!state)
return;
@@ -354,6 +361,7 @@ aoco_dml_finish(Relation relation, CmdType operation)
state->uniqueCheckDesc = NULL;
}
+ remove_dml_state(relationOid);
}
/*
diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c
index 6f4941447c..2c5cda5266 100644
--- a/src/backend/access/appendonly/appendonlyam_handler.c
+++ b/src/backend/access/appendonly/appendonlyam_handler.c
@@ -200,7 +200,7 @@ find_dml_state(const Oid relationOid)
*
* Should be called exactly once per relation.
*/
-static inline AppendOnlyDMLState *
+static inline void
remove_dml_state(const Oid relationOid)
{
AppendOnlyDMLState *state;
@@ -212,13 +212,13 @@ remove_dml_state(const Oid relationOid)
NULL);
if (!state)
- return NULL;
+ return;
if (appendOnlyDMLStates.last_used_state &&
appendOnlyDMLStates.last_used_state->relationOid == relationOid)
appendOnlyDMLStates.last_used_state = NULL;
- return state;
+ return;
}
/*
@@ -243,7 +243,14 @@ appendonly_dml_finish(Relation relation, CmdType operation)
AppendOnlyDMLState *state;
bool had_delete_desc = false;
- state = remove_dml_state(RelationGetRelid(relation));
+ Oid relationOid = RelationGetRelid(relation);
+
+ Assert(appendOnlyDMLStates.state_table);
+
+ state = (AppendOnlyDMLState *)hash_search(appendOnlyDMLStates.state_table,
+ &relationOid,
+ HASH_FIND,
+ NULL);
if (!state)
return;
@@ -311,6 +318,8 @@ appendonly_dml_finish(Relation relation, CmdType operation)
pfree(state->uniqueCheckDesc);
state->uniqueCheckDesc = NULL;
}
+
+ remove_dml_state(relationOid);
}
/*
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 12/41: Remove fixme in qp_correlated_query. (#14314)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit cd258f33920a047a7815090b6b454c023ceb140e
Author: Zhenghua Lyu <ka...@gmail.com>
AuthorDate: Sat Oct 22 13:45:29 2022 +0800
Remove fixme in qp_correlated_query. (#14314)
The commit faa7dc0713 fix the fallback but forget to remove
FIXME.
---
src/test/regress/expected/qp_correlated_query_optimizer.out | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/test/regress/expected/qp_correlated_query_optimizer.out b/src/test/regress/expected/qp_correlated_query_optimizer.out
index 25dd9c234e..a153038c25 100644
--- a/src/test/regress/expected/qp_correlated_query_optimizer.out
+++ b/src/test/regress/expected/qp_correlated_query_optimizer.out
@@ -3718,9 +3718,6 @@ EXPLAIN SELECT a FROM qp_tab1 f1 LEFT JOIN qp_tab2 on a=c WHERE NOT EXISTS(SELEC
Optimizer: Pivotal Optimizer (GPORCA) version 3.83.0
(11 rows)
--- start_ignore
-GPDB_12_MERGE_FIXME: Fallsback due to unsupported exec location.
--- end_ignore
EXPLAIN SELECT DISTINCT a FROM qp_tab1 WHERE NOT (SELECT TRUE FROM qp_tab2 WHERE EXISTS (SELECT * FROM qp_tab3 WHERE qp_tab2.c = qp_tab3.e));
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 33/41: Fix range tables opening's locking issue inside ExecInitModifyTable(). (#14418)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit fce2c2905526559626124489102ba07966b63d8c
Author: Aegeaner <gj...@vmware.com>
AuthorDate: Wed Nov 9 10:18:37 2022 +0800
Fix range tables opening's locking issue inside ExecInitModifyTable(). (#14418)
As #14417 reported, there will be assertion failures in some cases when
executing ModifyTable.
This is because we opened all the range table relations in NoLock mode,
but sometimes with no lock holding by us.
We fixed this by using GpPolicyFetch instead of opening relations since we
only need to judge if the range table is a partitioned table. This fix also
resolved a GPDB_91_MERGE FIXME left around range table locking code.
---
src/backend/executor/nodeModifyTable.c | 13 ++-----------
src/test/regress/expected/delete.out | 8 ++++++++
src/test/regress/sql/delete.sql | 7 +++++++
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 20d6988f9c..1cbc017a81 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -3401,7 +3401,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
PlanRowMark *rc = lfirst_node(PlanRowMark, l);
ExecRowMark *erm;
ExecAuxRowMark *aerm;
- bool isdistributed = false;
/* ignore "parent" rowmarks; they are irrelevant at runtime */
if (rc->isParent)
@@ -3410,21 +3409,13 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
/*
* Like in preprocess_targetlist, ignore distributed tables.
*/
- /*
- * GPDB_91_MERGE_FIXME: we are largely just ignoring locking altogether.
- * Perhaps that's OK as long as we take a full table lock on any UPDATEs
- * or DELETEs. But sure doesn't seem right. Can we do better?
- */
{
RangeTblEntry *rte = rt_fetch(rc->rti, estate->es_plannedstmt->rtable);
if (rte->rtekind == RTE_RELATION)
{
- Relation relation = heap_open(rte->relid, NoLock);
- if (GpPolicyIsPartitioned(relation->rd_cdbpolicy))
- isdistributed = true;
- heap_close(relation, NoLock);
- if (isdistributed)
+ GpPolicy *policy = GpPolicyFetch(rte->relid);
+ if (GpPolicyIsPartitioned(policy))
continue;
}
}
diff --git a/src/test/regress/expected/delete.out b/src/test/regress/expected/delete.out
index 8446f4226d..56c9168c92 100644
--- a/src/test/regress/expected/delete.out
+++ b/src/test/regress/expected/delete.out
@@ -30,4 +30,12 @@ SELECT id, a, char_length(b) FROM delete_test;
1 | 10 |
(1 row)
+-- issue 14417: Range Tables related relations opening's locking issue
+CREATE EXTERNAL WEB TABLE dummy(x int) EXECUTE 'touch /tmp/dummy2.csv;cat /tmp/dummy2.csv' ON MASTER FORMAT 'csv';
+CREATE TABLE issue_14417(x int);
+NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' 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.
+DELETE FROM issue_14417 WHERE x IN (SELECT x FROM dummy);
DROP TABLE delete_test;
+DROP TABLE issue_14417;
+DROP EXTERNAL TABLE dummy;
diff --git a/src/test/regress/sql/delete.sql b/src/test/regress/sql/delete.sql
index e6a2a39cc6..f0f8dbd783 100644
--- a/src/test/regress/sql/delete.sql
+++ b/src/test/regress/sql/delete.sql
@@ -22,4 +22,11 @@ DELETE FROM delete_test WHERE a > 25;
SELECT id, a, char_length(b) FROM delete_test;
+-- issue 14417: Range Tables related relations opening's locking issue
+CREATE EXTERNAL WEB TABLE dummy(x int) EXECUTE 'touch /tmp/dummy2.csv;cat /tmp/dummy2.csv' ON MASTER FORMAT 'csv';
+CREATE TABLE issue_14417(x int);
+DELETE FROM issue_14417 WHERE x IN (SELECT x FROM dummy);
+
DROP TABLE delete_test;
+DROP TABLE issue_14417;
+DROP EXTERNAL TABLE dummy;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 31/41: Refactor to extract SET_VAR to gp_bash_functions.sh
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 0f9ea5e85f451e96e6af9bb43c7df0634e3e2ac2
Author: Junwang Zhao <zh...@gmail.com>
AuthorDate: Fri Nov 4 14:43:57 2022 -0700
Refactor to extract SET_VAR to gp_bash_functions.sh
The `SET_VAR` function is indentical in gpcreateseg.sh and
gpinitsystem, since they both source the file gp_bash_functions.sh
Moving SET_VAR in gp_bash_functions.sh
---
gpMgmt/bin/gpinitsystem | 23 -----------------------
gpMgmt/bin/lib/gp_bash_functions.sh | 23 +++++++++++++++++++++++
gpMgmt/bin/lib/gpcreateseg.sh | 23 -----------------------
3 files changed, 23 insertions(+), 46 deletions(-)
diff --git a/gpMgmt/bin/gpinitsystem b/gpMgmt/bin/gpinitsystem
index e59bab05ce..f8d3bd37f8 100755
--- a/gpMgmt/bin/gpinitsystem
+++ b/gpMgmt/bin/gpinitsystem
@@ -1203,29 +1203,6 @@ DISPLAY_CONFIG () {
LOG_MSG "[INFO]:-End Function $FUNCNAME"
}
-SET_VAR () {
- #
- # MPP-13617: If segment contains a ~, we assume ~ is the field delimiter.
- # Otherwise we assume : is the delimiter. This allows us to easily
- # handle IPv6 addresses which may contain a : by using a ~ as a delimiter.
- #
- I=$1
- case $I in
- *~*)
- S="~"
- ;;
- *)
- S=":"
- ;;
- esac
- GP_HOSTNAME=`$ECHO $I|$CUT -d$S -f1`
- GP_HOSTADDRESS=`$ECHO $I|$CUT -d$S -f2`
- GP_PORT=`$ECHO $I|$CUT -d$S -f3`
- GP_DIR=`$ECHO $I|$CUT -d$S -f4`
- GP_DBID=`$ECHO $I|$CUT -d$S -f5`
- GP_CONTENT=`$ECHO $I|$CUT -d$S -f6`
-}
-
# Retrieve locale settings from the coordinator and set locale variables
# appropriately so those values can be used when initializing the segments.
SET_LOCALE_VARS_BASED_ON_COORDINATOR() {
diff --git a/gpMgmt/bin/lib/gp_bash_functions.sh b/gpMgmt/bin/lib/gp_bash_functions.sh
index 528ec9ae29..6c97005e84 100755
--- a/gpMgmt/bin/lib/gp_bash_functions.sh
+++ b/gpMgmt/bin/lib/gp_bash_functions.sh
@@ -1328,6 +1328,29 @@ CHECK_FTS () {
return $ret
}
+SET_VAR () {
+ #
+ # MPP-13617: If segment contains a ~, we assume ~ is the field delimiter.
+ # Otherwise we assume : is the delimiter. This allows us to easily
+ # handle IPv6 addresses which may contain a : by using a ~ as a delimiter.
+ #
+ I=$1
+ case $I in
+ *~*)
+ S="~"
+ ;;
+ *)
+ S=":"
+ ;;
+ esac
+ GP_HOSTNAME=`$ECHO $I|$CUT -d$S -f1`
+ GP_HOSTADDRESS=`$ECHO $I|$CUT -d$S -f2`
+ GP_PORT=`$ECHO $I|$CUT -d$S -f3`
+ GP_DIR=`$ECHO $I|$CUT -d$S -f4`
+ GP_DBID=`$ECHO $I|$CUT -d$S -f5`
+ GP_CONTENT=`$ECHO $I|$CUT -d$S -f6`
+}
+
#******************************************************************************
# Main Section
#******************************************************************************
diff --git a/gpMgmt/bin/lib/gpcreateseg.sh b/gpMgmt/bin/lib/gpcreateseg.sh
index b616f1bc57..2dfa970d86 100755
--- a/gpMgmt/bin/lib/gpcreateseg.sh
+++ b/gpMgmt/bin/lib/gpcreateseg.sh
@@ -68,29 +68,6 @@ CHK_CALL () {
fi
}
-SET_VAR () {
- #
- # MPP-13617: If segment contains a ~, we assume ~ is the field delimiter.
- # Otherwise we assume : is the delimiter. This allows us to easily
- # handle IPv6 addresses which may contain a : by using a ~ as a delimiter.
- #
- I=$1
- case $I in
- *~*)
- S="~"
- ;;
- *)
- S=":"
- ;;
- esac
- GP_HOSTNAME=`$ECHO $I|$CUT -d$S -f1`
- GP_HOSTADDRESS=`$ECHO $I|$CUT -d$S -f2`
- GP_PORT=`$ECHO $I|$CUT -d$S -f3`
- GP_DIR=`$ECHO $I|$CUT -d$S -f4`
- GP_DBID=`$ECHO $I|$CUT -d$S -f5`
- GP_CONTENT=`$ECHO $I|$CUT -d$S -f6`
-}
-
PARA_EXIT () {
if [ $1 -ne 0 ];then
$ECHO "FAILED:$SEGMENT_TO_CREATE" >> $PARALLEL_STATUS_FILE
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 13/41: Change FIXME to note in join_hash case.
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 173864a37cb28ed8b7813678975b28de55d178e7
Author: Zhenghua Lyu <ka...@gmail.com>
AuthorDate: Sun Oct 23 08:56:48 2022 +0800
Change FIXME to note in join_hash case.
The case is to test some code path during parallel hash join but
Greenplum does not support Postgres' parallel plan. Changes the FIXME
to a NOTE.
---
src/test/regress/expected/join_hash.out | 5 ++++-
src/test/regress/expected/join_hash_optimizer.out | 5 ++++-
src/test/regress/sql/join_hash.sql | 6 +++++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/test/regress/expected/join_hash.out b/src/test/regress/expected/join_hash.out
index fb32ed57f5..2a817e6972 100644
--- a/src/test/regress/expected/join_hash.out
+++ b/src/test/regress/expected/join_hash.out
@@ -918,9 +918,12 @@ rollback to settings;
-- the hash table)
-- parallel with parallel-aware hash join (hits ExecParallelHashLoadTuple and
-- sts_puttuple oversized tuple cases because it's multi-batch)
--- GPDB_12_MERGE_FIXME: I (Heikki) could not cajole the planner to create a
+-- NOTE: I (Heikki) could not cajole the planner to create a
-- plan like in upstream. I accepted the plan you get, but now this doesn't
-- exercise the special code path it's supposed to.
+-- Greenplum does not support parallel scan or parallel hash join now, the
+-- following cases will not hit the code path is supposed to be. We leave
+-- it here for maybe future wrk.
savepoint settings;
set max_parallel_workers_per_gather = 2;
set enable_parallel_hash = on;
diff --git a/src/test/regress/expected/join_hash_optimizer.out b/src/test/regress/expected/join_hash_optimizer.out
index 35cb582c8e..23eaedbd6f 100644
--- a/src/test/regress/expected/join_hash_optimizer.out
+++ b/src/test/regress/expected/join_hash_optimizer.out
@@ -1007,9 +1007,12 @@ rollback to settings;
-- the hash table)
-- parallel with parallel-aware hash join (hits ExecParallelHashLoadTuple and
-- sts_puttuple oversized tuple cases because it's multi-batch)
--- GPDB_12_MERGE_FIXME: I (Heikki) could not cajole the planner to create a
+-- NOTE: I (Heikki) could not cajole the planner to create a
-- plan like in upstream. I accepted the plan you get, but now this doesn't
-- exercise the special code path it's supposed to.
+-- Greenplum does not support parallel scan or parallel hash join now, the
+-- following cases will not hit the code path is supposed to be. We leave
+-- it here for maybe future wrk.
savepoint settings;
set max_parallel_workers_per_gather = 2;
set enable_parallel_hash = on;
diff --git a/src/test/regress/sql/join_hash.sql b/src/test/regress/sql/join_hash.sql
index 1e72839543..325068e9d2 100644
--- a/src/test/regress/sql/join_hash.sql
+++ b/src/test/regress/sql/join_hash.sql
@@ -471,10 +471,14 @@ rollback to settings;
-- parallel with parallel-aware hash join (hits ExecParallelHashLoadTuple and
-- sts_puttuple oversized tuple cases because it's multi-batch)
--- GPDB_12_MERGE_FIXME: I (Heikki) could not cajole the planner to create a
+-- NOTE: I (Heikki) could not cajole the planner to create a
-- plan like in upstream. I accepted the plan you get, but now this doesn't
-- exercise the special code path it's supposed to.
+-- Greenplum does not support parallel scan or parallel hash join now, the
+-- following cases will not hit the code path is supposed to be. We leave
+-- it here for maybe future wrk.
+
savepoint settings;
set max_parallel_workers_per_gather = 2;
set enable_parallel_hash = on;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 32/41: Workaround flaky test "dispatch" (#14429)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit e8c2b52cfb89f7db5ce4a60ee6f3a6b773c6c302
Author: David Kimura <dk...@vmware.com>
AuthorDate: Tue Nov 8 11:53:40 2022 -0800
Workaround flaky test "dispatch" (#14429)
Test case "dispatch started failing on PLANNER CI after commit a7ca9e27.
Using github Issue #14428 for tracking. It seems somehow triggered by
the test added in bfv_partition in aforementioned commit.
---
src/test/regress/expected/bfv_partition.out | 1 +
src/test/regress/sql/bfv_partition.sql | 1 +
2 files changed, 2 insertions(+)
diff --git a/src/test/regress/expected/bfv_partition.out b/src/test/regress/expected/bfv_partition.out
index ea4f0a2589..0e6191d471 100644
--- a/src/test/regress/expected/bfv_partition.out
+++ b/src/test/regress/expected/bfv_partition.out
@@ -3107,6 +3107,7 @@ WITH cte AS (
----
(0 rows)
+DROP TABLE a_partition_table_used_in_cte_test;
-- CLEANUP
-- start_ignore
drop schema if exists bfv_partition cascade;
diff --git a/src/test/regress/sql/bfv_partition.sql b/src/test/regress/sql/bfv_partition.sql
index 604bec7a82..bf705af128 100644
--- a/src/test/regress/sql/bfv_partition.sql
+++ b/src/test/regress/sql/bfv_partition.sql
@@ -1682,6 +1682,7 @@ ANALYZE a_partition_table_used_in_cte_test;
WITH cte AS (
SELECT * FROM a_partition_table_used_in_cte_test WHERE c1 < 2
) SELECT * FROM cte WHERE c1 = 1;
+DROP TABLE a_partition_table_used_in_cte_test;
-- CLEANUP
-- start_ignore
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 03/41: Fix incorrect sortOp and eqOp generated by IsCorrelatedEqualityOpExpr. (#14108)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit c66c184aca24d375b9297d835c72853c3aaaee84
Author: 1mmortal <ju...@alibaba-inc.com>
AuthorDate: Tue Oct 11 15:01:21 2022 +0800
Fix incorrect sortOp and eqOp generated by IsCorrelatedEqualityOpExpr. (#14108)
In GPDB, expression subquery is promoted to join, e.g.
select * from T where a > (select 10*avg(x) from R where T.b=R.y);
in postgres, the plan is:
QUERY PLAN
-----------------------------------------------------------------
Seq Scan on t (cost=0.00..80364.30 rows=753 width=8)
Filter: ((a)::numeric > (SubPlan 1))
SubPlan 1
-> Aggregate (cost=35.53..35.54 rows=1 width=32)
-> Seq Scan on r (cost=0.00..35.50 rows=10 width=4)
Filter: (t.b = y)
while in GPDB, the subquery is promoted to join:
QUERY PLAN
---------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Hash Join (cost=477.00..969.11 rows=9567 width=8)
Hash Cond: (t.b = "Expr_SUBQUERY".csq_c0)
Join Filter: ((t.a)::numeric > "Expr_SUBQUERY".csq_c1)
-> Seq Scan on t (cost=0.00..321.00 rows=28700 width=8)
-> Hash (cost=472.83..472.83 rows=333 width=36)
-> Subquery Scan on "Expr_SUBQUERY"
-> HashAggregate
Group Key: r.y
-> Seq Scan on r
Optimizer: Postgres query optimizer
But if the T.b and R.y are different type, it will report error like:
ERROR: operator 37 is not a valid ordering operator (pathkeys.c:579)
The root cause is that IsCorrelatedEqualityOpExpr may generate incorrect sort
operator and equal operator for SortGroupClause when the types of left and right
operands of OpExpr are different.
Since get_ordering_op_properties() requires the type of the left and right
operands being consistent and SortGroupClause->tleSortGroupRef is referencing
the target entry created from innerExpr, we teach IsCorrelatedEqualityOpExpr()
construct appropriate eqOp and sortOp according to the type of innerExpr.
---
src/backend/cdb/cdbsubselect.c | 29 ++--
src/test/regress/expected/subselect_gp.out | 186 +++++++++++++++++++++
.../regress/expected/subselect_gp_optimizer.out | 186 +++++++++++++++++++++
src/test/regress/sql/subselect_gp.sql | 83 +++++++++
4 files changed, 470 insertions(+), 14 deletions(-)
diff --git a/src/backend/cdb/cdbsubselect.c b/src/backend/cdb/cdbsubselect.c
index 07fd8d0f6a..6180441c3e 100644
--- a/src/backend/cdb/cdbsubselect.c
+++ b/src/backend/cdb/cdbsubselect.c
@@ -148,13 +148,13 @@ IsCorrelatedOpExpr(OpExpr *opexp, Expr **innerExpr)
* returns true if correlated equality condition
* *innerExpr - points to the inner expr i.e. bar(innervar) in the condition
* *eqOp and *sortOp - equality and < operators, to implement the condition as a mergejoin.
+ * The *eqOp and *sortOp should be determined according to innervar's type.
*/
static bool
IsCorrelatedEqualityOpExpr(OpExpr *opexp, Expr **innerExpr, Oid *eqOp, Oid *sortOp, bool *hashable)
{
Oid opfamily;
- Oid ltype;
- Oid rtype;
+ Oid innerExprType;
List *l;
Assert(opexp);
@@ -163,11 +163,17 @@ IsCorrelatedEqualityOpExpr(OpExpr *opexp, Expr **innerExpr, Oid *eqOp, Oid *sort
Assert(eqOp);
Assert(sortOp);
+ if (!IsCorrelatedOpExpr(opexp, innerExpr))
+ return false;
+
+ Assert(*innerExpr);
+ innerExprType = exprType((Node *)*innerExpr);
+
/*
* If this is an expression of the form a = b, then we want to know about
* the vars involved.
*/
- if (!op_mergejoinable(opexp->opno, exprType(linitial(opexp->args))))
+ if (!op_mergejoinable(opexp->opno, innerExprType))
return false;
/*
@@ -182,24 +188,19 @@ IsCorrelatedEqualityOpExpr(OpExpr *opexp, Expr **innerExpr, Oid *eqOp, Oid *sort
list_free(l);
/*
- * Look up the correct sort operator from the chosen opfamily.
+ * Look up the correct equility/sort operators from the chosen opfamily.
*/
- ltype = exprType(linitial(opexp->args));
- rtype = exprType(lsecond(opexp->args));
- *eqOp = get_opfamily_member(opfamily, ltype, rtype, BTEqualStrategyNumber);
+ *eqOp = get_opfamily_member(opfamily, innerExprType, innerExprType, BTEqualStrategyNumber);
if (!OidIsValid(*eqOp)) /* should not happen */
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
- BTEqualStrategyNumber, ltype, rtype, opfamily);
+ BTEqualStrategyNumber, innerExprType, innerExprType, opfamily);
- *sortOp = get_opfamily_member(opfamily, ltype, rtype, BTLessStrategyNumber);
+ *sortOp = get_opfamily_member(opfamily, innerExprType, innerExprType, BTLessStrategyNumber);
if (!OidIsValid(*sortOp)) /* should not happen */
elog(ERROR, "could not find member %d(%u,%u) of opfamily %u",
- BTLessStrategyNumber, ltype, rtype, opfamily);
+ BTLessStrategyNumber, innerExprType, innerExprType, opfamily);
- *hashable = op_hashjoinable(*eqOp, ltype);
-
- if (!IsCorrelatedOpExpr(opexp, innerExpr))
- return false;
+ *hashable = op_hashjoinable(*eqOp, innerExprType);
return true;
}
diff --git a/src/test/regress/expected/subselect_gp.out b/src/test/regress/expected/subselect_gp.out
index 966335ab41..2995f52a6d 100644
--- a/src/test/regress/expected/subselect_gp.out
+++ b/src/test/regress/expected/subselect_gp.out
@@ -3036,3 +3036,189 @@ select * from param_t a where a.i in
(1 row)
drop table if exists param_t;
+-- A guard test case for gpexpand's populate SQL
+-- Some simple notes and background is: we want to compute
+-- table size efficiently, it is better to avoid invoke
+-- pg_relation_size() in serial on QD, since this function
+-- will dispatch for each tuple. The bad pattern SQL is like
+-- select pg_relation_size(oid) from pg_class where xxx
+-- The idea is force pg_relations_size is evaluated on each
+-- segment and the sum the result together to get the final
+-- result. To make sure correctness, we have to evaluate
+-- pg_relation_size before any motion. The skill here is
+-- to wrap this in a subquery, due to volatile of pg_relation_size,
+-- this subquery won't be pulled up. Plus the skill of
+-- gp_dist_random('pg_class') we can achieve this goal.
+-- the below test is to verify the plan, we should see pg_relation_size
+-- is evaludated on each segment and then motion then sum together. The
+-- SQL pattern is a catalog join a table size "dict".
+set gp_enable_multiphase_agg = on;
+-- force nestloop join to make test stable since we
+-- are testing plan and do not care about where we
+-- put hash table.
+set enable_hashjoin = off;
+set enable_nestloop = on;
+set enable_indexscan = off;
+set enable_bitmapscan = off;
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> Nested Loop
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ Join Filter: (pc.oid = pg_class.oid)
+ -> Redistribute Motion 1:3 (slice2)
+ Output: pc.relname, pc.oid
+ Hash Key: pc.oid
+ -> Seq Scan on pg_catalog.pg_class pc
+ Output: pc.relname, pc.oid
+ -> Materialize
+ Output: pg_class.oid, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> HashAggregate
+ Output: pg_class.oid, sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text)))
+ Group Key: pg_class.oid
+ -> Redistribute Motion 3:3 (slice3; segments: 3)
+ Output: pg_class.oid, (pg_relation_size((pg_class.oid)::regclass, 'main'::text))
+ Hash Key: pg_class.oid
+ -> Seq Scan on pg_catalog.pg_class
+ Output: pg_class.oid, pg_relation_size((pg_class.oid)::regclass, 'main'::text)
+ Optimizer: Postgres query optimizer
+(21 rows)
+
+set gp_enable_multiphase_agg = off;
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> Nested Loop
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ Join Filter: (pc.oid = pg_class.oid)
+ -> Redistribute Motion 1:3 (slice2)
+ Output: pc.relname, pc.oid
+ Hash Key: pc.oid
+ -> Seq Scan on pg_catalog.pg_class pc
+ Output: pc.relname, pc.oid
+ -> Materialize
+ Output: pg_class.oid, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> HashAggregate
+ Output: pg_class.oid, sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text)))
+ Group Key: pg_class.oid
+ -> Redistribute Motion 3:3 (slice3; segments: 3)
+ Output: pg_class.oid, (pg_relation_size((pg_class.oid)::regclass, 'main'::text))
+ Hash Key: pg_class.oid
+ -> Seq Scan on pg_catalog.pg_class
+ Output: pg_class.oid, pg_relation_size((pg_class.oid)::regclass, 'main'::text)
+ Optimizer: Postgres query optimizer
+(21 rows)
+
+reset gp_enable_multiphase_agg;
+reset enable_hashjoin;
+reset enable_nestloop;
+reset enable_indexscan;
+reset enable_bitmapscan;
+create table sublink_outer_table(a int, b int) distributed by(b);
+create table sublink_inner_table(x int, y bigint) distributed by(y);
+set optimizer to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=436.00..1310.77 rows=28700 width=8)
+ -> Hash Join (cost=436.00..928.11 rows=9567 width=8)
+ Hash Cond: (t.b = sublink_inner_table.y)
+ Join Filter: ((t.a)::numeric > (('10'::numeric * avg(sublink_inner_table.x))))
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=431.83..431.83 rows=333 width=40)
+ -> HashAggregate (cost=423.50..428.50 rows=333 width=40)
+ Group Key: sublink_inner_table.y
+ -> Seq Scan on sublink_inner_table (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(10 rows)
+
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=436.00..1310.77 rows=28700 width=8)
+ -> Hash Join (cost=436.00..928.11 rows=9567 width=8)
+ Hash Cond: (t.b = "Expr_SUBQUERY".csq_c0)
+ Join Filter: ((t.a)::numeric > "Expr_SUBQUERY".csq_c1)
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=431.83..431.83 rows=333 width=40)
+ -> Subquery Scan on "Expr_SUBQUERY" (cost=423.50..431.83 rows=333 width=40)
+ -> HashAggregate (cost=423.50..428.50 rows=333 width=40)
+ Group Key: r.y
+ -> Seq Scan on sublink_inner_table r (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(11 rows)
+
+set enable_hashagg to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=2404.84..3279.62 rows=28700 width=8)
+ -> Hash Join (cost=2404.84..2896.95 rows=9567 width=8)
+ Hash Cond: (t.b = sublink_inner_table.y)
+ Join Filter: ((t.a)::numeric > (('10'::numeric * avg(sublink_inner_table.x))))
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=2400.67..2400.67 rows=333 width=40)
+ -> GroupAggregate (cost=2197.59..2397.34 rows=333 width=40)
+ Group Key: sublink_inner_table.y
+ -> Sort (cost=2197.59..2262.51 rows=25967 width=12)
+ Sort Key: sublink_inner_table.y
+ -> Seq Scan on sublink_inner_table (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(12 rows)
+
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=2404.84..3279.62 rows=28700 width=8)
+ -> Hash Join (cost=2404.84..2896.95 rows=9567 width=8)
+ Hash Cond: (t.b = "Expr_SUBQUERY".csq_c0)
+ Join Filter: ((t.a)::numeric > "Expr_SUBQUERY".csq_c1)
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=2400.67..2400.67 rows=333 width=40)
+ -> Subquery Scan on "Expr_SUBQUERY" (cost=2197.59..2400.67 rows=333 width=40)
+ -> GroupAggregate (cost=2197.59..2397.34 rows=333 width=40)
+ Group Key: r.y
+ -> Sort (cost=2197.59..2262.51 rows=25967 width=12)
+ Sort Key: r.y
+ -> Seq Scan on sublink_inner_table r (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
+drop table sublink_outer_table;
+drop table sublink_inner_table;
+reset optimizer;
+reset enable_hashagg;
diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out
index 533abf961d..8aba40fb65 100644
--- a/src/test/regress/expected/subselect_gp_optimizer.out
+++ b/src/test/regress/expected/subselect_gp_optimizer.out
@@ -3125,3 +3125,189 @@ select * from param_t a where a.i in
(1 row)
drop table if exists param_t;
+-- A guard test case for gpexpand's populate SQL
+-- Some simple notes and background is: we want to compute
+-- table size efficiently, it is better to avoid invoke
+-- pg_relation_size() in serial on QD, since this function
+-- will dispatch for each tuple. The bad pattern SQL is like
+-- select pg_relation_size(oid) from pg_class where xxx
+-- The idea is force pg_relations_size is evaluated on each
+-- segment and the sum the result together to get the final
+-- result. To make sure correctness, we have to evaluate
+-- pg_relation_size before any motion. The skill here is
+-- to wrap this in a subquery, due to volatile of pg_relation_size,
+-- this subquery won't be pulled up. Plus the skill of
+-- gp_dist_random('pg_class') we can achieve this goal.
+-- the below test is to verify the plan, we should see pg_relation_size
+-- is evaludated on each segment and then motion then sum together. The
+-- SQL pattern is a catalog join a table size "dict".
+set gp_enable_multiphase_agg = on;
+-- force nestloop join to make test stable since we
+-- are testing plan and do not care about where we
+-- put hash table.
+set enable_hashjoin = off;
+set enable_nestloop = on;
+set enable_indexscan = off;
+set enable_bitmapscan = off;
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> Nested Loop
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ Join Filter: (pc.oid = pg_class.oid)
+ -> Redistribute Motion 1:3 (slice2)
+ Output: pc.relname, pc.oid
+ Hash Key: pc.oid
+ -> Seq Scan on pg_catalog.pg_class pc
+ Output: pc.relname, pc.oid
+ -> Materialize
+ Output: pg_class.oid, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> HashAggregate
+ Output: pg_class.oid, sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text)))
+ Group Key: pg_class.oid
+ -> Redistribute Motion 3:3 (slice3; segments: 3)
+ Output: pg_class.oid, (pg_relation_size((pg_class.oid)::regclass, 'main'::text))
+ Hash Key: pg_class.oid
+ -> Seq Scan on pg_catalog.pg_class
+ Output: pg_class.oid, pg_relation_size((pg_class.oid)::regclass, 'main'::text)
+ Optimizer: Postgres query optimizer
+(21 rows)
+
+set gp_enable_multiphase_agg = off;
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3)
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> Nested Loop
+ Output: pc.relname, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ Join Filter: (pc.oid = pg_class.oid)
+ -> Redistribute Motion 1:3 (slice2)
+ Output: pc.relname, pc.oid
+ Hash Key: pc.oid
+ -> Seq Scan on pg_catalog.pg_class pc
+ Output: pc.relname, pc.oid
+ -> Materialize
+ Output: pg_class.oid, (sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text))))
+ -> HashAggregate
+ Output: pg_class.oid, sum((pg_relation_size((pg_class.oid)::regclass, 'main'::text)))
+ Group Key: pg_class.oid
+ -> Redistribute Motion 3:3 (slice3; segments: 3)
+ Output: pg_class.oid, (pg_relation_size((pg_class.oid)::regclass, 'main'::text))
+ Hash Key: pg_class.oid
+ -> Seq Scan on pg_catalog.pg_class
+ Output: pg_class.oid, pg_relation_size((pg_class.oid)::regclass, 'main'::text)
+ Optimizer: Postgres query optimizer
+(21 rows)
+
+reset gp_enable_multiphase_agg;
+reset enable_hashjoin;
+reset enable_nestloop;
+reset enable_indexscan;
+reset enable_bitmapscan;
+create table sublink_outer_table(a int, b int) distributed by(b);
+create table sublink_inner_table(x int, y bigint) distributed by(y);
+set optimizer to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=436.00..1310.77 rows=28700 width=8)
+ -> Hash Join (cost=436.00..928.11 rows=9567 width=8)
+ Hash Cond: (t.b = sublink_inner_table.y)
+ Join Filter: ((t.a)::numeric > (('10'::numeric * avg(sublink_inner_table.x))))
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=431.83..431.83 rows=333 width=40)
+ -> HashAggregate (cost=423.50..428.50 rows=333 width=40)
+ Group Key: sublink_inner_table.y
+ -> Seq Scan on sublink_inner_table (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(10 rows)
+
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=436.00..1310.77 rows=28700 width=8)
+ -> Hash Join (cost=436.00..928.11 rows=9567 width=8)
+ Hash Cond: (t.b = "Expr_SUBQUERY".csq_c0)
+ Join Filter: ((t.a)::numeric > "Expr_SUBQUERY".csq_c1)
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=431.83..431.83 rows=333 width=40)
+ -> Subquery Scan on "Expr_SUBQUERY" (cost=423.50..431.83 rows=333 width=40)
+ -> HashAggregate (cost=423.50..428.50 rows=333 width=40)
+ Group Key: r.y
+ -> Seq Scan on sublink_inner_table r (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(11 rows)
+
+set enable_hashagg to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=2404.84..3279.62 rows=28700 width=8)
+ -> Hash Join (cost=2404.84..2896.95 rows=9567 width=8)
+ Hash Cond: (t.b = sublink_inner_table.y)
+ Join Filter: ((t.a)::numeric > (('10'::numeric * avg(sublink_inner_table.x))))
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=2400.67..2400.67 rows=333 width=40)
+ -> GroupAggregate (cost=2197.59..2397.34 rows=333 width=40)
+ Group Key: sublink_inner_table.y
+ -> Sort (cost=2197.59..2262.51 rows=25967 width=12)
+ Sort Key: sublink_inner_table.y
+ -> Seq Scan on sublink_inner_table (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(12 rows)
+
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1 (slice1; segments: 3) (cost=2404.84..3279.62 rows=28700 width=8)
+ -> Hash Join (cost=2404.84..2896.95 rows=9567 width=8)
+ Hash Cond: (t.b = "Expr_SUBQUERY".csq_c0)
+ Join Filter: ((t.a)::numeric > "Expr_SUBQUERY".csq_c1)
+ -> Seq Scan on sublink_outer_table t (cost=0.00..321.00 rows=28700 width=8)
+ -> Hash (cost=2400.67..2400.67 rows=333 width=40)
+ -> Subquery Scan on "Expr_SUBQUERY" (cost=2197.59..2400.67 rows=333 width=40)
+ -> GroupAggregate (cost=2197.59..2397.34 rows=333 width=40)
+ Group Key: r.y
+ -> Sort (cost=2197.59..2262.51 rows=25967 width=12)
+ Sort Key: r.y
+ -> Seq Scan on sublink_inner_table r (cost=0.00..293.67 rows=25967 width=12)
+ Optimizer: Postgres query optimizer
+(13 rows)
+
+drop table sublink_outer_table;
+drop table sublink_inner_table;
+reset optimizer;
+reset enable_hashagg;
diff --git a/src/test/regress/sql/subselect_gp.sql b/src/test/regress/sql/subselect_gp.sql
index 5391e4747c..de95b3d355 100644
--- a/src/test/regress/sql/subselect_gp.sql
+++ b/src/test/regress/sql/subselect_gp.sql
@@ -1214,3 +1214,86 @@ select * from param_t a where a.i in
drop table if exists param_t;
+
+-- A guard test case for gpexpand's populate SQL
+-- Some simple notes and background is: we want to compute
+-- table size efficiently, it is better to avoid invoke
+-- pg_relation_size() in serial on QD, since this function
+-- will dispatch for each tuple. The bad pattern SQL is like
+-- select pg_relation_size(oid) from pg_class where xxx
+-- The idea is force pg_relations_size is evaluated on each
+-- segment and the sum the result together to get the final
+-- result. To make sure correctness, we have to evaluate
+-- pg_relation_size before any motion. The skill here is
+-- to wrap this in a subquery, due to volatile of pg_relation_size,
+-- this subquery won't be pulled up. Plus the skill of
+-- gp_dist_random('pg_class') we can achieve this goal.
+
+-- the below test is to verify the plan, we should see pg_relation_size
+-- is evaludated on each segment and then motion then sum together. The
+-- SQL pattern is a catalog join a table size "dict".
+
+set gp_enable_multiphase_agg = on;
+-- force nestloop join to make test stable since we
+-- are testing plan and do not care about where we
+-- put hash table.
+set enable_hashjoin = off;
+set enable_nestloop = on;
+set enable_indexscan = off;
+set enable_bitmapscan = off;
+
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+
+set gp_enable_multiphase_agg = off;
+
+explain (verbose on, costs off)
+with cte(table_oid, size) as
+(
+ select
+ table_oid,
+ sum(size) size
+ from (
+ select oid,
+ pg_relation_size(oid)
+ from gp_dist_random('pg_class')
+ ) x(table_oid, size)
+ group by table_oid
+)
+select pc.relname, ts.size
+from pg_class pc, cte ts
+where pc.oid = ts.table_oid;
+
+reset gp_enable_multiphase_agg;
+reset enable_hashjoin;
+reset enable_nestloop;
+reset enable_indexscan;
+reset enable_bitmapscan;
+create table sublink_outer_table(a int, b int) distributed by(b);
+create table sublink_inner_table(x int, y bigint) distributed by(y);
+
+set optimizer to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+
+set enable_hashagg to off;
+explain select t.* from sublink_outer_table t join (select y ,10*avg(x) s from sublink_inner_table group by y) RR on RR.y = t.b and t.a > rr.s;
+explain select * from sublink_outer_table T where a > (select 10*avg(x) from sublink_inner_table R where T.b=R.y);
+drop table sublink_outer_table;
+drop table sublink_inner_table;
+reset optimizer;
+reset enable_hashagg;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 25/41: Remove unnecessary code that dealt with locus of UNION plans. (#10879)
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 4be1bf50eab09cf7a0c9b2478358ba7ff8594f91
Author: Heikki Linnakangas <he...@iki.fi>
AuthorDate: Wed Nov 2 04:10:48 2022 +0200
Remove unnecessary code that dealt with locus of UNION plans. (#10879)
The effort was duplicated with set_append_path_locus(), which is called
from create_append_path(). Let's just let set_append_path_locus() deal
with it.
Reviewed-by: Haotian Chen <ch...@vmware.com>
Reviewed-by: Zhenghua Lyu <ka...@gmail.com>
---
src/backend/optimizer/prep/prepunion.c | 24 +-----------------------
src/test/regress/expected/with_clause.out | 28 +++++++++++++---------------
2 files changed, 14 insertions(+), 38 deletions(-)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index 5656e4dbcd..fda13f0924 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -597,7 +597,6 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
List *tlist_list;
List *tlist;
Path *path;
- GpSetOpType optype = PSETOP_NONE; /* CDB */
/*
* If plain UNION, tell children to fetch all tuples.
@@ -661,39 +660,18 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
result_rel->reltarget = create_pathtarget(root, tlist);
result_rel->consider_parallel = consider_parallel;
-
- /* GPDB_96_MERGE_FIXME: We should use the new pathified upper planner
- * infrastructure for this. I think we should create multiple Paths,
- * representing different kinds of PSETOP_* implementations, and
- * let the "add_path()" choose the cheapest one.
- */
- /* CDB: Decide on approach, condition argument plans to suit. */
- if ( Gp_role == GP_ROLE_DISPATCH )
- {
- optype = choose_setop_type(pathlist);
- adjust_setop_arguments(root, pathlist, tlist_list, optype);
- }
- else if (Gp_role == GP_ROLE_UTILITY ||
- Gp_role == GP_ROLE_EXECUTE) /* MPP-2928 */
- {
- optype = PSETOP_SEQUENTIAL_QD;
- }
-
/*
* Append the child results together.
*/
path = (Path *) create_append_path(root, result_rel, pathlist, NIL,
NIL, NULL, 0, false, -1);
- // GPDB_96_MERGE_FIXME: Where should this go now?
- //mark_append_locus(plan, optype); /* CDB: Mark the plan result locus. */
-
/*
* For UNION ALL, we just need the Append path. For UNION, need to add
* node(s) to remove duplicates.
*/
if (!op->all)
{
- if ( optype == PSETOP_PARALLEL_PARTITIONED )
+ if (CdbPathLocus_IsPartitioned(path->locus))
{
/* CDB: Hash motion to collocate non-distinct tuples. */
path = make_motion_hash_all_targets(root, path, tlist);
diff --git a/src/test/regress/expected/with_clause.out b/src/test/regress/expected/with_clause.out
index 018235254d..c2610c7d6d 100644
--- a/src/test/regress/expected/with_clause.out
+++ b/src/test/regress/expected/with_clause.out
@@ -2263,10 +2263,10 @@ UNION ALL
SELECT count(a1.i)
FROM a1
INNER JOIN a2 ON a2.i = a1.i;
- QUERY PLAN
-----------------------------------------------------------------------------------
- Gather Motion 3:1 (slice1; segments: 3)
- -> Append
+ QUERY PLAN
+----------------------------------------------------------------------
+ Append
+ -> Gather Motion 3:1 (slice1; segments: 3)
-> Subquery Scan on "*SELECT* 1"
-> Hash Join
Hash Cond: (share1_ref1.i = a2.i)
@@ -2276,18 +2276,16 @@ SELECT count(a1.i)
-> Subquery Scan on a2
-> Shared Scan (share slice:id 1:0)
-> Seq Scan on foo foo_1
- -> Redistribute Motion 1:3 (slice2; segments: 1)
- Hash Key: (count(share1_ref2.i))
- -> Aggregate
- -> Gather Motion 3:1 (slice3; segments: 3)
- -> Hash Join
- Hash Cond: (share1_ref2.i = a2_1.i)
- -> Shared Scan (share slice:id 3:1)
- -> Hash
- -> Subquery Scan on a2_1
- -> Shared Scan (share slice:id 3:0)
+ -> Aggregate
+ -> Gather Motion 3:1 (slice2; segments: 3)
+ -> Hash Join
+ Hash Cond: (share1_ref2.i = a2_1.i)
+ -> Shared Scan (share slice:id 2:1)
+ -> Hash
+ -> Subquery Scan on a2_1
+ -> Shared Scan (share slice:id 2:0)
Optimizer: Postgres query optimizer
-(22 rows)
+(20 rows)
-- Another cross-slice ShareInputScan test. There is one producing slice,
-- and two consumers in second slice. Make sure the Share Input Scan
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org
(cloudberry) 08/41: Removed unnecessary variable assignment.
Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit e45481b27637ea6a2ec7e1e9089e5386fe1bdfe9
Author: Gleb Khudyaev <66...@users.noreply.github.com>
AuthorDate: Wed Oct 12 02:05:22 2022 +0300
Removed unnecessary variable assignment.
The same value is assigned to the variable at the moment
of declaration (some lines before)
---
src/backend/access/aocs/aocs_compaction.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/backend/access/aocs/aocs_compaction.c b/src/backend/access/aocs/aocs_compaction.c
index 34ac15cfe8..2dec50319f 100644
--- a/src/backend/access/aocs/aocs_compaction.c
+++ b/src/backend/access/aocs/aocs_compaction.c
@@ -118,8 +118,6 @@ AOCSSegmentFileTruncateToEOF(Relation aorel, int segno, AOCSVPInfo *vpinfo, AOVa
Assert(RelationIsAoCols(aorel));
- relname = RelationGetRelationName(aorel);
-
for (j = 0; j < vpinfo->nEntry; ++j)
{
int64 segeof;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org