8000 Refactor pattern_fixed_prefix() to avoid dealing in incomplete patterns. · sureandrew/postgres@1590731 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1590731

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 7940028 commit 1590731

File tree

3 files changed

+57
-127
lines changed

3 files changed

+57
-127
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,6 @@ match_special_index_operator(Expr *clause, Oid opfamily,
20812081
Oid expr_op;
20822082
Const *patt;
20832083
Const *prefix = NULL;
2084-
Const *rest = NULL;
20852084

20862085
/*
20872086
* Currently, all known special operators require the indexkey on the
@@ -2108,36 +2107,36 @@ match_special_index_operator(Expr *clause, Oid opfamily,
21082107
case OID_NAME_LIKE_OP:
21092108
/* the right-hand const is type text for all of these */
21102109
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like,
2111-
&prefix, &rest) != Pattern_Prefix_None;
2110+
&prefix, NULL) != Pattern_Prefix_None;
21122111
break;
21132112

21142113
case OID_BYTEA_LIKE_OP:
21152114
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like,
2116-
&prefix, &rest) != Pattern_Prefix_None;
2115+
&prefix, NULL) != Pattern_Prefix_None;
21172116
break;
21182117

21192118
case OID_TEXT_ICLIKE_OP:
21202119
case OID_BPCHAR_ICLIKE_OP:
21212120
case OID_NAME_ICLIKE_OP:
21222121
/* the right-hand const is type text for all of these */
21232122
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like_IC,
2124-
&prefix, &rest) != Pattern_Prefix_None;
2123+
&prefix, NULL) != Pattern_Prefix_None;
21252124
break;
21262125

21272126
case OID_TEXT_REGEXEQ_OP:
21282127
case OID_BPCHAR_REGEXEQ_OP:
21292128
case OID_NAME_REGEXEQ_OP:
21302129
/* the right-hand const is type text for all of these */
21312130
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex,
2132-
&prefix, &rest) != Pattern_Prefix_None;
2131+
&prefix, NULL) != Pattern_Prefix_None;
21332132
break;
21342133

21352134
case OID_TEXT_ICREGEXEQ_OP:
21362135
case OID_BPCHAR_ICREGEXEQ_OP:
21372136
case OID_NAME_ICREGEXEQ_OP:
21382137
/* the right-hand const is type text for all of these */
21392138
isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC,
2140-
&prefix, &rest) != Pattern_Prefix_None;
2139+
&prefix, NULL) != Pattern_Prefix_None;
21412140
break;
21422141

21432142
case OID_INET_SUB_OP:
@@ -2380,7 +2379,6 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily)
23802379
Oid expr_op = ((OpExpr *) clause)->opno;
23812380
Const *patt = (Const *) rightop;
23822381
Const *prefix = NULL;
2383-
Const *rest = NULL;
23842382
Pattern_Prefix_Status pstatus;
23852383
List *result;
23862384

@@ -2396,7 +2394,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily)
23962394
case OID_NAME_LIKE_OP:
23972395
case OID_BYTEA_LIKE_OP:
23982396
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like,
2399-
&prefix, &rest);
2397+
&prefix, NULL);
24002398
result = prefix_quals(leftop, opfamily, prefix, pstatus);
24012399
break;
24022400

@@ -2405,7 +2403,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily)
24052403
case OID_NAME_ICLIKE_OP:
24062404
/* the right-hand const is type text for all of these */
24072405
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Like_IC,
2408-
&prefix, &rest);
2406+
&prefix, NULL);
24092407
result = prefix_quals(leftop, opfamily, prefix, pstatus);
24102408
break;
24112409

@@ -2414,7 +2412,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily)
24142412
case OID_NAME_REGEXEQ_OP:
24152413
/* the right-hand const is type text for all of these */
24162414
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex,
2417-
&prefix, &rest);
2415+
&prefix, NULL);
24182416
result = prefix_quals(leftop, opfamily, prefix, pstatus);
24192417
break;
24202418

@@ -2423,7 +2421,7 @@ expand_indexqual_opclause(RestrictInfo *rinfo, Oid opfamily)
24232421
case OID_NAME_ICREGEXEQ_OP:
24242422
/* the right-hand const is type text for all of these */
24252423
pstatus = pattern_fixed_prefix(patt, Pattern_Type_Regex_IC,
2426-
&prefix, &rest);
2424+
&prefix, NULL);
24272425
result = prefix_quals(leftop, opfamily, prefix, pstatus);
24282426
break;
24292427

0 commit comments

Comments
 (0)
0