Skip to content

Commit 2e6e53a

Browse files
authored
Dump Babelfish operator classes for numeric-fixeddecimal comparisons to support index scan (babelfish-for-postgresql#605)
PostgreSQL does not dump user-defined operator classes over built-in types by default. This change ensures Babelfish's custom numeric operator classes are preserved during pg_upgrade operations, maintaining index scan capabilities between money/smallmoney and numeric types. Extension PR: babelfish-for-postgresql/babelfish_extensions#3970 Signed-off-by: Tanya Gupta [email protected] Issues Resolved BABEL-5959
1 parent eb0b48f commit 2e6e53a

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/bin/pg_dump/dump_babel_utils.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,9 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
17771777
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int4_numeric_ops\"" : "sys.int4_numeric_ops") != 0 &&
17781778
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int4_ops\"" : "sys.numeric_int4_ops") != 0 &&
17791779
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int8_numeric_ops\"" : "sys.int8_numeric_ops") != 0 &&
1780-
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8_ops\"" : "sys.numeric_int8_ops") != 0)
1780+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8_ops\"" : "sys.numeric_int8_ops") != 0 &&
1781+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_fixeddecimal_cmp_ops\"" : "sys.numeric_fixeddecimal_cmp_ops") != 0 &&
1782+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"fixeddecimal_numeric_cmp_ops\"" : "sys.fixeddecimal_numeric_cmp_ops") != 0)
17811783
return;
17821784

17831785
query = createPQExpBuffer();
@@ -1922,6 +1924,40 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
19221924
"FUNCTION 1 sys.numeric_int8_cmp(numeric, int8) ";
19231925
}
19241926

1927+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_fixeddecimal_cmp_ops\"" : "sys.numeric_fixeddecimal_cmp_ops") == 0)
1928+
{
1929+
str = quote_all_identifiers ?
1930+
"OPERATOR 1 \"sys\".< (numeric, \"sys\".\"fixeddecimal\") ,\n "
1931+
"OPERATOR 2 \"sys\".<= (numeric, \"sys\".\"fixeddecimal\") ,\n "
1932+
"OPERATOR 3 \"sys\".= (numeric, \"sys\".\"fixeddecimal\") ,\n "
1933+
"OPERATOR 4 \"sys\".>= (numeric, \"sys\".\"fixeddecimal\") ,\n "
1934+
"OPERATOR 5 \"sys\".> (numeric, \"sys\".\"fixeddecimal\") ,\n "
1935+
"FUNCTION 1 \"sys\".\"numeric_fixeddecimal_cmp\"(numeric, \"sys\".\"fixeddecimal\") " :
1936+
"OPERATOR 1 sys.< (numeric, sys.fixeddecimal) ,\n "
1937+
"OPERATOR 2 sys.<= (numeric, sys.fixeddecimal) ,\n "
1938+
"OPERATOR 3 sys.= (numeric, sys.fixeddecimal) ,\n "
1939+
"OPERATOR 4 sys.>= (numeric, sys.fixeddecimal) ,\n "
1940+
"OPERATOR 5 sys.> (numeric, sys.fixeddecimal) ,\n "
1941+
"FUNCTION 1 sys.numeric_fixeddecimal_cmp(numeric, sys.fixeddecimal) ";
1942+
}
1943+
1944+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"fixeddecimal_numeric_cmp_ops\"" : "sys.fixeddecimal_numeric_cmp_ops") == 0)
1945+
{
1946+
str = quote_all_identifiers ?
1947+
"OPERATOR 1 \"sys\".< (\"sys\".\"fixeddecimal\", numeric) ,\n "
1948+
"OPERATOR 2 \"sys\".<= (\"sys\".\"fixeddecimal\", numeric) ,\n "
1949+
"OPERATOR 3 \"sys\".= (\"sys\".\"fixeddecimal\", numeric) ,\n "
1950+
"OPERATOR 4 \"sys\".>= (\"sys\".\"fixeddecimal\", numeric) ,\n "
1951+
"OPERATOR 5 \"sys\".> (\"sys\".\"fixeddecimal\", numeric) ,\n "
1952+
"FUNCTION 1 \"sys\".\"fixeddecimal_numeric_cmp\"(\"sys\".\"fixeddecimal\", numeric) " :
1953+
"OPERATOR 1 sys.< (sys.fixeddecimal, numeric) ,\n "
1954+
"OPERATOR 2 sys.<= (sys.fixeddecimal, numeric) ,\n "
1955+
"OPERATOR 3 sys.= (sys.fixeddecimal, numeric) ,\n "
1956+
"OPERATOR 4 sys.>= (sys.fixeddecimal, numeric) ,\n "
1957+
"OPERATOR 5 sys.> (sys.fixeddecimal, numeric) ,\n "
1958+
"FUNCTION 1 sys.fixeddecimal_numeric_cmp(sys.fixeddecimal, numeric) ";
1959+
}
1960+
19251961
if(str != NULL)
19261962
appendPQExpBufferStr(buff, str);
19271963

0 commit comments

Comments
 (0)