Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions contrib/pax_storage/expected/delete_sum_stats.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- Verify that DELETE statistics refresh uses the SUM result type when
-- deserializing and merging stats. In particular, sum(bigint) returns numeric.
set pax.max_tuples_per_group = 25;
create table pax_delete_sum_stats (
dist_key int,
id bigint,
int_amount int,
bigint_amount bigint,
numeric_amount numeric
)
using pax
with (minmax_columns = 'int_amount,bigint_amount,numeric_amount')
distributed by (dist_key);
insert into pax_delete_sum_stats
select 1, i, i, i, i::numeric * 2
from generate_series(1, 1000) i;
select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;
rows | int_sum | bigint_sum | numeric_sum
------+---------+------------+-------------
1000 | 500500 | 500500 | 1001000
(1 row)

delete from pax_delete_sum_stats where id between 1 and 100;
select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;
rows | int_sum | bigint_sum | numeric_sum
------+---------+------------+-------------
900 | 495450 | 495450 | 990900
(1 row)

insert into pax_delete_sum_stats
select 1, i, i, i, i::numeric * 2
from generate_series(1001, 1100) i;
delete from pax_delete_sum_stats where id between 301 and 400;
select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;
rows | int_sum | bigint_sum | numeric_sum
------+---------+------------+-------------
900 | 565450 | 565450 | 1130900
(1 row)

drop table pax_delete_sum_stats;
reset pax.max_tuples_per_group;
1 change: 1 addition & 0 deletions contrib/pax_storage/pax_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test: statistics_bloom_filter
test: filter_tree filter_tree_arithmetic
test: filter_tree_root_quals
test: statistics/statistics
test: delete_sum_stats
test: statistics/min_max_time_types statistics/min_max_text_types statistics/min_max_other_types statistics/min_max_net_types statistics/min_max_int_types statistics/min_max_geo_types statistics/min_max_float_types statistics/min_max_bit_byte_types


Expand Down
47 changes: 47 additions & 0 deletions contrib/pax_storage/sql/delete_sum_stats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- Verify that DELETE statistics refresh uses the SUM result type when
-- deserializing and merging stats. In particular, sum(bigint) returns numeric.
set pax.max_tuples_per_group = 25;

create table pax_delete_sum_stats (
dist_key int,
id bigint,
int_amount int,
bigint_amount bigint,
numeric_amount numeric
)
using pax
with (minmax_columns = 'int_amount,bigint_amount,numeric_amount')
distributed by (dist_key);

insert into pax_delete_sum_stats
select 1, i, i, i, i::numeric * 2
from generate_series(1, 1000) i;

select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;

delete from pax_delete_sum_stats where id between 1 and 100;

select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;

insert into pax_delete_sum_stats
select 1, i, i, i, i::numeric * 2
from generate_series(1001, 1100) i;

delete from pax_delete_sum_stats where id between 301 and 400;

select count(*) as rows,
sum(int_amount) as int_sum,
sum(bigint_amount) as bigint_sum,
sum(numeric_amount) as numeric_sum
from pax_delete_sum_stats;

drop table pax_delete_sum_stats;
reset pax.max_tuples_per_group;
10 changes: 5 additions & 5 deletions contrib/pax_storage/src/cpp/storage/micro_partition_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,19 +758,19 @@ void MicroPartitionStats::MergeRawInfo(
} else if (sum_stat->status == STATUS_NEED_UPDATE) {
sum_result =
FromValue(stats_info->columnstats(column_index).datastats().sum(),
typlen, typbyval, column_index);
sum_stat->rettyplen, sum_stat->rettypbyval, column_index);
Datum newval = cbdb::FunctionCall2Coll(&sum_stat->add_func, InvalidOid,
sum_stat->result, sum_result);
if (!sum_stat->rettypbyval && newval != sum_stat->result &&
sum_stat->result) {
cbdb::Pfree(cbdb::DatumToPointer(sum_stat->result));
}
sum_stat->result =
cbdb::datumCopy(newval, sum_stat->rettyplen, sum_stat->rettypbyval);
cbdb::datumCopy(newval, sum_stat->rettypbyval, sum_stat->rettyplen);
} else if (sum_stat->status == STATUS_MISSING_INIT_VAL) {
sum_result =
FromValue(stats_info->columnstats(column_index).datastats().sum(),
typlen, typbyval, column_index);
sum_stat->rettyplen, sum_stat->rettypbyval, column_index);
sum_stat->result = cbdb::datumCopy(sum_result, sum_stat->rettypbyval,
sum_stat->rettyplen);
sum_stat->status = STATUS_NEED_UPDATE;
Expand Down Expand Up @@ -966,8 +966,8 @@ void MicroPartitionStats::MergeTo(MicroPartitionStats *stats) {
left_sum_stat->result) {
cbdb::Pfree(cbdb::DatumToPointer(left_sum_stat->result));
}
left_sum_stat->result = cbdb::datumCopy(newval, left_sum_stat->rettyplen,
left_sum_stat->rettypbyval);
left_sum_stat->result = cbdb::datumCopy(
newval, left_sum_stat->rettypbyval, left_sum_stat->rettyplen);
} else if (left_sum_stat->status == STATUS_MISSING_INIT_VAL) {
left_sum_stat->result =
cbdb::datumCopy(right_sum_stat->result, left_sum_stat->rettypbyval,
Expand Down
Loading