Add-proper_typecasting_arithematic_operands.patch

text/x-patch

Filename: Add-proper_typecasting_arithematic_operands.patch
Type: text/x-patch
Part: 0
Message: free space % calculation in pgstathashindex

Patch

Format: unified
File+
contrib/pgstattuple/pgstatindex.c 4 2
commit a34659959fe7385e68d196e57e90fe92b12764d4
Author: ashu <ashutosh12.1@example.com>
Date:   Mon Aug 7 11:18:27 2017 +0530

    Add proper typecasting to the operands when doing arithmatic operations.
    
    Patch by Ashutosh Sharma.

diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 44e322d..4e363cd 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -687,13 +687,15 @@ pgstathashindex(PG_FUNCTION_ARGS)
 	index_close(rel, AccessShareLock);
 
 	/* Count unused pages as free space. */
-	stats.free_space += stats.unused_pages * stats.space_per_page;
+	stats.free_space += ((uint64) stats.unused_pages *
+						 (uint64) stats.space_per_page);
 
 	/*
 	 * Total space available for tuples excludes the metapage and the bitmap
 	 * pages.
 	 */
-	total_space = (nblocks - (stats.bitmap_pages + 1)) * stats.space_per_page;
+	total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
+		(uint64) stats.space_per_page;
 
 	if (total_space == 0)
 		free_percent = 0.0;