Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 00dac60

Browse files
committed
Refactor pattern_fixed_prefix() to avoid dealing in incomplete patterns.
Previously, pattern_fixed_prefix() was defined to return whatever fixed prefix it could extract from the pattern, plus the "rest" of the pattern. That definition was sensible for LIKE patterns, but not so much for regexes, where reconstituting a valid pattern minus the prefix could be quite tricky (certainly the existing code wasn't doing that correctly). Since the only thing that callers ever did with the "rest" of the pattern was to pass it to like_selectivity() or regex_selectivity(), let's cut out the middle-man and just have pattern_fixed_prefix's subroutines do this directly. Then pattern_fixed_prefix can return a simple selectivity number, and the question of how to cope with partial patterns is removed from its API specification. While at it, adjust the API spec so that callers who don't actually care about the pattern's selectivity (which is a lot of them) can pass NULL for the selectivity pointer to skip doing the work of computing a selectivity estimate. This patch is only an API refactoring that doesn't actually change any processing, other than allowing a little bit of useless work to be skipped. However, it's necessary infrastructure for my upcoming fix to regex prefix extraction, because after that change there won't be any simple way to identify the "rest" of the regex, not even to the low level of fidelity needed by regex_selectivity. We can cope with that if regex_fixed_prefix and regex_selectivity communicate directly, but not if we have to work within the old API. Hence, back-patch to all active branches.
1 parent e7ef6d7 commit 00dac60

File tree

3 files changed

+60
-128
lines changed

3 files changed

+60
-128
lines changed

src/backend/optimizer/path/indxpath.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,6 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
27852785
Oid expr_coll;
27862786
Const *patt;
27872787
Const *prefix = NULL;
2788-
Const *rest = NULL;
27892788
Pattern_Prefix_Status pstatus = Pattern_Prefix_None;
27902789

27912790
/*
@@ -2814,13 +2813,13 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
28142813
case OID_NAME_LIKE_OP:
28152814
/* the right-hand const is type text for all of these */
28162815
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
2817-
&prefix, &rest);
2816+
&prefix, NULL);
28182817
isIndexable = (pstatus != Pattern_Prefix_None);
28192818
break;
28202819

28212820
case OID_BYTEA_LIKE_OP:
28222821
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
2823-
&prefix, &rest);
2822+
&prefix, NULL);
28242823
isIndexable = (pstatus != Pattern_Prefix_None);
28252824
break;
28262825

@@ -2829,7 +2828,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
28292828
case OID_NAME_ICLIKE_OP:
28302829
/* the right-hand const is type text for all of these */
28312830
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, expr_coll,
2832-
&prefix, &rest);
2831+
&prefix, NULL);
28332832
isIndexable = (pstatus != Pattern_Prefix_None);
28342833
break;
28352834

@@ -2838,7 +2837,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
28382837
case OID_NAME_REGEXEQ_OP:
28392838
/* the right-hand const is type text for all of these */
28402839
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex, expr_coll,
2841-
&prefix, &rest);
2840+
&prefix, NULL);
28422841
isIndexable = (pstatus != Pattern_Prefix_None);
28432842
break;
28442843

@@ -2847,7 +2846,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
28472846
case OID_NAME_ICREGEXEQ_OP:
28482847
/* the right-hand const is type text for all of these */
28492848
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, expr_coll,
2850-
&prefix, &rest);
2849+
&prefix, NULL);
28512850
isIndexable = (pstatus != Pattern_Prefix_None);
28522851
break;
28532852

@@ -3115,7 +3114,6 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
31153114
Oid expr_coll = ((OpExpr *) clause)->inputcollid;
31163115
Const *patt = (Const *) rightop;
31173116
Const *prefix = NULL;
3118-
Const *rest = NULL;
31193117
Pattern_Prefix_Status pstatus;
31203118

31213119
/*
@@ -3135,7 +3133,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
31353133
if (!op_in_opfamily(expr_op, opfamily))
31363134
{
31373135
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
3138-
&prefix, &rest);
3136+
&prefix, NULL);
31393137
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
31403138
}
31413139
break;
@@ -3147,7 +3145,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
31473145
{
31483146
/* the right-hand const is type text for all of these */
31493147
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, expr_coll,
3150-
&prefix, &rest);
3148+
&prefix, NULL);
31513149
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
31523150
}
31533151
break;
@@ -3159,7 +3157,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
31593157
{
31603158
/* the right-hand const is type text for all of these */
31613159
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex, expr_coll,
3162-
&prefix, &rest);
3160+
&prefix, NULL);
31633161
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
31643162
}
31653163
break;
@@ -3171,7 +3169,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
31713169
{
31723170
/* the right-hand const is type text for all of these */
31733171
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, expr_coll,
3174-
&prefix, &rest);
3172+
&prefix, NULL);
31753173
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
31763174
}
31773175
break;

0 commit comments

Comments
 (0)