diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index 50f0852..d806e21 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2328,7 +2328,7 @@ final_cost_mergejoin(PlannerInfo *root, MergePath *path,
 	 */
 	else if (enable_material && innersortkeys != NIL &&
 			 relation_byte_size(inner_path_rows, inner_path->parent->width) >
-			 (work_mem * 1024L))
+			 ((double) work_mem * 1024))
 		path->materialize_inner = true;
 	else
 		path->materialize_inner = false;
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 0f92118..5d7de78 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -937,7 +937,7 @@ subplan_is_hashable(Plan *plan)
 	 */
 	subquery_size = plan->plan_rows *
 		(MAXALIGN(plan->plan_width) + MAXALIGN(sizeof(HeapTupleHeaderData)));
-	if (subquery_size > work_mem * 1024L)
+	if (subquery_size > (double) work_mem * 1024)
 		return false;
 
 	return true;
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c
index a7169ef..e813c68 100644
--- a/src/backend/optimizer/util/pathnode.c
+++ b/src/backend/optimizer/util/pathnode.c
@@ -1368,7 +1368,7 @@ create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath,
 		 */
 		int			hashentrysize = rel->width + 64;
 
-		if (hashentrysize * pathnode->path.rows > work_mem * 1024L)
+		if (hashentrysize * pathnode->path.rows > (double) work_mem * 1024)
 			all_hash = false;	/* don't try to hash */
 		else
 			cost_agg(&agg_path, root,
			