aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/indxpath.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-07-09 23:23:02 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-07-09 23:23:02 -0400
commit8fc7b07b64d4f14b1738ce725f23f4903fce18f7 (patch)
treef05b0dd899d63b7097573ea860fdbed1d7d1c606 /src/backend/optimizer/path/indxpath.c
parenteb1b48816ba4e8f8e37bd25cd6e760034c0078fe (diff)
downloadpostgresql-8fc7b07b64d4f14b1738ce725f23f4903fce18f7.tar.gz
postgresql-8fc7b07b64d4f14b1738ce725f23f4903fce18f7.zip
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.
Diffstat (limited to 'src/backend/optimizer/path/indxpath.c')
-rw-r--r--src/backend/optimizer/path/indxpath.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 2e8ccd05785..66b68fc71d1 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -2785,7 +2785,6 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
Oid expr_coll;
Const *patt;
Const *prefix = NULL;
- Const *rest = NULL;
Pattern_Prefix_Status pstatus = Pattern_Prefix_None;
/*
@@ -2814,13 +2813,13 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
case OID_NAME_LIKE_OP:
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
isIndexable = (pstatus != Pattern_Prefix_None);
break;
case OID_BYTEA_LIKE_OP:
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
isIndexable = (pstatus != Pattern_Prefix_None);
break;
@@ -2829,7 +2828,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
case OID_NAME_ICLIKE_OP:
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
isIndexable = (pstatus != Pattern_Prefix_None);
break;
@@ -2838,7 +2837,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
case OID_NAME_REGEXEQ_OP:
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
isIndexable = (pstatus != Pattern_Prefix_None);
break;
@@ -2847,7 +2846,7 @@ match_special_index_operator(Expr *clause, Oid opfamily, Oid idxcollation,
case OID_NAME_ICREGEXEQ_OP:
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
isIndexable = (pstatus != Pattern_Prefix_None);
break;
@@ -3115,7 +3114,6 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
Oid expr_coll = ((OpExpr *) clause)->inputcollid;
Const *patt = (Const *) rightop;
Const *prefix = NULL;
- Const *rest = NULL;
Pattern_Prefix_Status pstatus;
/*
@@ -3135,7 +3133,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
if (!op_in_opfamily(expr_op, opfamily))
{
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
}
break;
@@ -3147,7 +3145,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
{
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like_IC, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
}
break;
@@ -3159,7 +3157,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
{
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
}
break;
@@ -3171,7 +3169,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily, Oid idxcollation)
{
/* the right-hand const is type text for all of these */
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC, expr_coll,
- &prefix, &rest);
+ &prefix, NULL);
return prefix_quals(leftop, opfamily, idxcollation, prefix, pstatus);
}
break;