Skip to content

Commit 03bbf70

Browse files
authored
Dump Babelfish operator classes for numeric-int comparisons to support index scan (#576)
Since Postgres does not dump user-defined operator classes over built-in data types, this commit makes changes to dump new operator classes added in babelfish extension as part of the numeric operator family (babelfish-for-postgresql/babelfish_extensions#3761). These operator classes are essential for supporting index scans between int and numeric types when the index is created on a numeric column. The change ensures that the operator classes are properly preserved during pg_upgrade operations, maintaining the index scan capabilities in the upgraded database. Task: BABEL-5648 Signed-off-by: Sumit Jaiswal <[email protected]>
1 parent 5e62ffa commit 03bbf70

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/bin/pg_dump/dump_babel_utils.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,13 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
17711771
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int2_numeric\"" : "sys.int2_numeric") != 0 &&
17721772
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int2\"" : "sys.numeric_int2") != 0 &&
17731773
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int8_numeric\"" : "sys.int8_numeric") != 0 &&
1774-
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8\"" : "sys.numeric_int8") != 0)
1774+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8\"" : "sys.numeric_int8") != 0 &&
1775+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int2_numeric_ops\"" : "sys.int2_numeric_ops") != 0 &&
1776+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int2_ops\"" : "sys.numeric_int2_ops") != 0 &&
1777+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int4_numeric_ops\"" : "sys.int4_numeric_ops") != 0 &&
1778+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int4_ops\"" : "sys.numeric_int4_ops") != 0 &&
1779+
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)
17751781
return;
17761782

17771783
query = createPQExpBuffer();
@@ -1800,15 +1806,16 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18001806
}
18011807

18021808
if (strcasecmp(opfnamespace, "\"pg_catalog\"") != 0 ||
1803-
strcasecmp(opfname, "integer_ops") != 0)
1809+
(strcasecmp(opfname, "integer_ops") != 0 && strcasecmp(opfname, "numeric_ops") != 0))
18041810
{
18051811
PQclear(res);
18061812
return;
18071813
}
18081814

18091815
PQclear(res);
18101816

1811-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int_numeric\"" : "sys.int_numeric") == 0)
1817+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int_numeric\"" : "sys.int_numeric") == 0 ||
1818+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int4_numeric_ops\"" : "sys.int4_numeric_ops") == 0)
18121819
{
18131820
str = quote_all_identifiers ?
18141821
"OPERATOR 1 \"sys\".< (int4, numeric) ,\n "
@@ -1825,7 +1832,8 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18251832
"FUNCTION 1 sys.int4_numeric_cmp(int4, numeric) ";
18261833
}
18271834

1828-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int\"" : "sys.numeric_int") == 0)
1835+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int\"" : "sys.numeric_int") == 0 ||
1836+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int4_ops\"" : "sys.numeric_int4_ops") == 0)
18291837
{
18301838
str = quote_all_identifiers ?
18311839
"OPERATOR 1 \"sys\".< (numeric, int4) ,\n "
@@ -1842,7 +1850,8 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18421850
"FUNCTION 1 sys.numeric_int4_cmp(numeric, int4) ";
18431851
}
18441852

1845-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int2_numeric\"" : "sys.int2_numeric") == 0)
1853+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int2_numeric\"" : "sys.int2_numeric") == 0 ||
1854+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int2_numeric_ops\"" : "sys.int2_numeric_ops") == 0)
18461855
{
18471856
str = quote_all_identifiers ?
18481857
"OPERATOR 1 \"sys\".< (int2, numeric) ,\n "
@@ -1859,7 +1868,8 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18591868
"FUNCTION 1 sys.int2_numeric_cmp(int2, numeric) ";
18601869
}
18611870

1862-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int2\"" : "sys.numeric_int2") == 0)
1871+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int2\"" : "sys.numeric_int2") == 0 ||
1872+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int2_ops\"" : "sys.numeric_int2_ops") == 0)
18631873
{
18641874
str = quote_all_identifiers ?
18651875
"OPERATOR 1 \"sys\".< (numeric, int2) ,\n "
@@ -1876,7 +1886,8 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18761886
"FUNCTION 1 sys.numeric_int2_cmp(numeric, int2) ";
18771887
}
18781888

1879-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int8_numeric\"" : "sys.int8_numeric") == 0)
1889+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int8_numeric\"" : "sys.int8_numeric") == 0 ||
1890+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"int8_numeric_ops\"" : "sys.int8_numeric_ops") == 0)
18801891
{
18811892
str = quote_all_identifiers ?
18821893
"OPERATOR 1 \"sys\".< (int8, numeric) ,\n "
@@ -1893,7 +1904,8 @@ babelfishDumpOpclassHelper(Archive *fout, const OpclassInfo *opcinfo, PQExpBuffe
18931904
"FUNCTION 1 sys.int8_numeric_cmp(int8, numeric) ";
18941905
}
18951906

1896-
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8\"" : "sys.numeric_int8") == 0)
1907+
if (pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8\"" : "sys.numeric_int8") == 0 ||
1908+
pg_strcasecmp(opclass, quote_all_identifiers ? "\"sys\".\"numeric_int8_ops\"" : "sys.numeric_int8_ops") == 0)
18971909
{
18981910
str = quote_all_identifiers ?
18991911
"OPERATOR 1 \"sys\".< (numeric, int8) ,\n "

0 commit comments

Comments
 (0)