9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.237 2009/03/05 23:06:45 tgl Exp $
12
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.238 2009/03/11 03:32:22 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -2138,6 +2138,7 @@ match_special_index_operator(Expr *clause, Oid opfamily,
2138
2138
Const * patt ;
2139
2139
Const * prefix = NULL ;
2140
2140
Const * rest = NULL ;
2141
+ Pattern_Prefix_Status pstatus = Pattern_Prefix_None ;
2141
2142
2142
2143
/*
2143
2144
* Currently, all known special operators require the indexkey on the
@@ -2163,37 +2164,42 @@ match_special_index_operator(Expr *clause, Oid opfamily,
2163
2164
case OID_BPCHAR_LIKE_OP :
2164
2165
case OID_NAME_LIKE_OP :
2165
2166
/* the right-hand const is type text for all of these */
2166
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like ,
2167
- & prefix , & rest ) != Pattern_Prefix_None ;
2167
+ pstatus = pattern_fixed_prefix (patt , Pattern_Type_Like ,
2168
+ & prefix , & rest );
2169
+ isIndexable = (pstatus != Pattern_Prefix_None );
2168
2170
break ;
2169
2171
2170
2172
case OID_BYTEA_LIKE_OP :
2171
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like ,
2172
- & prefix , & rest ) != Pattern_Prefix_None ;
2173
+ pstatus = pattern_fixed_prefix (patt , Pattern_Type_Like ,
2174
+ & prefix , & rest );
2175
+ isIndexable = (pstatus != Pattern_Prefix_None );
2173
2176
break ;
2174
2177
2175
2178
case OID_TEXT_ICLIKE_OP :
2176
2179
case OID_BPCHAR_ICLIKE_OP :
2177
2180
case OID_NAME_ICLIKE_OP :
2178
2181
/* the right-hand const is type text for all of these */
2179
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Like_IC ,
2180
- & prefix , & rest ) != Pattern_Prefix_None ;
2182
+ pstatus = pattern_fixed_prefix (patt , Pattern_Type_Like_IC ,
2183
+ & prefix , & rest );
2184
+ isIndexable = (pstatus != Pattern_Prefix_None );
2181
2185
break ;
2182
2186
2183
2187
case OID_TEXT_REGEXEQ_OP :
2184
2188
case OID_BPCHAR_REGEXEQ_OP :
2185
2189
case OID_NAME_REGEXEQ_OP :
2186
2190
/* the right-hand const is type text for all of these */
2187
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex ,
2188
- & prefix , & rest ) != Pattern_Prefix_None ;
2191
+ pstatus = pattern_fixed_prefix (patt , Pattern_Type_Regex ,
2192
+ & prefix , & rest );
2193
+ isIndexable = (pstatus != Pattern_Prefix_None );
2189
2194
break ;
2190
2195
2191
2196
case OID_TEXT_ICREGEXEQ_OP :
2192
2197
case OID_BPCHAR_ICREGEXEQ_OP :
2193
2198
case OID_NAME_ICREGEXEQ_OP :
2194
2199
/* the right-hand const is type text for all of these */
2195
- isIndexable = pattern_fixed_prefix (patt , Pattern_Type_Regex_IC ,
2196
- & prefix , & rest ) != Pattern_Prefix_None ;
2200
+ pstatus = pattern_fixed_prefix (patt , Pattern_Type_Regex_IC ,
2201
+ & prefix , & rest );
2202
+ isIndexable = (pstatus != Pattern_Prefix_None );
2197
2203
break ;
2198
2204
2199
2205
case OID_INET_SUB_OP :
@@ -2217,9 +2223,17 @@ match_special_index_operator(Expr *clause, Oid opfamily,
2217
2223
* want to apply. (A hash index, for example, will not support ">=".)
2218
2224
* Currently, only btree supports the operators we need.
2219
2225
*
2226
+ * Note: actually, in the Pattern_Prefix_Exact case, we only need "="
2227
+ * so a hash index would work. Currently it doesn't seem worth checking
2228
+ * for that, however.
2229
+ *
2220
2230
* We insist on the opfamily being the specific one we expect, else we'd
2221
2231
* do the wrong thing if someone were to make a reverse-sort opfamily with
2222
2232
* the same operators.
2233
+ *
2234
+ * The non-pattern opclasses will not sort the way we need in most non-C
2235
+ * locales. We can use such an index anyway for an exact match (simple
2236
+ * equality), but not for prefix-match cases.
2223
2237
*/
2224
2238
switch (expr_op )
2225
2239
{
@@ -2229,7 +2243,8 @@ match_special_index_operator(Expr *clause, Oid opfamily,
2229
2243
case OID_TEXT_ICREGEXEQ_OP :
2230
2244
isIndexable =
2231
2245
(opfamily == TEXT_PATTERN_BTREE_FAM_OID ) ||
2232
- (opfamily == TEXT_BTREE_FAM_OID && lc_collate_is_c ());
2246
+ (opfamily == TEXT_BTREE_FAM_OID &&
2247
+ (pstatus == Pattern_Prefix_Exact || lc_collate_is_c ()));
2233
2248
break ;
2234
2249
2235
2250
case OID_BPCHAR_LIKE_OP :
@@ -2238,7 +2253,8 @@ match_special_index_operator(Expr *clause, Oid opfamily,
2238
2253
case OID_BPCHAR_ICREGEXEQ_OP :
2239
2254
isIndexable =
2240
2255
(opfamily == BPCHAR_PATTERN_BTREE_FAM_OID ) ||
2241
- (opfamily == BPCHAR_BTREE_FAM_OID && lc_collate_is_c ());
2256
+ (opfamily == BPCHAR_BTREE_FAM_OID &&
2257
+ (pstatus == Pattern_Prefix_Exact || lc_collate_is_c ()));
2242
2258
break ;
2243
2259
2244
2260
case OID_NAME_LIKE_OP :
0 commit comments