From d98ce62e39dab622c546a6294ad45d3f0312817e Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Mon, 28 Oct 2024 16:36:27 +0530
Subject: [PATCH 7/8] Temporary fix for collation

The equality operator on string operands requires collation. Supply it.
This temporary fix is required for some queries added for RLS testing.

A better fix is to use FK/PK style quals. We will work on it next.

Author: Ashutosh Bapat
---
 src/backend/rewrite/rewriteGraphTable.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/backend/rewrite/rewriteGraphTable.c b/src/backend/rewrite/rewriteGraphTable.c
index 9c14fa3b1b7..326e35da150 100644
--- a/src/backend/rewrite/rewriteGraphTable.c
+++ b/src/backend/rewrite/rewriteGraphTable.c
@@ -1150,23 +1150,32 @@ build_edge_vertex_link_quals(HeapTuple edgetup, int edgerti, int refrti, AttrNum
 	{
 		AttrNumber	keyattn = DatumGetInt16(d1[i]);
 		AttrNumber	refattn = DatumGetInt16(d2[i]);
+		Var		   *keyvar;
+		Var		   *refvar;
 		Oid			atttypid;
+		int32		atttypmod;
+		Oid			attcoll;
 		TypeCacheEntry *typentry;
 		OpExpr	   *op;
 
+		get_atttypetypmodcoll(pgeform->pgerelid, keyattn, &atttypid, &atttypmod, &attcoll);
+		keyvar = makeVar(edgerti, keyattn, atttypid, atttypmod, attcoll, 0);
+
 		/*
 		 * TODO: Assumes types the same on both sides; no collations yet. Some
 		 * of this could probably be shared with foreign key triggers.
 		 */
-		atttypid = get_atttype(pgeform->pgerelid, keyattn);
+		/* get_atttypetypmodcoll(, refattn, &atttypid, &atttypmod, &attcoll); */
+		refvar = makeVar(refrti, refattn, atttypid, atttypmod, attcoll, 0);
+
 		typentry = lookup_type_cache(atttypid, TYPECACHE_EQ_OPR);
 
 		op = makeNode(OpExpr);
 		op->location = -1;
 		op->opno = typentry->eq_opr;
+		op->inputcollid = attcoll;
 		op->opresulttype = BOOLOID;
-		op->args = list_make2(makeVar(edgerti, keyattn, atttypid, -1, 0, 0),
-							  makeVar(refrti, refattn, atttypid, -1, 0, 0));
+		op->args = list_make2(keyvar, refvar);
 		quals = lappend(quals, op);
 	}
 
-- 
2.34.1

