diff --git a/src/backend/access/aocs/aocsam.c b/src/backend/access/aocs/aocsam.c index 870cfbe4b9e..267dd837697 100644 --- a/src/backend/access/aocs/aocsam.c +++ b/src/backend/access/aocs/aocsam.c @@ -1012,6 +1012,7 @@ aocs_insert_init(Relation rel, int segno) desc = (AOCSInsertDesc) palloc0(sizeof(AOCSInsertDescData)); desc->aoi_rel = rel; desc->appendOnlyMetaDataSnapshot = RegisterSnapshot(GetCatalogSnapshot(InvalidOid)); + desc->insertMultiFiles = false; /* * Writers uses this since they have exclusive access to the lock acquired @@ -1072,10 +1073,9 @@ aocs_insert_init(Relation rel, int segno) (FileSegInfo *) desc->fsInfo, desc->lastSequence, rel, segno, tupleDesc->natts, true); - /* should not enable insertMultiFiles if the table is created by own transaction */ - desc->insertMultiFiles = enable_parallel && - gp_appendonly_insert_files > 1 && - !ShouldUseReservedSegno(rel, CHOOSE_MODE_WRITE); + /* Should not enable insertMultiFiles if the table is created by own transaction or in utility mode */ + if (Gp_role != GP_ROLE_UTILITY) + desc->insertMultiFiles = gp_appendonly_insert_files > 1 && !ShouldUseReservedSegno(rel, CHOOSE_MODE_WRITE); return desc; } diff --git a/src/backend/access/appendonly/appendonlyam.c b/src/backend/access/appendonly/appendonlyam.c index b5993e30f4f..4d84e957026 100755 --- a/src/backend/access/appendonly/appendonlyam.c +++ b/src/backend/access/appendonly/appendonlyam.c @@ -2664,6 +2664,7 @@ appendonly_insert_init(Relation rel, int segno) aoInsertDesc->aoi_rel = rel; aoInsertDesc->range = 0; + aoInsertDesc->insertMultiFiles = false; /* * We want to see an up-to-date view of the metadata. The target segment's @@ -2851,10 +2852,9 @@ aoInsertDesc->appendOnlyMetaDataSnapshot, //CONCERN:Safe to assume all block dir aoInsertDesc->fsInfo, aoInsertDesc->lastSequence, rel, segno, 1, false); - /* should not enable insertMultiFiles if the table is created by own transaction */ - aoInsertDesc->insertMultiFiles = enable_parallel && - gp_appendonly_insert_files > 1 && - !ShouldUseReservedSegno(rel, CHOOSE_MODE_WRITE); + /* Should not enable insertMultiFiles if the table is created by own transaction or in utility mode */ + if (Gp_role != GP_ROLE_UTILITY) + aoInsertDesc->insertMultiFiles = gp_appendonly_insert_files > 1 && !ShouldUseReservedSegno(rel, CHOOSE_MODE_WRITE); return aoInsertDesc; } diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 53cb6e9d6a8..2e39cea261c 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -3177,7 +3177,7 @@ struct config_int ConfigureNamesInt_gp[] = NULL }, &gp_appendonly_insert_files, - 4, 0, 127, + 4 /* CBDB_PARALLEL If default value is changed, set it in src/test/regress/GNUMakefile too, see details there */, 0, 127, NULL, NULL, NULL }, diff --git a/src/test/isolation2/Makefile b/src/test/isolation2/Makefile index 0fed5742cd6..aec939457e7 100644 --- a/src/test/isolation2/Makefile +++ b/src/test/isolation2/Makefile @@ -63,7 +63,11 @@ clean distclean: install: all gpdiff.pl gpstringsubs.pl installcheck: install installcheck-parallel-retrieve-cursor - $(pg_isolation2_regress_installcheck) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_isolation2 --schedule=$(srcdir)/isolation2_schedule + (\ + gpconfig -c gp_appendonly_insert_files -v 0; \ + gpstop -u; \ + $(pg_isolation2_regress_installcheck) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_isolation2 --schedule=$(srcdir)/isolation2_schedule \ + ) installcheck-resgroup: install $(pg_isolation2_regress_installcheck) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_resgroup --dbname=isolation2resgrouptest --schedule=$(srcdir)/isolation2_resgroup_schedule @@ -74,6 +78,8 @@ installcheck-parallel-retrieve-cursor: install # Add a new rule for running installcheck with parallel mode enabled. installcheck-cbdb-parallel: install (\ - export PGOPTIONS='-c optimizer=off -c enable_parallel=true -c gp_appendonly_insert_files=0'; \ + gpconfig -c gp_appendonly_insert_files -v 0; \ + gpstop -u; \ + export PGOPTIONS='-c optimizer=off -c enable_parallel=true'; \ $(pg_isolation2_regress_installcheck) --init-file=$(top_builddir)/src/test/regress/init_file --init-file=./init_file_isolation2 --schedule=$(srcdir)/isolation2_schedule \ ) \ No newline at end of file diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile index 70dddce82aa..d16d70385a5 100644 --- a/src/test/regress/GNUmakefile +++ b/src/test/regress/GNUmakefile @@ -204,8 +204,18 @@ installcheck: installcheck-good installcheck-small: all $(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(EXTRA_TESTS) +# We have set default gp_appendonly_insert_files = 4 for user's underlying parallelism. +# But that will cause lots of diffs between non-parallel and parallel mode that we can't +# afford to modify them one by one, or create lots of answer files(and we didn't support that yet). +# Any tests related to ao parallel should set GUCs in their own sql files, like gp_parallel. +# Using gpconfig is a workaround for regression test for non-parallel and parallel mode. +# Same for src/test/isolation2/Makefile installcheck-good: all twophase_pqexecparams hooktest query_info_hook_test - $(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule --schedule=$(srcdir)/greenplum_schedule $(EXTRA_TESTS) + (\ + gpconfig -c gp_appendonly_insert_files -v 0; \ + gpstop -u; \ + $(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule --schedule=$(srcdir)/greenplum_schedule $(EXTRA_TESTS) \ + ) installcheck-parallel: all $(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(MAXCONNOPT) $(EXTRA_TESTS) diff --git a/src/test/regress/expected/gp_parallel.out b/src/test/regress/expected/gp_parallel.out index 306c1119bb3..04e8184f622 100644 --- a/src/test/regress/expected/gp_parallel.out +++ b/src/test/regress/expected/gp_parallel.out @@ -35,6 +35,8 @@ set force_parallel_mode = 0; set optimizer = off; create schema test_parallel; set search_path to test_parallel; +-- set this to default in case regress change it by gpstop. +set gp_appendonly_insert_files = 4; create table ao1(x int, y int) with(appendonly=true); 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. @@ -48,7 +50,8 @@ begin; -- encourage use of parallel plans set local min_parallel_table_scan_size = 0; set local max_parallel_workers_per_gather = 4; -set local enable_parallel = true; +-- test insert into multiple files even enable_parallel is off. +set local enable_parallel = off; -- insert multiple segfiles for parallel set local gp_appendonly_insert_files = 4; -- test appendonly table parallel @@ -62,6 +65,7 @@ select segfilecount from pg_appendonly where relid = 'ao1'::regclass; 4 (1 row) +set local enable_parallel = on; explain(costs off) select count(*) from ao1; QUERY PLAN -------------------------------------------------- @@ -79,6 +83,7 @@ select count(*) from ao1; (1 row) -- test aocs table parallel +set local enable_parallel = off; insert into aocs1 select i, i from generate_series(1, 1200000) g(i); analyze aocs1; select segfilecount from pg_appendonly where relid = 'aocs1'::regclass; @@ -87,6 +92,7 @@ select segfilecount from pg_appendonly where relid = 'aocs1'::regclass; 4 (1 row) +set local enable_parallel = on; explain(costs off) select count(*) from aocs1; QUERY PLAN -------------------------------------------------- @@ -1698,5 +1704,6 @@ abort; -- start_ignore drop schema test_parallel cascade; -- end_ignore +reset gp_appendonly_insert_files; reset force_parallel_mode; reset optimizer; diff --git a/src/test/regress/sql/gp_parallel.sql b/src/test/regress/sql/gp_parallel.sql index 6b68b31ebae..e52226a68b9 100644 --- a/src/test/regress/sql/gp_parallel.sql +++ b/src/test/regress/sql/gp_parallel.sql @@ -36,6 +36,8 @@ set optimizer = off; create schema test_parallel; set search_path to test_parallel; +-- set this to default in case regress change it by gpstop. +set gp_appendonly_insert_files = 4; create table ao1(x int, y int) with(appendonly=true); create table ao2(x int, y int) with(appendonly=true); @@ -46,7 +48,8 @@ begin; -- encourage use of parallel plans set local min_parallel_table_scan_size = 0; set local max_parallel_workers_per_gather = 4; -set local enable_parallel = true; +-- test insert into multiple files even enable_parallel is off. +set local enable_parallel = off; -- insert multiple segfiles for parallel set local gp_appendonly_insert_files = 4; @@ -57,13 +60,16 @@ analyze ao1; insert into ao2 select i%10, i from generate_series(1, 1200000) g(i); analyze ao2; select segfilecount from pg_appendonly where relid = 'ao1'::regclass; +set local enable_parallel = on; explain(costs off) select count(*) from ao1; select count(*) from ao1; -- test aocs table parallel +set local enable_parallel = off; insert into aocs1 select i, i from generate_series(1, 1200000) g(i); analyze aocs1; select segfilecount from pg_appendonly where relid = 'aocs1'::regclass; +set local enable_parallel = on; explain(costs off) select count(*) from aocs1; select count(*) from aocs1; @@ -508,5 +514,6 @@ abort; drop schema test_parallel cascade; -- end_ignore +reset gp_appendonly_insert_files; reset force_parallel_mode; reset optimizer;