9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.137 2003/05/13 04:38:58 tgl Exp $
12
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.138 2003/05/15 15:50:18 petere Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -1797,44 +1797,40 @@ match_special_index_operator(Expr *clause, Oid opclass,
1797
1797
case OID_VARCHAR_LIKE_OP :
1798
1798
case OID_NAME_LIKE_OP :
1799
1799
/* the right-hand const is type text for all of these */
1800
- if (locale_is_like_safe ())
1801
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like ,
1802
- & prefix , & rest ) != Pattern_Prefix_None ;
1800
+ isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like ,
1801
+ & prefix , & rest ) != Pattern_Prefix_None ;
1803
1802
break ;
1804
1803
1805
1804
case OID_BYTEA_LIKE_OP :
1806
1805
isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like ,
1807
- & prefix , & rest ) != Pattern_Prefix_None ;
1806
+ & prefix , & rest ) != Pattern_Prefix_None ;
1808
1807
break ;
1809
1808
1810
1809
case OID_TEXT_ICLIKE_OP :
1811
1810
case OID_BPCHAR_ICLIKE_OP :
1812
1811
case OID_VARCHAR_ICLIKE_OP :
1813
1812
case OID_NAME_ICLIKE_OP :
1814
1813
/* the right-hand const is type text for all of these */
1815
- if (locale_is_like_safe ())
1816
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like_IC ,
1817
- & prefix , & rest ) != Pattern_Prefix_None ;
1814
+ isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like_IC ,
1815
+ & prefix , & rest ) != Pattern_Prefix_None ;
1818
1816
break ;
1819
1817
1820
1818
case OID_TEXT_REGEXEQ_OP :
1821
1819
case OID_BPCHAR_REGEXEQ_OP :
1822
1820
case OID_VARCHAR_REGEXEQ_OP :
1823
1821
case OID_NAME_REGEXEQ_OP :
1824
1822
/* the right-hand const is type text for all of these */
1825
- if (locale_is_like_safe ())
1826
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex ,
1827
- & prefix , & rest ) != Pattern_Prefix_None ;
1823
+ isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex ,
1824
+ & prefix , & rest ) != Pattern_Prefix_None ;
1828
1825
break ;
1829
1826
1830
1827
case OID_TEXT_ICREGEXEQ_OP :
1831
1828
case OID_BPCHAR_ICREGEXEQ_OP :
1832
1829
case OID_VARCHAR_ICREGEXEQ_OP :
1833
1830
case OID_NAME_ICREGEXEQ_OP :
1834
1831
/* the right-hand const is type text for all of these */
1835
- if (locale_is_like_safe ())
1836
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex_IC ,
1837
- & prefix , & rest ) != Pattern_Prefix_None ;
1832
+ isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex_IC ,
1833
+ & prefix , & rest ) != Pattern_Prefix_None ;
1838
1834
break ;
1839
1835
1840
1836
case OID_INET_SUB_OP :
@@ -1867,42 +1863,53 @@ match_special_index_operator(Expr *clause, Oid opclass,
1867
1863
case OID_TEXT_ICLIKE_OP :
1868
1864
case OID_TEXT_REGEXEQ_OP :
1869
1865
case OID_TEXT_ICREGEXEQ_OP :
1870
- if (!op_in_opclass (find_operator (">=" , TEXTOID ), opclass ) ||
1871
- !op_in_opclass (find_operator ("<" , TEXTOID ), opclass ))
1872
- isIndexable = false;
1866
+ if (lc_collate_is_c ())
1867
+ isIndexable = (op_in_opclass (find_operator (">=" , TEXTOID ), opclass )
1868
+ && op_in_opclass (find_operator ("<" , TEXTOID ), opclass ));
1869
+ else
1870
+ isIndexable = (op_in_opclass (find_operator ("~>=~" , TEXTOID ), opclass )
1871
+ && op_in_opclass (find_operator ("~<~" , TEXTOID ), opclass ));
1873
1872
break ;
1874
1873
1875
1874
case OID_BYTEA_LIKE_OP :
1876
- if (!op_in_opclass (find_operator (">=" , BYTEAOID ), opclass ) ||
1877
- !op_in_opclass (find_operator ("<" , BYTEAOID ), opclass ))
1878
- isIndexable = false;
1875
+ isIndexable = (op_in_opclass (find_operator (">=" , BYTEAOID ), opclass )
1876
+ && op_in_opclass (find_operator ("<" , BYTEAOID ), opclass ));
1879
1877
break ;
1880
1878
1881
1879
case OID_BPCHAR_LIKE_OP :
1882
1880
case OID_BPCHAR_ICLIKE_OP :
1883
1881
case OID_BPCHAR_REGEXEQ_OP :
1884
1882
case OID_BPCHAR_ICREGEXEQ_OP :
1885
- if (!op_in_opclass (find_operator (">=" , BPCHAROID ), opclass ) ||
1886
- !op_in_opclass (find_operator ("<" , BPCHAROID ), opclass ))
1887
- isIndexable = false;
1883
+ if (lc_collate_is_c ())
1884
+ isIndexable = (op_in_opclass (find_operator (">=" , BPCHAROID ), opclass )
1885
+ && op_in_opclass (find_operator ("<" , BPCHAROID ), opclass ));
1886
+ else
1887
+ isIndexable = (op_in_opclass (find_operator ("~>=~" , BPCHAROID ), opclass )
1888
+ && op_in_opclass (find_operator ("~<~" , BPCHAROID ), opclass ));
1888
1889
break ;
1889
1890
1890
1891
case OID_VARCHAR_LIKE_OP :
1891
1892
case OID_VARCHAR_ICLIKE_OP :
1892
1893
case OID_VARCHAR_REGEXEQ_OP :
1893
1894
case OID_VARCHAR_ICREGEXEQ_OP :
1894
- if (!op_in_opclass (find_operator (">=" , VARCHAROID ), opclass ) ||
1895
- !op_in_opclass (find_operator ("<" , VARCHAROID ), opclass ))
1896
- isIndexable = false;
1895
+ if (lc_collate_is_c ())
1896
+ isIndexable = (op_in_opclass (find_operator (">=" , VARCHAROID ), opclass )
1897
+ && op_in_opclass (find_operator ("<" , VARCHAROID ), opclass ));
1898
+ else
1899
+ isIndexable = (op_in_opclass (find_operator ("~>=~" , VARCHAROID ), opclass )
1900
+ && op_in_opclass (find_operator ("~<~" , VARCHAROID ), opclass ));
1897
1901
break ;
1898
1902
1899
1903
case OID_NAME_LIKE_OP :
1900
1904
case OID_NAME_ICLIKE_OP :
1901
1905
case OID_NAME_REGEXEQ_OP :
1902
1906
case OID_NAME_ICREGEXEQ_OP :
1903
- if (!op_in_opclass (find_operator (">=" , NAMEOID ), opclass ) ||
1904
- !op_in_opclass (find_operator ("<" , NAMEOID ), opclass ))
1905
- isIndexable = false;
1907
+ if (lc_collate_is_c ())
1908
+ isIndexable = (op_in_opclass (find_operator (">=" , NAMEOID ), opclass )
1909
+ && op_in_opclass (find_operator ("<" , NAMEOID ), opclass ));
1910
+ else
1911
+ isIndexable = (op_in_opclass (find_operator ("~>=~" , NAMEOID ), opclass )
1912
+ && op_in_opclass (find_operator ("~<~" , NAMEOID ), opclass ));
1906
1913
break ;
1907
1914
1908
1915
case OID_INET_SUB_OP :
@@ -2039,6 +2046,7 @@ prefix_quals(Node *leftop, Oid expr_op,
2039
2046
List * result ;
2040
2047
Oid datatype ;
2041
2048
Oid oproid ;
2049
+ const char * oprname ;
2042
2050
char * prefix ;
2043
2051
Const * con ;
2044
2052
Expr * expr ;
@@ -2098,9 +2106,10 @@ prefix_quals(Node *leftop, Oid expr_op,
2098
2106
*/
2099
2107
if (pstatus == Pattern_Prefix_Exact )
2100
2108
{
2101
- oproid = find_operator ("=" , datatype );
2109
+ oprname = (datatype == BYTEAOID || lc_collate_is_c () ? "=" : "~=~" );
2110
+ oproid = find_operator (oprname , datatype );
2102
2111
if (oproid == InvalidOid )
2103
- elog (ERROR , "prefix_quals: no = operator for type %u" , datatype );
2112
+ elog (ERROR , "prefix_quals: no operator %s for type %u" , oprname , datatype );
2104
2113
con = string_to_const (prefix , datatype );
2105
2114
expr = make_opclause (oproid , BOOLOID , false,
2106
2115
(Expr * ) leftop , (Expr * ) con );
@@ -2113,9 +2122,10 @@ prefix_quals(Node *leftop, Oid expr_op,
2113
2122
*
2114
2123
* We can always say "x >= prefix".
2115
2124
*/
2116
- oproid = find_operator (">=" , datatype );
2125
+ oprname = (datatype == BYTEAOID || lc_collate_is_c () ? ">=" : "~>=~" );
2126
+ oproid = find_operator (oprname , datatype );
2117
2127
if (oproid == InvalidOid )
2118
- elog (ERROR , "prefix_quals: no >= operator for type %u" , datatype );
2128
+ elog (ERROR , "prefix_quals: no operator %s for type %u" , oprname , datatype );
2119
2129
con = string_to_const (prefix , datatype );
2120
2130
expr = make_opclause (oproid , BOOLOID , false,
2121
2131
(Expr * ) leftop , (Expr * ) con );
@@ -2129,9 +2139,10 @@ prefix_quals(Node *leftop, Oid expr_op,
2129
2139
greaterstr = make_greater_string (con );
2130
2140
if (greaterstr )
2131
2141
{
2132
- oproid = find_operator ("<" , datatype );
2142
+ oprname = (datatype == BYTEAOID || lc_collate_is_c () ? "<" : "~<~" );
2143
+ oproid = find_operator (oprname , datatype );
2133
2144
if (oproid == InvalidOid )
2134
- elog (ERROR , "prefix_quals: no < operator for type %u" , datatype );
2145
+ elog (ERROR , "prefix_quals: no operator %s for type %u" , oprname , datatype );
2135
2146
expr = make_opclause (oproid , BOOLOID , false,
2136
2147
(Expr * ) leftop , (Expr * ) greaterstr );
2137
2148
result = lappend (result , expr );
0 commit comments