You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by re...@apache.org on 2025/01/09 12:11:42 UTC

(cloudberry) 04/05: brin ao/co: Improve summarize tests

This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit a0ab44f026e7df52f690e0b2609e6ef6fd1a1646
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Mon Feb 27 14:39:05 2023 -0800

    brin ao/co: Improve summarize tests
    
    Add a dedicated section to test summarization for BRIN indexes on AO/CO
    tables. Add more commentary and coverage.
---
 src/test/regress/expected/brin.out                 |   6 +-
 src/test/regress/expected/brin_ao.out              | 101 ++++++++++---
 src/test/regress/expected/brin_ao_optimizer.out    | 103 ++++++++++---
 src/test/regress/expected/brin_aocs.out            | 158 ++++++++++----------
 src/test/regress/expected/brin_aocs_optimizer.out  | 160 +++++++++++----------
 src/test/regress/expected/brin_bloom.out           |  23 ++-
 src/test/regress/expected/brin_bloom_optimizer.out |  23 ++-
 src/test/regress/expected/brin_multi.out           |  21 ++-
 src/test/regress/expected/brin_multi_optimizer.out |  20 ++-
 .../regress/expected/brin_multi_optimizer_1.out    |  21 ++-
 src/test/regress/expected/brin_optimizer.out       |   6 +-
 src/test/regress/sql/brin_ao.sql                   |  81 +++++++++--
 src/test/regress/sql/brin_aocs.sql                 |  81 +++++++++--
 src/test/singlenode_regress/expected/brin.out      |  26 +++-
 .../singlenode_regress/expected/brin_bloom.out     |  23 ++-
 .../singlenode_regress/expected/brin_multi.out     |  20 ++-
 .../singlenode_regress/expected/privileges.out     |   7 +-
 17 files changed, 620 insertions(+), 260 deletions(-)

diff --git a/src/test/regress/expected/brin.out b/src/test/regress/expected/brin.out
index e4984c2470..4a3152a3ef 100644
--- a/src/test/regress/expected/brin.out
+++ b/src/test/regress/expected/brin.out
@@ -543,7 +543,11 @@ SELECT brin_desummarize_range('brinidx', 0);
 (1 row)
 
 SELECT brin_summarize_range('brinidx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 DROP TABLE brintest_2;
 -- test brin cost estimates behave sanely based on correlation of values
 -- GPDB: use more rows, and a larger statistics sample, to get the same plan
diff --git a/src/test/regress/expected/brin_ao.out b/src/test/regress/expected/brin_ao.out
index e299fd17a2..b65a03a5f3 100644
--- a/src/test/regress/expected/brin_ao.out
+++ b/src/test/regress/expected/brin_ao.out
@@ -1,5 +1,6 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
+-- Test scan correctness
 CREATE TABLE brintest_ao (id int,
 	byteacol bytea,
 	charcol "char",
@@ -445,23 +446,16 @@ INSERT INTO brintest_ao SELECT
 	format('%s/%s%s', odd, even, tenthous)::pg_lsn,
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
-VACUUM brintest_ao;  -- force a summarization cycle in brinaoidx
-UPDATE brintest_ao SET int8col = int8col * int4col;
-UPDATE brintest_ao SET textcol = '' WHERE textcol IS NOT NULL;
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_ao;
-INSERT INTO brintest_ao SELECT * FROM brintest_ao;
--- We should have two segment files.
-SELECT segment_id, segno FROM gp_toolkit.__gp_aoseg('brintest_ao');
- segment_id | segno 
-------------+-------
-          1 |     1
-          1 |     2
-(2 rows)
-
+-- Test summarization
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
+CREATE TABLE brin_ao_summarize(i int) USING ao_row;
+NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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 INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_ao'); -- error, not an index
-ERROR:  "brintest_ao" is not an index
+SELECT brin_summarize_new_values('brin_ao_summarize'); -- error, not an index
+ERROR:  "brin_ao_summarize" is not an index
 CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 ERROR:  "tenk1_unique1" is not a BRIN index
@@ -470,13 +464,82 @@ CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
-SELECT brin_summarize_new_values('brinaoidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+DROP INDEX brin_ao_summarize_i_idx;
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         2
+(1 row)
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+DELETE FROM brin_ao_summarize WHERE i = 1;
+VACUUM brin_ao_summarize;
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+  FROM brin_ao_summarize;
+  blknum  
+----------
+ 67108864
+(1 row)
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
  brin_summarize_new_values 
 ---------------------------
                          0
 (1 row)
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaoidx', 1);
-ERROR:  cannot summarize specific page range for append-optimized tables  (seg0 slice1 192.168.0.148:7002 pid=2970354)
+SELECT brin_summarize_range('brin_ao_summarize_i_idx', 1);
+ERROR:  cannot summarize specific page range for append-optimized tables  (seg2 slice1 192.168.0.148:7004 pid=25354)
 CONTEXT:  SQL function "brin_summarize_range" statement 1
diff --git a/src/test/regress/expected/brin_ao_optimizer.out b/src/test/regress/expected/brin_ao_optimizer.out
index 3802537410..47073d2923 100644
--- a/src/test/regress/expected/brin_ao_optimizer.out
+++ b/src/test/regress/expected/brin_ao_optimizer.out
@@ -1,5 +1,6 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
+-- Test scan correctness
 CREATE TABLE brintest_ao (id int,
 	byteacol bytea,
 	charcol "char",
@@ -463,23 +464,16 @@ INSERT INTO brintest_ao SELECT
 	format('%s/%s%s', odd, even, tenthous)::pg_lsn,
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
-VACUUM brintest_ao;  -- force a summarization cycle in brinaoidx
-UPDATE brintest_ao SET int8col = int8col * int4col;
-UPDATE brintest_ao SET textcol = '' WHERE textcol IS NOT NULL;
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_ao;
-INSERT INTO brintest_ao SELECT * FROM brintest_ao;
--- We should have two segment files.
-SELECT segment_id, segno FROM gp_toolkit.__gp_aoseg('brintest_ao');
- segment_id | segno 
-------------+-------
-          1 |     1
-          1 |     2
-(2 rows)
-
+-- Test summarization
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
+CREATE TABLE brin_ao_summarize(i int) USING ao_row;
+NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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 INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_ao'); -- error, not an index
-ERROR:  "brintest_ao" is not an index
+SELECT brin_summarize_new_values('brin_ao_summarize'); -- error, not an index
+ERROR:  "brin_ao_summarize" is not an index
 CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 ERROR:  "tenk1_unique1" is not a BRIN index
@@ -488,13 +482,84 @@ CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
-SELECT brin_summarize_new_values('brinaoidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+DROP INDEX brin_ao_summarize_i_idx;
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         2
+(1 row)
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+DELETE FROM brin_ao_summarize WHERE i = 1;
+VACUUM brin_ao_summarize;
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+  FROM brin_ao_summarize;
+NOTICE:  One or more columns in the following table(s) do not have statistics: brin_ao_summarize
+HINT:  For non-partitioned tables, run analyze <table_name>(<column_list>). For partitioned tables, run analyze rootpartition <table_name>(<column_list>). See log for columns missing statistics.
+  blknum  
+----------
+ 67108864
+(1 row)
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
  brin_summarize_new_values 
 ---------------------------
                          0
 (1 row)
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaoidx', 1);
-ERROR:  cannot summarize specific page range for append-optimized tables  (seg0 slice1 192.168.0.148:7002 pid=3012326)
+SELECT brin_summarize_range('brin_ao_summarize_i_idx', 1);
+ERROR:  cannot summarize specific page range for append-optimized tables  (seg0 slice1 192.168.0.148:7002 pid=20357)
 CONTEXT:  SQL function "brin_summarize_range" statement 1
diff --git a/src/test/regress/expected/brin_aocs.out b/src/test/regress/expected/brin_aocs.out
index c29a8781b2..6626179657 100644
--- a/src/test/regress/expected/brin_aocs.out
+++ b/src/test/regress/expected/brin_aocs.out
@@ -1,5 +1,6 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
+-- Test scan correctness
 CREATE TABLE brintest_aocs (id int,
 	byteacol bytea,
 	charcol "char",
@@ -445,79 +446,16 @@ INSERT INTO brintest_aocs SELECT
 	format('%s/%s%s', odd, even, tenthous)::pg_lsn,
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
-VACUUM brintest_aocs;  -- force a summarization cycle in brinaocsidx
-UPDATE brintest_aocs SET int8col = int8col * int4col;
-UPDATE brintest_aocs SET textcol = '' WHERE textcol IS NOT NULL;
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_aocs;
-INSERT INTO brintest_aocs SELECT * FROM brintest_aocs;
--- We should have two segment files.
-SELECT segment_id, segno, column_num FROM gp_toolkit.__gp_aocsseg('brintest_aocs');
- segment_id | segno | column_num 
-------------+-------+------------
-          1 |     1 |          0
-          1 |     1 |          1
-          1 |     1 |          2
-          1 |     1 |          3
-          1 |     1 |          4
-          1 |     1 |          5
-          1 |     1 |          6
-          1 |     1 |          7
-          1 |     1 |          8
-          1 |     1 |          9
-          1 |     1 |         10
-          1 |     1 |         11
-          1 |     1 |         12
-          1 |     1 |         13
-          1 |     1 |         14
-          1 |     1 |         15
-          1 |     1 |         16
-          1 |     1 |         17
-          1 |     1 |         18
-          1 |     1 |         19
-          1 |     1 |         20
-          1 |     1 |         21
-          1 |     1 |         22
-          1 |     1 |         23
-          1 |     1 |         24
-          1 |     1 |         25
-          1 |     1 |         26
-          1 |     1 |         27
-          1 |     1 |         28
-          1 |     2 |          0
-          1 |     2 |          1
-          1 |     2 |          2
-          1 |     2 |          3
-          1 |     2 |          4
-          1 |     2 |          5
-          1 |     2 |          6
-          1 |     2 |          7
-          1 |     2 |          8
-          1 |     2 |          9
-          1 |     2 |         10
-          1 |     2 |         11
-          1 |     2 |         12
-          1 |     2 |         13
-          1 |     2 |         14
-          1 |     2 |         15
-          1 |     2 |         16
-          1 |     2 |         17
-          1 |     2 |         18
-          1 |     2 |         19
-          1 |     2 |         20
-          1 |     2 |         21
-          1 |     2 |         22
-          1 |     2 |         23
-          1 |     2 |         24
-          1 |     2 |         25
-          1 |     2 |         26
-          1 |     2 |         27
-          1 |     2 |         28
-(58 rows)
-
+-- Test summarization
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
+CREATE TABLE brin_aoco_summarize(i int) USING ao_column;
+NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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 INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_aocs'); -- error, not an index
-ERROR:  "brintest_aocs" is not an index
+SELECT brin_summarize_new_values('brin_aoco_summarize'); -- error, not an index
+ERROR:  "brin_aoco_summarize" is not an index
 CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 ERROR:  "tenk1_unique1" is not a BRIN index
@@ -526,14 +464,82 @@ CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
--- start_ignore
-SELECT brin_summarize_new_values('brinaocsidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+DROP INDEX brin_aoco_summarize_i_idx;
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         2
+(1 row)
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+DELETE FROM brin_aoco_summarize WHERE i = 1;
+VACUUM brin_aoco_summarize;
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+FROM brin_aoco_summarize;
+  blknum  
+----------
+ 67108864
+(1 row)
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
  brin_summarize_new_values 
 ---------------------------
                          0
 (1 row)
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaocsidx', 1);
-ERROR:  cannot summarize specific page range for append-optimized tables  (seg1 slice1 192.168.0.148:7003 pid=3047874)
+SELECT brin_summarize_range('brin_aoco_summarize_i_idx', 1);
+ERROR:  cannot summarize specific page range for append-optimized tables  (seg0 slice1 192.168.0.148:7002 pid=67650)
 CONTEXT:  SQL function "brin_summarize_range" statement 1
diff --git a/src/test/regress/expected/brin_aocs_optimizer.out b/src/test/regress/expected/brin_aocs_optimizer.out
index 270068e711..0a33c7ba89 100644
--- a/src/test/regress/expected/brin_aocs_optimizer.out
+++ b/src/test/regress/expected/brin_aocs_optimizer.out
@@ -1,5 +1,6 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
+-- Test scan correctness
 CREATE TABLE brintest_aocs (id int,
 	byteacol bytea,
 	charcol "char",
@@ -463,79 +464,16 @@ INSERT INTO brintest_aocs SELECT
 	format('%s/%s%s', odd, even, tenthous)::pg_lsn,
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
-VACUUM brintest_aocs;  -- force a summarization cycle in brinaocsidx
-UPDATE brintest_aocs SET int8col = int8col * int4col;
-UPDATE brintest_aocs SET textcol = '' WHERE textcol IS NOT NULL;
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_aocs;
-INSERT INTO brintest_aocs SELECT * FROM brintest_aocs;
--- We should have two segment files.
-SELECT segment_id, segno, column_num FROM gp_toolkit.__gp_aocsseg('brintest_aocs');
- segment_id | segno | column_num 
-------------+-------+------------
-          1 |     1 |          0
-          1 |     1 |          1
-          1 |     1 |          2
-          1 |     1 |          3
-          1 |     1 |          4
-          1 |     1 |          5
-          1 |     1 |          6
-          1 |     1 |          7
-          1 |     1 |          8
-          1 |     1 |          9
-          1 |     1 |         10
-          1 |     1 |         11
-          1 |     1 |         12
-          1 |     1 |         13
-          1 |     1 |         14
-          1 |     1 |         15
-          1 |     1 |         16
-          1 |     1 |         17
-          1 |     1 |         18
-          1 |     1 |         19
-          1 |     1 |         20
-          1 |     1 |         21
-          1 |     1 |         22
-          1 |     1 |         23
-          1 |     1 |         24
-          1 |     1 |         25
-          1 |     1 |         26
-          1 |     1 |         27
-          1 |     1 |         28
-          1 |     2 |          0
-          1 |     2 |          1
-          1 |     2 |          2
-          1 |     2 |          3
-          1 |     2 |          4
-          1 |     2 |          5
-          1 |     2 |          6
-          1 |     2 |          7
-          1 |     2 |          8
-          1 |     2 |          9
-          1 |     2 |         10
-          1 |     2 |         11
-          1 |     2 |         12
-          1 |     2 |         13
-          1 |     2 |         14
-          1 |     2 |         15
-          1 |     2 |         16
-          1 |     2 |         17
-          1 |     2 |         18
-          1 |     2 |         19
-          1 |     2 |         20
-          1 |     2 |         21
-          1 |     2 |         22
-          1 |     2 |         23
-          1 |     2 |         24
-          1 |     2 |         25
-          1 |     2 |         26
-          1 |     2 |         27
-          1 |     2 |         28
-(58 rows)
-
+-- Test summarization
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
+CREATE TABLE brin_aoco_summarize(i int) USING ao_column;
+NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' 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 INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_aocs'); -- error, not an index
-ERROR:  "brintest_aocs" is not an index
+SELECT brin_summarize_new_values('brin_aoco_summarize'); -- error, not an index
+ERROR:  "brin_aoco_summarize" is not an index
 CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 ERROR:  "tenk1_unique1" is not a BRIN index
@@ -544,14 +482,84 @@ CONTEXT:  SQL function "brin_summarize_new_values" statement 1
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
--- start_ignore
-SELECT brin_summarize_new_values('brinaocsidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+DROP INDEX brin_aoco_summarize_i_idx;
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         0
+(1 row)
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+ brin_summarize_new_values 
+---------------------------
+                         2
+(1 row)
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+DELETE FROM brin_aoco_summarize WHERE i = 1;
+VACUUM brin_aoco_summarize;
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+FROM brin_aoco_summarize;
+NOTICE:  One or more columns in the following table(s) do not have statistics: brin_aoco_summarize
+HINT:  For non-partitioned tables, run analyze <table_name>(<column_list>). For partitioned tables, run analyze rootpartition <table_name>(<column_list>). See log for columns missing statistics.
+  blknum  
+----------
+ 67108864
+(1 row)
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
  brin_summarize_new_values 
 ---------------------------
                          0
 (1 row)
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaocsidx', 1);
-ERROR:  cannot summarize specific page range for append-optimized tables  (seg1 slice1 192.168.0.148:7003 pid=3082856)
+SELECT brin_summarize_range('brin_aoco_summarize_i_idx', 1);
+ERROR:  cannot summarize specific page range for append-optimized tables  (seg0 slice1 192.168.0.148:7002 pid=75014)
 CONTEXT:  SQL function "brin_summarize_range" statement 1
diff --git a/src/test/regress/expected/brin_bloom.out b/src/test/regress/expected/brin_bloom.out
index c70c6a41d1..241847a270 100644
--- a/src/test/regress/expected/brin_bloom.out
+++ b/src/test/regress/expected/brin_bloom.out
@@ -373,21 +373,30 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/regress/expected/brin_bloom_optimizer.out b/src/test/regress/expected/brin_bloom_optimizer.out
index beae9a9f64..65622f51b4 100644
--- a/src/test/regress/expected/brin_bloom_optimizer.out
+++ b/src/test/regress/expected/brin_bloom_optimizer.out
@@ -402,21 +402,30 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/regress/expected/brin_multi.out b/src/test/regress/expected/brin_multi.out
index f70283843c..51277fdb88 100644
--- a/src/test/regress/expected/brin_multi.out
+++ b/src/test/regress/expected/brin_multi.out
@@ -408,19 +408,30 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_multi_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_multi_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/regress/expected/brin_multi_optimizer.out b/src/test/regress/expected/brin_multi_optimizer.out
index db05cc5d90..39100bfeb8 100644
--- a/src/test/regress/expected/brin_multi_optimizer.out
+++ b/src/test/regress/expected/brin_multi_optimizer.out
@@ -558,19 +558,31 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_multi_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 CONTEXT:  SQL function "brin_summarize_range" statement 1
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_multi_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/regress/expected/brin_multi_optimizer_1.out b/src/test/regress/expected/brin_multi_optimizer_1.out
index 38ef6caf4e..99b3f83b1a 100644
--- a/src/test/regress/expected/brin_multi_optimizer_1.out
+++ b/src/test/regress/expected/brin_multi_optimizer_1.out
@@ -558,19 +558,30 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_multi_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_multi_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/regress/expected/brin_optimizer.out b/src/test/regress/expected/brin_optimizer.out
index 460574a4b7..627c540c38 100644
--- a/src/test/regress/expected/brin_optimizer.out
+++ b/src/test/regress/expected/brin_optimizer.out
@@ -561,7 +561,11 @@ SELECT brin_desummarize_range('brinidx', 0);
 (1 row)
 
 SELECT brin_summarize_range('brinidx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 DROP TABLE brintest_2;
 -- test brin cost estimates behave sanely based on correlation of values
 -- GPDB: use more rows, and a larger statistics sample, to get the same plan
diff --git a/src/test/regress/sql/brin_ao.sql b/src/test/regress/sql/brin_ao.sql
index b5d8b79eb5..0fb1473465 100644
--- a/src/test/regress/sql/brin_ao.sql
+++ b/src/test/regress/sql/brin_ao.sql
@@ -1,6 +1,8 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
 
+-- Test scan correctness
+
 CREATE TABLE brintest_ao (id int,
 	byteacol bytea,
 	charcol "char",
@@ -455,25 +457,82 @@ INSERT INTO brintest_ao SELECT
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
 
-VACUUM brintest_ao;  -- force a summarization cycle in brinaoidx
+-- Test summarization
 
-UPDATE brintest_ao SET int8col = int8col * int4col;
-UPDATE brintest_ao SET textcol = '' WHERE textcol IS NOT NULL;
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
 
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_ao;
-INSERT INTO brintest_ao SELECT * FROM brintest_ao;
--- We should have two segment files.
-SELECT segment_id, segno FROM gp_toolkit.__gp_aoseg('brintest_ao');
+CREATE TABLE brin_ao_summarize(i int) USING ao_row;
+CREATE INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
 
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_ao'); -- error, not an index
+SELECT brin_summarize_new_values('brin_ao_summarize'); -- error, not an index
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 -- New strategy of VACUUM AO/CO was introduced by PR #13255 for performance enhancement.
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
-SELECT brin_summarize_new_values('brinaoidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+
+DROP INDEX brin_ao_summarize_i_idx;
+
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_ao_summarize USING brin(i) WITH (pages_per_range=1);
+
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_ao_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+
+DELETE FROM brin_ao_summarize WHERE i = 1;
+
+VACUUM brin_ao_summarize;
+
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+  FROM brin_ao_summarize;
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_ao_summarize_i_idx');
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaoidx', 1);
+SELECT brin_summarize_range('brin_ao_summarize_i_idx', 1);
diff --git a/src/test/regress/sql/brin_aocs.sql b/src/test/regress/sql/brin_aocs.sql
index dee60a19fd..7267628b44 100644
--- a/src/test/regress/sql/brin_aocs.sql
+++ b/src/test/regress/sql/brin_aocs.sql
@@ -1,6 +1,8 @@
 -- Most of these test steps are modified such that the tables' tuples are
 -- co-located on one QE.
 
+-- Test scan correctness
+
 CREATE TABLE brintest_aocs (id int,
 	byteacol bytea,
 	charcol "char",
@@ -455,25 +457,82 @@ INSERT INTO brintest_aocs SELECT
 	box(point(odd, even), point(thousand, twothousand))
 FROM tenk1 ORDER BY unique2 LIMIT 5 OFFSET 5;
 
-VACUUM brintest_aocs;  -- force a summarization cycle in brinaocsidx
+-- Test summarization
 
-UPDATE brintest_aocs SET int8col = int8col * int4col;
-UPDATE brintest_aocs SET textcol = '' WHERE textcol IS NOT NULL;
+-- Note: We use loops to populate logical heap pages in one aoseg. These logical
+-- heap blocks can start at a large number. See AOSegmentGet_startHeapBlock(segno).
 
--- Vaccum again so that a new segment file is created.
-VACUUM brintest_aocs;
-INSERT INTO brintest_aocs SELECT * FROM brintest_aocs;
--- We should have two segment files.
-SELECT segment_id, segno, column_num FROM gp_toolkit.__gp_aocsseg('brintest_aocs');
+CREATE TABLE brin_aoco_summarize(i int) USING ao_column;
+CREATE INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
 
 -- Tests for brin_summarize_new_values
-SELECT brin_summarize_new_values('brintest_aocs'); -- error, not an index
+SELECT brin_summarize_new_values('brin_aoco_summarize'); -- error, not an index
 SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
 -- New strategy of VACUUM AO/CO was introduced by PR #13255 for performance enhancement.
 -- Index dead tuples will not always be cleaned up completely after VACUUM, resulting
 -- brin_summarize_new_values() will not always be accurate. So ignore the check to
 -- coordinate with the new behavior.
-SELECT brin_summarize_new_values('brinaocsidx'); -- ok, no change expected
+-- There is no data, so nothing to summarize.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+
+DROP INDEX brin_aoco_summarize_i_idx;
+
+-- Create 3 blocks all on 1 QE, in 1 aoseg: 2 blocks full, 1 block with 1 tuple.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (1) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554434, 0)';
+  END LOOP;
+END;
+$$;
+
+-- Now create the index on the data inserted above.
+CREATE INDEX ON brin_aoco_summarize USING brin(i) WITH (pages_per_range=1);
+
+-- There is nothing new to summarize - it was all done during the index build.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+
+-- Insert more so we have 5 blocks on 1 QE, in 1 aoseg: 4 blocks full, 1 block
+-- with 1 tuple. The last and penultimate blocks will be unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (20) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554436, 0)';
+  END LOOP;
+END;
+$$;
+
+-- The last 2 blocks will be summarized.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
+
+-- Insert more so we have 7 blocks on 1 QE, in 1 aoseg: 6 blocks full, 1 page
+-- with 1 tuple. The last and penultimate blocks are unsummarized.
+DO $$
+DECLARE curtid tid;
+BEGIN
+  LOOP
+    INSERT INTO brin_aoco_summarize VALUES (30) RETURNING ctid INTO curtid;
+    EXIT WHEN curtid > tid '(33554438, 0)';
+  END LOOP;
+END;
+$$;
+
+DELETE FROM brin_aoco_summarize WHERE i = 1;
+
+VACUUM brin_aoco_summarize;
+
+-- All the tuples will have been moved to one aoseg and all the tuples should
+-- have fit in one logical heap block.
+SELECT distinct(right(split_part(ctid::text, ',', 1), -1)) AS blknum
+FROM brin_aoco_summarize;
+
+-- VACUUM should have already summarized this one logical heap block, so
+-- invoking summarization again will be a no-op.
+SELECT brin_summarize_new_values('brin_aoco_summarize_i_idx');
 
 -- We don't allow specific range summarization for AO tables at the moment.
-SELECT brin_summarize_range('brinaocsidx', 1);
+SELECT brin_summarize_range('brin_aoco_summarize_i_idx', 1);
diff --git a/src/test/singlenode_regress/expected/brin.out b/src/test/singlenode_regress/expected/brin.out
index c8c9b7633e..9b2e46b711 100644
--- a/src/test/singlenode_regress/expected/brin.out
+++ b/src/test/singlenode_regress/expected/brin.out
@@ -452,19 +452,31 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range  (seg0 slice1 127.0.0.1:7002 pid=11998)
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range  (seg0 slice1 127.0.0.1:7002 pid=11998)
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 CONTEXT:  SQL function "brin_summarize_range" statement 1
 -- summarize all pages
 SELECT brin_summarize_range('brin_summarize_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- nothing: page doesn't exist in table
@@ -492,7 +504,11 @@ SELECT brin_desummarize_range('brinidx', 0);
 (1 row)
 
 SELECT brin_summarize_range('brinidx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 DROP TABLE brintest_2;
 -- test brin cost estimates behave sanely based on correlation of values
 CREATE TABLE brin_test (a INT, b INT);
diff --git a/src/test/singlenode_regress/expected/brin_bloom.out b/src/test/singlenode_regress/expected/brin_bloom.out
index 1f0b96ca3e..3beab15511 100644
--- a/src/test/singlenode_regress/expected/brin_bloom.out
+++ b/src/test/singlenode_regress/expected/brin_bloom.out
@@ -373,21 +373,30 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_bloom_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/singlenode_regress/expected/brin_multi.out b/src/test/singlenode_regress/expected/brin_multi.out
index e88af5de7e..15083d1ff5 100644
--- a/src/test/singlenode_regress/expected/brin_multi.out
+++ b/src/test/singlenode_regress/expected/brin_multi.out
@@ -408,21 +408,33 @@ END;
 $$;
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 0);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 CONTEXT:  SQL function "brin_summarize_range" statement 1
 -- nothing: already summarized
 SELECT brin_summarize_range('brin_summarize_multi_idx', 1);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    0
+(1 row)
+
 CONTEXT:  SQL function "brin_summarize_range" statement 1
 -- summarize one range
 SELECT brin_summarize_range('brin_summarize_multi_idx', 2);
-ERROR:  Cloudberry could not summarize indicated page range
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 CONTEXT:  SQL function "brin_summarize_range" statement 1
 -- nothing: page doesn't exist in table
 SELECT brin_summarize_range('brin_summarize_multi_idx', 4294967295);
  brin_summarize_range 
 ----------------------
-                    1
+                    0
 (1 row)
 
 -- invalid block number values
diff --git a/src/test/singlenode_regress/expected/privileges.out b/src/test/singlenode_regress/expected/privileges.out
index 88f3057cd4..8edbe4a41d 100644
--- a/src/test/singlenode_regress/expected/privileges.out
+++ b/src/test/singlenode_regress/expected/privileges.out
@@ -1533,8 +1533,11 @@ SELECT brin_desummarize_range('sro_brin', 0);
 (1 row)
 
 SELECT brin_summarize_range('sro_brin', 0);
-ERROR:  Cloudberry could not summarize indicated page range
-CONTEXT:  SQL function "brin_summarize_range" statement 1
+ brin_summarize_range 
+----------------------
+                    1
+(1 row)
+
 DROP TABLE sro_tab;
 -- Check with a partitioned table
 CREATE TABLE sro_ptab (a int) PARTITION BY RANGE (a);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org