Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ CREATE
-- verify_cpu_usage: calculate each QE's average cpu usage using all the data in
-- the table cpu_usage_sample. And compare the average value to the expected value.
-- return true if the practical value is close to the expected value.
CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage INT, err_rate INT) RETURNS BOOL AS $$ import json import functools
all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM cpu_usage_samples '''.format(name=groupname)) usage = float(all_info[0]['cpu'])
CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage INT, err_rate INT) RETURNS BOOL AS $$ import json
all_info = plpy.execute(''' SELECT sample::json->'{name}' AS cpu FROM cpu_usage_samples '''.format(name=groupname)) usage = sum(float(row['cpu']) for row in all_info) / len(all_info)
return abs(usage - expect_cpu_usage) <= err_rate $$ LANGUAGE plpython3u;
CREATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ $$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION verify_cpu_usage(groupname TEXT, expect_cpu_usage INT, err_rate INT)
RETURNS BOOL AS $$
import json
import functools

all_info = plpy.execute('''
SELECT sample::json->'{name}' AS cpu FROM cpu_usage_samples
'''.format(name=groupname))
usage = float(all_info[0]['cpu'])
usage = sum(float(row['cpu']) for row in all_info) / len(all_info)

return abs(usage - expect_cpu_usage) <= err_rate
$$ LANGUAGE plpython3u;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- start_matchsubs
-- m/\(cluster.c:\d+\)/
-- s/\(cluster.c:\d+\)/\(cluster.c:###\)/
-- end_matchsubs
-- ALTER TABLE ... SET DISTRIBUTED BY
-- This is the main interface for system expansion
\set DATA values(1, 2), (2, 3), (3, 4)
Expand Down Expand Up @@ -171,7 +175,7 @@ ERROR: permission denied: "pg_class" is a system catalog
create table atsdb (i int, j text) distributed by (j);
insert into atsdb select i, i::text from generate_series(1, 10) i;
alter table atsdb set with(appendonly = true);
ERROR: PAX not allow swap relation files for different AM (cluster.c:1535)
ERROR: PAX not allow swap relation files for different AM (cluster.c:###)
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
relname | ?column? | reloptions
Expand Down Expand Up @@ -316,7 +320,7 @@ select * from distcheck where rel = 'atsdb';

alter table atsdb drop column n;
alter table atsdb set with(appendonly = true, compresslevel = 3);
ERROR: PAX not allow swap relation files for different AM (cluster.c:1535)
ERROR: PAX not allow swap relation files for different AM (cluster.c:###)
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
relname | ?column? | reloptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- start_matchsubs
-- m/\(cluster.c:\d+\)/
-- s/\(cluster.c:\d+\)/\(cluster.c:###\)/
-- end_matchsubs
-- ALTER TABLE ... SET DISTRIBUTED BY
-- This is the main interface for system expansion
\set DATA values(1, 2), (2, 3), (3, 4)
Expand Down Expand Up @@ -171,7 +175,7 @@ ERROR: permission denied: "pg_class" is a system catalog
create table atsdb (i int, j text) distributed by (j);
insert into atsdb select i, i::text from generate_series(1, 10) i;
alter table atsdb set with(appendonly = true);
ERROR: PAX not allow swap relation files for different AM (cluster.c:1535)
ERROR: PAX not allow swap relation files for different AM (cluster.c:###)
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
relname | ?column? | reloptions
Expand Down Expand Up @@ -316,7 +320,7 @@ select * from distcheck where rel = 'atsdb';

alter table atsdb drop column n;
alter table atsdb set with(appendonly = true, compresslevel = 3);
ERROR: PAX not allow swap relation files for different AM (cluster.c:1535)
ERROR: PAX not allow swap relation files for different AM (cluster.c:###)
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
relname | ?column? | reloptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ CREATE FUNCTION recreate_two_level_table() RETURNS VOID
PARTITION r2 START (5) END (8)
);
$fn$;
-- clean up any leftover table from other tests
SET client_min_messages TO warning;
DROP TABLE IF EXISTS r;
RESET client_min_messages;
-- validate that there are no constraints when we start
SELECT * FROM partition_tables_show_all('r');
ERROR: relation "r" does not exist
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- start_matchsubs
-- m/\(cluster.c:\d+\)/
-- s/\(cluster.c:\d+\)/\(cluster.c:###\)/
-- end_matchsubs
-- ALTER TABLE ... SET DISTRIBUTED BY
-- This is the main interface for system expansion
\set DATA values(1, 2), (2, 3), (3, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ CREATE FUNCTION recreate_two_level_table() RETURNS VOID
);
$fn$;

-- clean up any leftover table from other tests
SET client_min_messages TO warning;
DROP TABLE IF EXISTS r;
RESET client_min_messages;
-- validate that there are no constraints when we start
SELECT * FROM partition_tables_show_all('r');

Expand Down
29 changes: 5 additions & 24 deletions src/backend/access/aocs/aocsam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1462,8 +1462,6 @@ aoco_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
int natts;
Datum *values;
bool *isnull;
TransactionId FreezeXid;
MultiXactId MultiXactCutoff;
Tuplesortstate *tuplesort;
PGRUsage ru0;

Expand Down Expand Up @@ -1523,29 +1521,12 @@ aoco_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
Assert(RelationGetTargetBlock(NewHeap) == InvalidBlockNumber);

/*
* Compute sane values for FreezeXid and CutoffMulti with regular
* VACUUM machinery to avoidconfising existing CLUSTER code.
* AO/AOCO tables have no per-tuple xmin/xmax, so freeze limits don't
* apply. Return Invalid values so that relfrozenxid and relminmxid
* remain unchanged after CLUSTER.
*/
vacuum_set_xid_limits(OldHeap, 0, 0, 0, 0,
&OldestXmin, &FreezeXid, NULL, &MultiXactCutoff,
NULL);

/*
* FreezeXid will become the table's new relfrozenxid, and that mustn't go
* backwards, so take the max.
*/
if (TransactionIdPrecedes(FreezeXid, OldHeap->rd_rel->relfrozenxid))
FreezeXid = OldHeap->rd_rel->relfrozenxid;

/*
* MultiXactCutoff, similarly, shouldn't go backwards either.
*/
if (MultiXactIdPrecedes(MultiXactCutoff, OldHeap->rd_rel->relminmxid))
MultiXactCutoff = OldHeap->rd_rel->relminmxid;

/* return selected values to caller */
*xid_cutoff = FreezeXid;
*multi_cutoff = MultiXactCutoff;
*xid_cutoff = InvalidTransactionId;
*multi_cutoff = InvalidMultiXactId;

tuplesort = tuplesort_begin_cluster(oldTupDesc, OldIndex,
maintenance_work_mem, NULL, false);
Expand Down
29 changes: 5 additions & 24 deletions src/backend/access/appendonly/appendonlyam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,6 @@ appendonly_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
int natts;
Datum *values;
bool *isnull;
TransactionId FreezeXid;
MultiXactId MultiXactCutoff;
Tuplesortstate *tuplesort;
PGRUsage ru0;

Expand Down Expand Up @@ -1380,29 +1378,12 @@ appendonly_relation_copy_for_cluster(Relation OldHeap, Relation NewHeap,
Assert(RelationGetTargetBlock(NewHeap) == InvalidBlockNumber);

/*
* Compute sane values for FreezeXid and CutoffMulti with regular
* VACUUM machinery to avoidconfising existing CLUSTER code.
* AO/AOCO tables have no per-tuple xmin/xmax, so freeze limits don't
* apply. Return Invalid values so that relfrozenxid and relminmxid
* remain unchanged after CLUSTER.
*/
vacuum_set_xid_limits(OldHeap, 0, 0, 0, 0,
&OldestXmin, &FreezeXid, NULL, &MultiXactCutoff,
NULL);

/*
* FreezeXid will become the table's new relfrozenxid, and that mustn't go
* backwards, so take the max.
*/
if (TransactionIdPrecedes(FreezeXid, OldHeap->rd_rel->relfrozenxid))
FreezeXid = OldHeap->rd_rel->relfrozenxid;

/*
* MultiXactCutoff, similarly, shouldn't go backwards either.
*/
if (MultiXactIdPrecedes(MultiXactCutoff, OldHeap->rd_rel->relminmxid))
MultiXactCutoff = OldHeap->rd_rel->relminmxid;

/* return selected values to caller */
*xid_cutoff = FreezeXid;
*multi_cutoff = MultiXactCutoff;
*xid_cutoff = InvalidTransactionId;
*multi_cutoff = InvalidMultiXactId;

tuplesort = tuplesort_begin_cluster(oldTupDesc, OldIndex,
maintenance_work_mem, NULL, false);
Expand Down
13 changes: 10 additions & 3 deletions src/backend/commands/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,17 +1486,24 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
Assert(!TransactionIdIsValid(frozenXid) ||
TransactionIdIsNormal(frozenXid));
relform1->relfrozenxid = frozenXid;
Assert(MultiXactIdIsValid(cutoffMulti));
Assert(!MultiXactIdIsValid(cutoffMulti) ||
MultiXactIdPrecedesOrEquals(FirstMultiXactId, cutoffMulti));
relform1->relminmxid = cutoffMulti;
}
/*
* Cloudberry: append-optimized tables do not have a valid relfrozenxid.
* Overwrite the entry for both relations.
* Cloudberry: append-optimized tables do not have a valid relfrozenxid
* or relminmxid. Overwrite the entry for both relations.
*/
if (relform1->relkind != RELKIND_INDEX && IsAccessMethodAO(relform1->relam))
{
relform1->relfrozenxid = InvalidTransactionId;
relform1->relminmxid = InvalidMultiXactId;
}
if (relform2->relkind != RELKIND_INDEX && IsAccessMethodAO(relform2->relam))
{
relform2->relfrozenxid = InvalidTransactionId;
relform2->relminmxid = InvalidMultiXactId;
}

/* swap size statistics too, since new rel has freshly-updated stats */
if (swap_stats)
Expand Down
Loading