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 13:45:13 UTC

(cloudberry) branch main updated: Fix colLargeRowIndexes array overflow

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


The following commit(s) were added to refs/heads/main by this push:
     new 0b987de603 Fix colLargeRowIndexes array overflow
0b987de603 is described below

commit 0b987de603915fd0596a3b7c63b8b192ba68bae5
Author: Jianghua Yang <yj...@gmail.com>
AuthorDate: Thu Jan 9 13:14:17 2025 +0800

    Fix colLargeRowIndexes array overflow
    
    Child table may have attrs more then parent table, then array overflow.
    So use the max attrs number.
---
 src/backend/commands/analyze.c      | 18 ++++++++++++++++--
 src/backend/utils/cache/lsyscache.c |  3 +--
 src/include/utils/lsyscache.h       |  2 ++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index c1b46e20ff..ee1975cc2f 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -504,6 +504,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
 	int64		AnalyzePageDirty = VacuumPageDirty;
 	PgStat_Counter startreadtime = 0;
 	PgStat_Counter startwritetime = 0;
+	int max_natts = onerel->rd_att->natts;
 
 
 	if (inh)
@@ -722,8 +723,21 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
 	/*
 	 * Maintain information if the row of a column exceeds WIDTH_THRESHOLD
 	 */
-	colLargeRowIndexes = (Bitmapset **) palloc0(sizeof(Bitmapset *) * onerel->rd_att->natts);
-	colLargeRowLength = (double *)palloc0(sizeof(double) * onerel->rd_att->natts);
+	if (inh)
+	{
+		ListCell *le;
+		List* tableOIDs = find_all_inheritors(RelationGetRelid(onerel), NoLock, NULL);
+		foreach (le, tableOIDs)
+		{
+			Oid child_relid = lfirst_oid(le);
+			int natts = get_relnatts(child_relid);
+			if (natts > max_natts)
+				max_natts = natts;
+		}
+	}
+	colLargeRowIndexes = (Bitmapset **) palloc0(sizeof(Bitmapset *) * max_natts);
+	colLargeRowLength = (double *)palloc0(sizeof(double) * max_natts);
+
 
 	if ((params->options & VACOPT_FULLSCAN) != 0)
 	{
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 1a64d3870b..c1a56e362a 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -2494,7 +2494,7 @@ get_relname_relid(const char *relname, Oid relnamespace)
 						   ObjectIdGetDatum(relnamespace));
 }
 
-#ifdef NOT_USED
+
 /*
  * get_relnatts
  *
@@ -2518,7 +2518,6 @@ get_relnatts(Oid relid)
 	else
 		return InvalidAttrNumber;
 }
-#endif
 
 /*
  * get_rel_name
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index b176b746b4..56823275fc 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -269,6 +269,8 @@ extern CmpType get_comparison_type(Oid oidOp);
 extern List *get_operator_opfamilies(Oid opno);
 extern List *get_index_opfamilies(Oid oidIndex);
 
+extern int get_relnatts(Oid relid);
+
 #define type_is_array(typid)  (get_element_type(typid) != InvalidOid)
 /* type_is_array_domain accepts both plain arrays and domains over arrays */
 #define type_is_array_domain(typid)  (get_base_element_type(typid) != InvalidOid)


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